subc – go.zakaria.org/subc Index | Files | Directories

package subc

import "go.zakaria.org/subc"

Index

Variables

var ErrNoSubc = errors.New("Subcommand not given")

ErrNoSubc is returned when the given arguments do not contain a subcommand.

var ErrSubcNotExist = errors.New("Subcommand does not exist")

ErrSubcNotExist is returned when a subcommand that does not exist is requested.

var ErrUsage = errors.New("Usage 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

func Output() io.Writer

Output returns the destination writer for usage and error messages.

func Parse

func Parse() (string, error)

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

func ParseArgs(arguments []string) (string, error)

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

func SetOutput(output io.Writer)

Sets destination for all subcommand usage and messages. By default this is os.Stderr.

func Sub

func Sub(name string) (s *flag.FlagSet)

Sub adds a new subcommand or accesses and existing subcommand.

Source Files

subc.go

Directories

PathSynopsis
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.