ffcli

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2021 License: Apache-2.0 Imports: 6 Imported by: 4

Documentation

Overview

Package ffcli is for building declarative commandline applications.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultUsageFunc

func DefaultUsageFunc(c *Command) string

DefaultUsageFunc is the default UsageFunc used for all commands if no custom UsageFunc is provided.

Types

type Command

type Command struct {
	// Name of the command. Used for sub-command matching, and as a replacement
	// for Usage, if no Usage string is provided. Required for sub-commands,
	// optional for the root command.
	Name string

	// Usage for this command. Printed at the top of the help output.
	// Recommended but not required. Should be one line of the form
	//
	//     cmd [flags] subcmd [flags] <required> [<optional> ...]
	//
	Usage string

	// ShortHelp is printed next to the command name when it appears as a
	// sub-command, in the help output of its parent command. Recommended.
	ShortHelp string

	// LongHelp is printed in the help output, after usage and before flags.
	// Typically a paragraph or more of prose-like text, providing more explicit
	// context and guidance than what is implied by flags and arguments.
	// Optional.
	LongHelp string

	// UsageFunc generates a complete usage output, displayed to the user when
	// the -h flag is passed. The function is invoked with its corresponding
	// command, and its output should reflect the command's short and long help
	// strings, subcommands, and available flags. Optional; if not provided, a
	// suitable, compact default is used.
	UsageFunc func(*Command) string

	// FlagSet associated with this command. Optional, but if none is provided,
	// an empty FlagSet will be defined and attached during Run, so that the -h
	// flag works as expected.
	FlagSet *flag.FlagSet

	// Options provided to ff.Parse when parsing arguments for this command.
	// Optional.
	Options []ff.Option

	// Subcommands accessible underneath (i.e. after) this command. Optional.
	Subcommands []*Command

	// Exec is invoked if this command has been determined to be the terminal
	// command selected by the arguments provided to Run. The args passed to
	// Exec are the args left over after flags parsing. Optional.
	//
	// If Exec returns flag.ErrHelp, Run will behave as if -h were passed and
	// emit the complete usage output.
	Exec func(args []string) error
}

Command combines a main function with a flag.FlagSet, and zero or more sub-commands. A commandline program can be represented as a declarative tree of commands.

func (*Command) Run

func (c *Command) Run(args []string) error

Run parses the commandline arguments for this command and all sub-commands recursively, and invokes the Exec function for the terminal command, if it's defined.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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