totp-cli icon indicating copy to clipboard operation
totp-cli copied to clipboard

use cobra/urfave instead of my own go-commander

Open yitsushi opened this issue 4 years ago • 2 comments

Or just leave it there as it is ;)

yitsushi avatar Sep 23 '21 10:09 yitsushi

We can use urfave/cli too, the api looks better than cobra.

yitsushi avatar Oct 28 '21 08:10 yitsushi

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)

}

yitsushi avatar Oct 28 '21 09:10 yitsushi