utils.go 665 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package cli
  2. import (
  3. "flag"
  4. "fmt"
  5. "io"
  6. )
  7. type GlobalOpts struct {
  8. ConfigPath string
  9. Debug bool
  10. ConfigStanza string
  11. }
  12. func (o GlobalOpts) String() string {
  13. return "--config --debug --account"
  14. }
  15. type Command interface {
  16. Func([]string) error
  17. Help(io.Writer, *flag.FlagSet)
  18. }
  19. type CommandMap map[string]Command
  20. type ProgramInfo struct {
  21. Name string
  22. Opts GlobalOpts
  23. Commands CommandMap
  24. }
  25. func Usage(w io.Writer, info ProgramInfo) {
  26. fmt.Fprintf(w, "USAGE: %s [%s] SUBCOMMAND [subcommand opts]\n", info.Name, info.Opts)
  27. fmt.Fprintf(w, "\nSUBCOMMANDS:\n")
  28. for command := range info.Commands {
  29. fmt.Fprintf(w, "\t%s\n", command)
  30. }
  31. }