main.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. package main
  2. import (
  3. "fmt"
  4. "surdeus.su/core/cli/mtool"
  5. "surdeus.su/util/bb/tool/cat"
  6. "surdeus.su/util/bb/tool/date"
  7. "surdeus.su/util/bb/tool/ec"
  8. "surdeus.su/util/bb/tool/echo"
  9. "surdeus.su/util/bb/tool/ftest"
  10. "surdeus.su/util/bb/tool/grange"
  11. "surdeus.su/util/bb/tool/in"
  12. "surdeus.su/util/bb/tool/ln"
  13. "surdeus.su/util/bb/tool/ls"
  14. "surdeus.su/util/bb/tool/mergelbl"
  15. "surdeus.su/util/bb/tool/mkdir"
  16. "surdeus.su/util/bb/tool/paths"
  17. "surdeus.su/util/bb/tool/quote"
  18. "surdeus.su/util/bb/tool/read"
  19. "surdeus.su/util/bb/tool/sort"
  20. "surdeus.su/util/bb/tool/tac"
  21. "surdeus.su/util/bb/tool/uniq"
  22. "surdeus.su/util/bb/tool/urlprs"
  23. "surdeus.su/util/bb/tool/useprog"
  24. "surdeus.su/util/bb/tool/wc"
  25. "surdeus.su/util/bb/tool/whoami"
  26. "surdeus.su/util/bb/tool/yes"
  27. "os"
  28. )
  29. var root = mtool.T("bb").Subs(
  30. mtool.T("cat").Func(cat.Run).Desc(
  31. "concatenate files",
  32. ).Usage(
  33. "[file1 file2 ...fileN]",
  34. ),
  35. mtool.T("mkdir").Func(mkdir.Run).Desc(
  36. "make new directories",
  37. ).Usage(
  38. "<dir1 [dir2 dir3 ...dirN]>",
  39. ),
  40. mtool.T("echo").Func(echo.Run).Desc(
  41. "print strings",
  42. ).Usage(
  43. "[str1 str2 ...strN]",
  44. ),
  45. mtool.T("true").Func(func(flags *mtool.Flags) {
  46. os.Exit(0)
  47. }).Desc("exit successfuly"),
  48. mtool.T("false").Func(func(flags *mtool.Flags) {
  49. os.Exit(1)
  50. }).Desc("exit with failure"),
  51. mtool.T("sort").Func(sort.Run).Desc(
  52. "sort strings",
  53. ),
  54. mtool.T("tac").Func(tac.Run).Desc(
  55. "reversed cat",
  56. ),
  57. mtool.T("ls").Func(ls.Run).Desc(
  58. "list files",
  59. ).Usage(
  60. "[fileDir1 fileDir2 ...fileDirN]",
  61. ),
  62. mtool.T("yes").Func(yes.Run).Desc(
  63. "repeat string",
  64. ),
  65. mtool.T("date").Func(date.Run).Desc(
  66. "print date",
  67. ),
  68. mtool.T("uniq").Func(uniq.Run).Desc(
  69. "filter repeated strings",
  70. ),
  71. mtool.T("quote").Func(quote.Run).Desc(
  72. "quote strings with spaces",
  73. ),
  74. mtool.T("urlprs").Func(urlprs.Run).Desc(
  75. "parse URL",
  76. ),
  77. mtool.T("read").Func(read.Run).Desc(
  78. "read lines",
  79. ),
  80. mtool.T("ec").Func(ec.Run).Desc(
  81. "render escape characters",
  82. ),
  83. mtool.T("lbl").Func(mergelbl.Run).Desc(
  84. "merge files line by line",
  85. ),
  86. mtool.T("ftest").Func(ftest.Run).Desc(
  87. "filter files",
  88. ),
  89. mtool.T("wc").Func(wc.Run).Desc(
  90. "word, rune, byte counts",
  91. ),
  92. mtool.T("range").Func(grange.Run).Desc(
  93. "print num range",
  94. ),
  95. mtool.T("in").Func(in.Run).Desc(
  96. "print only strings that are in arguments",
  97. ),
  98. mtool.T("which").Func(useprog.Run).Desc(
  99. "print path to executable",
  100. ),
  101. mtool.T("whoami").Func(whoami.Run).Desc(
  102. "print your username",
  103. ),
  104. mtool.T("ln").Func(ln.Run).Desc(
  105. "link files",
  106. ),
  107. mtool.T("paths").Func(paths.Run).Desc(
  108. "print different parts of paths",
  109. ),
  110. mtool.T("env").Func(func(flags *mtool.Flags) {
  111. flags.Parse()
  112. envs := os.Environ()
  113. for _, env := range envs {
  114. fmt.Println(env)
  115. }
  116. }).Desc(
  117. "print all the environment variables",
  118. ),
  119. ).Desc(
  120. "not POSIX compatible BusyBox utilities",
  121. ).Ldesc(`
  122. The program is not supposed to be a "BusyBox killer.".
  123. In fact it just has better options for Surdeus's scripts.
  124. `)
  125. func main() {
  126. root.Run(os.Args[1:])
  127. }