main.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package main
  2. import (
  3. "surdeus.su/core/cli/mtool"
  4. "strconv"
  5. "fmt"
  6. "os"
  7. "strings"
  8. )
  9. var (
  10. root = mtool.T("test").Subs(
  11. mtool.T("echo").Func(func(flags *mtool.Flags) {
  12. var (
  13. b bool
  14. n int
  15. )
  16. flags.BoolVar(&b, "u", false, "convert to uppercase", "UPPERCASE")
  17. flags.IntVar(&n, "n", 1, `
  18. amount of times to print
  19. and long long desc to check things
  20. `,
  21. "NUMPRINT", "NUMPRINT1")
  22. args := flags.Parse()
  23. if b {
  24. for i, arg := range args {
  25. args[i] = strings.ToUpper(arg)
  26. }
  27. }
  28. for i:=0 ; i<n ; i++ {
  29. fmt.Println(args)
  30. }
  31. }).Desc(
  32. "print string array to standard output",
  33. ).Usage(
  34. "[str1 str2 ... strN]",
  35. ).Ldesc(`
  36. Some long description for the echo program
  37. to check how this shit works.
  38. `),
  39. mtool.T("sum").Func(func(flags *mtool.Flags) {
  40. args := flags.Parse()
  41. one, _ := strconv.Atoi(args[0])
  42. two, _ := strconv.Atoi(args[1])
  43. fmt.Println(one + two)
  44. }).Desc(
  45. "add one value to another",
  46. ).Usage(
  47. "<int1> <int2>",
  48. ),
  49. mtool.T("sub").Subs(
  50. mtool.T("first").Func(func(flags *mtool.Flags) {
  51. fmt.Println("called the first", flags.Parse())
  52. }).Desc(
  53. "first sub tool",
  54. ),
  55. mtool.T("second").Func(func(flags *mtool.Flags) {
  56. fmt.Println("called the second", flags.Parse())
  57. }).Desc(
  58. "second sub tool",
  59. ),
  60. ).Desc(
  61. "the tool to demonstrate how subtools work",
  62. ),
  63. ).Desc(
  64. "the testing program to show how to use the lib",
  65. ).Ldesc(`
  66. This is the long description where you
  67. can put anything you want about the program.
  68. `)
  69. )
  70. func main() {
  71. root.Run(os.Args[1:])
  72. }