/* The command package provides the command structure for kurz. Each command is implemented in its own file: the main command.go file only contains information for the root command, its flags, and helpers. Command files are expected to contain the following, for a command "foo" - the command itself, as a *command.Cobra instance, named FooCommand - the command flag variables, named fooSomething. Always prefix by the command name to avoid name conflicts - a init() function which will bind the flags to the command, and the command itself to other commands. - optional: - for commands usable without a subcommand, the command callable, as fooCommand(c *cobra.Command, args []string). - commands needing subcommands do not need a callable First-level commands bind to kurz, other commands may bind to the other FooCommand variables. */ package command import ( "fmt" "github.com/spf13/cobra" "os" ) var kurz = &cobra.Command{ Use: "kurz", Short: "kurz CLI", Long: "The kurz command uses the kurz API to provide a web-based URL shortener/aliaser", } var Verbose bool const ConfigName = ".kurz.js" func verbose() rune { if Verbose { return 'Y' } else { return 'N' } } /* Build() assembles the command structure from the various command files. It is the only function the main package needs to be aware of. */ func Build() { kurz.PersistentFlags().BoolVarP(&Verbose, "verbose", "v", false, "Be verbose") err := kurz.Execute() if err != nil { fmt.Print("Error initializing commands: %+v\n", err) os.Exit(1) } }