2022-06-16 09:02:24 +03:00
|
|
|
package main
|
|
|
|
|
2023-10-23 14:30:51 +03:00
|
|
|
import (
|
2023-12-14 21:35:22 +03:00
|
|
|
"github.com/di4f/cli/mtool"
|
2022-06-16 09:02:24 +03:00
|
|
|
"strconv"
|
|
|
|
"fmt"
|
2023-11-09 23:44:57 +03:00
|
|
|
"os"
|
2022-06-16 09:02:24 +03:00
|
|
|
)
|
|
|
|
|
2023-10-23 14:30:51 +03:00
|
|
|
var (
|
2023-11-09 23:44:57 +03:00
|
|
|
root = mtool.T("test").Subs(
|
|
|
|
mtool.T("echo").Func(func(flags *mtool.Flags) {
|
2023-11-11 20:40:53 +03:00
|
|
|
var b bool
|
|
|
|
flags.BoolVar(&b, "b", false, "the check flag")
|
|
|
|
args := flags.Parse()
|
|
|
|
fmt.Println(args)
|
|
|
|
}).Desc(
|
|
|
|
"print string array to standard output",
|
|
|
|
).Usage(
|
|
|
|
"[str1 str2 ... strN]",
|
|
|
|
),
|
2023-11-09 23:44:57 +03:00
|
|
|
mtool.T("sum").Func(func(flags *mtool.Flags) {
|
2023-11-11 20:40:53 +03:00
|
|
|
args := flags.Parse()
|
|
|
|
one, _ := strconv.Atoi(args[0])
|
|
|
|
two, _ := strconv.Atoi(args[1])
|
|
|
|
fmt.Println(one + two)
|
|
|
|
}).Desc(
|
|
|
|
"add one value to another",
|
|
|
|
).Usage(
|
|
|
|
"<int1> <int2>",
|
|
|
|
),
|
2023-11-09 23:44:57 +03:00
|
|
|
mtool.T("sub").Subs(
|
|
|
|
mtool.T("first").Func(func(flags *mtool.Flags) {
|
2023-11-11 20:40:53 +03:00
|
|
|
fmt.Println("called the first", flags.Parse())
|
|
|
|
}).Desc(
|
|
|
|
"first sub tool",
|
|
|
|
),
|
2023-12-14 21:35:22 +03:00
|
|
|
mtool.T("second").Func(func(flags *mtool.Flags) {
|
2023-11-11 20:40:53 +03:00
|
|
|
fmt.Println("called the second", flags.Parse())
|
|
|
|
}).Desc(
|
|
|
|
"second sub tool",
|
|
|
|
),
|
2023-11-10 12:10:16 +03:00
|
|
|
).Desc(
|
|
|
|
"the tool to demonstrate how subtools work",
|
|
|
|
),
|
|
|
|
).Desc(
|
|
|
|
"the testing program to show how to use the lib",
|
|
|
|
).Ldesc(
|
2023-12-14 21:35:22 +03:00
|
|
|
"this is the long description where you " +
|
2023-11-10 12:10:16 +03:00
|
|
|
"can put anything you want about the program",
|
2023-11-09 23:44:57 +03:00
|
|
|
)
|
2022-06-16 09:02:24 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2023-11-09 23:44:57 +03:00
|
|
|
root.Run(os.Args[1:])
|
2022-06-16 09:02:24 +03:00
|
|
|
}
|