1234567891011121314151617181920212223242526272829303132333435363738 |
- package cli
- import (
- "flag"
- "fmt"
- "io"
- )
- type GlobalOpts struct {
- ConfigPath string
- Debug bool
- ConfigStanza string
- }
- func (o GlobalOpts) String() string {
- return "--config --debug --account"
- }
- type Command interface {
- Func([]string) error
- Help(io.Writer, *flag.FlagSet)
- }
- type CommandMap map[string]Command
- type ProgramInfo struct {
- Name string
- Opts GlobalOpts
- Commands CommandMap
- }
- func Usage(w io.Writer, info ProgramInfo) {
- fmt.Fprintf(w, "USAGE: %s [%s] SUBCOMMAND [subcommand opts]\n", info.Name, info.Opts)
- fmt.Fprintf(w, "\nSUBCOMMANDS:\n")
- for command := range info.Commands {
- fmt.Fprintf(w, "\t%s\n", command)
- }
- }
|