bb/main.go

132 lines
3 KiB
Go
Raw Permalink Normal View History

2022-08-06 05:45:08 +03:00
package main
2023-03-08 16:39:50 +03:00
import (
2023-11-25 16:44:47 +03:00
"fmt"
2024-05-15 21:07:35 +03:00
"surdeus.su/core/cli/mtool"
2023-12-04 13:49:01 +03:00
2024-05-15 21:07:35 +03:00
"surdeus.su/util/bb/tool/cat"
"surdeus.su/util/bb/tool/date"
"surdeus.su/util/bb/tool/ec"
"surdeus.su/util/bb/tool/echo"
"surdeus.su/util/bb/tool/ftest"
"surdeus.su/util/bb/tool/grange"
"surdeus.su/util/bb/tool/in"
"surdeus.su/util/bb/tool/ln"
"surdeus.su/util/bb/tool/ls"
"surdeus.su/util/bb/tool/mergelbl"
"surdeus.su/util/bb/tool/mkdir"
"surdeus.su/util/bb/tool/paths"
"surdeus.su/util/bb/tool/quote"
"surdeus.su/util/bb/tool/read"
"surdeus.su/util/bb/tool/sort"
"surdeus.su/util/bb/tool/tac"
"surdeus.su/util/bb/tool/uniq"
"surdeus.su/util/bb/tool/urlprs"
"surdeus.su/util/bb/tool/useprog"
"surdeus.su/util/bb/tool/wc"
"surdeus.su/util/bb/tool/whoami"
"surdeus.su/util/bb/tool/yes"
2023-11-11 12:51:15 +03:00
"os"
2022-08-06 05:45:08 +03:00
)
2023-12-04 13:49:01 +03:00
var root = mtool.T("bb").Subs(
2023-11-11 12:51:15 +03:00
mtool.T("cat").Func(cat.Run).Desc(
"concatenate files",
2023-11-11 22:44:23 +03:00
).Usage(
"[file1 file2 ...fileN]",
2023-11-11 12:51:15 +03:00
),
mtool.T("mkdir").Func(mkdir.Run).Desc(
"make new directories",
2023-11-11 22:44:23 +03:00
).Usage(
"<dir1 [dir2 dir3 ...dirN]>",
2023-11-11 12:51:15 +03:00
),
mtool.T("echo").Func(echo.Run).Desc(
"print strings",
2023-11-11 22:44:23 +03:00
).Usage(
"[str1 str2 ...strN]",
2023-11-11 12:51:15 +03:00
),
2023-12-04 13:49:01 +03:00
mtool.T("true").Func(func(flags *mtool.Flags) {
2023-11-11 12:51:15 +03:00
os.Exit(0)
}).Desc("exit successfuly"),
2023-12-04 13:49:01 +03:00
mtool.T("false").Func(func(flags *mtool.Flags) {
2023-11-11 12:51:15 +03:00
os.Exit(1)
}).Desc("exit with failure"),
mtool.T("sort").Func(sort.Run).Desc(
"sort strings",
),
mtool.T("tac").Func(tac.Run).Desc(
"reversed cat",
),
mtool.T("ls").Func(ls.Run).Desc(
"list files",
2023-11-11 22:44:23 +03:00
).Usage(
"[fileDir1 fileDir2 ...fileDirN]",
2023-11-11 12:51:15 +03:00
),
mtool.T("yes").Func(yes.Run).Desc(
"repeat string",
),
mtool.T("date").Func(date.Run).Desc(
"print date",
),
mtool.T("uniq").Func(uniq.Run).Desc(
"filter repeated strings",
),
mtool.T("quote").Func(quote.Run).Desc(
"quote strings with spaces",
),
mtool.T("urlprs").Func(urlprs.Run).Desc(
"parse URL",
),
mtool.T("read").Func(read.Run).Desc(
"read lines",
),
mtool.T("ec").Func(ec.Run).Desc(
"render escape characters",
),
mtool.T("lbl").Func(mergelbl.Run).Desc(
"merge files line by line",
),
mtool.T("ftest").Func(ftest.Run).Desc(
"filter files",
),
mtool.T("wc").Func(wc.Run).Desc(
"word, rune, byte counts",
),
mtool.T("range").Func(grange.Run).Desc(
"print num range",
),
mtool.T("in").Func(in.Run).Desc(
"print only strings that are in arguments",
),
mtool.T("which").Func(useprog.Run).Desc(
"print path to executable",
),
mtool.T("whoami").Func(whoami.Run).Desc(
"print your username",
),
mtool.T("ln").Func(ln.Run).Desc(
"link files",
),
mtool.T("paths").Func(paths.Run).Desc(
"print different parts of paths",
),
2023-12-04 13:49:01 +03:00
mtool.T("env").Func(func(flags *mtool.Flags) {
2023-11-25 16:44:47 +03:00
flags.Parse()
envs := os.Environ()
for _, env := range envs {
fmt.Println(env)
}
}).Desc(
"print all the environment variables",
),
2023-11-11 12:51:15 +03:00
).Desc(
2023-12-04 13:49:01 +03:00
"not POSIX compatible BusyBox utilities",
2024-07-21 00:58:36 +03:00
).Ldesc(`
The program is not supposed to be a "BusyBox killer.".
In fact it just has better options for Surdeus's scripts.
`)
2022-08-06 05:45:08 +03:00
2023-11-11 12:51:15 +03:00
func main() {
root.Run(os.Args[1:])
2022-08-06 05:45:08 +03:00
}