package subc
import "go.zakaria.org/subc"
Index ¶
- Variables
- func Output() io.Writer
- func Parse() (string, error)
- func ParseArgs(arguments []string) (string, error)
- func SetOutput(output io.Writer)
- func Sub(name string) (s *flag.FlagSet)
Variables ¶
ErrNoSubc is returned when the given arguments do not contain a subcommand.
ErrSubcNotExist is returned when a subcommand that does not exist is requested.
ErrUsage is returned when usage/help is requested.
var Usage = func() { names := make([]string, len(subcommands)) i := 0 for name := range subcommands { names[i] = name i++ } fmt.Fprintf(outputWriter, "Usage of %s [%s]\n", os.Args[0], strings.Join(names, "|")) for name, f := range subcommands { fmt.Fprintf(outputWriter, "%s:\n", name) f.PrintDefaults() } }
Prints a usage message documenting all defined subcommands and their flags.
Functions ¶
func Output ¶
Output returns the destination writer for usage and error messages.
func Parse ¶
Parse parses the flags for the subcommand os.Args[1]. Must be called after all flags are defined and before flags are accessed by the program. Returns the name of the requested subcommand.
func ParseArgs ¶
Parse parses the the flags of the subcommand given as the first item in the argument list. The given argument list should not include the command name. Returns the name of the parsed subcommand.
func SetOutput ¶
Sets destination for all subcommand usage and messages. By default this is os.Stderr.
func Sub ¶
Sub adds a new subcommand or accesses and existing subcommand.
Source Files ¶
subc.go
Directories ¶
| Path | Synopsis |
|---|---|
| examples | |
| examples/simple |
- Version
- v0.0.0-20220111123713-7a1672f22994 (latest)
- Published
- Jan 11, 2022
- Platform
- linux/amd64
- Imports
- 6 packages
- Last checked
- 1 year ago –
Tools for package owners.