subcmd

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package subcmd implements simple command line interface subcommands.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(cmdBaseDoc, description string, options []Option) error

Run runs a subcommand specified by args, or a help request.

Types

type MultiStringFlag

type MultiStringFlag struct {
	Values []string
}

MultiStringFlag is a flag that can be specified multiple times. Use with flag.Var.

func (*MultiStringFlag) Set

func (f *MultiStringFlag) Set(value string) error

func (*MultiStringFlag) String

func (f *MultiStringFlag) String() string

type Option

type Option struct {
	// Name of the option. This must match what the user types for this option to be selected.
	Name string

	// Summary is a brief description of the option. Short: needs to fit in a list of all
	// subcommands in the help text that summarizes all subcommand options.
	Summary string

	// Description is a description of the option that will be printed directly appended to Summary
	// to optionally add more detail to the option-specific help message.
	Description string

	// TakeArgsReason is a brief description of why this option takes non-flag args and what it will
	// do with them, or empty string (default) if the option doesn't accept non-flag args. If empty
	// string, the Run function enforces that only flag args are passed to this option.
	TakeArgsReason string

	// Handle is called when this option is the one picked by the user. Handle must set up any
	// additional flags on its own, run flag parsing by invoking p, then carry out the cmd. Handle
	// is a single function rather than split into individual "Flags" and "Run" funcs so the flags
	// can be declared succinctly as local variables.
	Handle func(p ParseFunc) error
}

type ParseFunc

type ParseFunc func() error

ParseFunc parses all flags that have been set up. Include extra handling for "-h" help flag detailed output, invalid args, and error conditions.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL