totp-cli
totp-cli copied to clipboard
use cobra/urfave instead of my own go-commander
Or just leave it there as it is ;)
We can use urfave/cli too, the api looks better than cobra.
package main
import (
"fmt"
"os"
"sort"
"github.com/urfave/cli/v2"
)
func main() {
app := &cli.App{
Name: "test-cli",
Usage: "because why not",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "stuff",
Value: "noice",
Aliases: []string{"s"},
Usage: "I'm ready \\o/",
EnvVars: []string{"CLI_STUFF"},
},
},
Commands: []*cli.Command{
{
Name: "doit",
Aliases: []string{"d", "do"},
Usage: "Just do it!",
Category: "motiv",
Action: func(c *cli.Context) error {
fmt.Println("Just do it!")
return nil
},
},
{
Name: "youcan",
Aliases: []string{"y", "yc", "can"},
Usage: "You can do it!",
Category: "motiv",
Action: func(c *cli.Context) error {
fmt.Println("You can do it!")
return nil
},
},
},
Action: func(c *cli.Context) error {
fmt.Printf("vim-go: %s\n", c.String("stuff"))
return nil
},
}
sort.Sort(cli.FlagsByName(app.Flags))
sort.Sort(cli.CommandsByName(app.Commands))
app.Run(os.Args)
}