cliutils

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2024 License: GPL-3.0 Imports: 4 Imported by: 20

Documentation

Overview

Package cliutils provides utilities for building command-line interfaces.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HelpRequested

func HelpRequested(argv ...string) bool

HelpRequested reads the argv and returns whether it contains one of `-h`, `--help`, in any position, or `help` as the first element in the vector. If this happens a subcommand should invoke its own help method to print help.

Types

type Command

type Command interface {
	// Help prints the help for the command on the stdout.
	Help(argv ...string) error

	// Main executes the command main function.
	Main(ctx context.Context, argv ...string) error
}

Command is an rbmk command-line command.

type CommandWithSubCommands

type CommandWithSubCommands struct {
	// contains filtered or unexported fields
}

CommandWithSubCommands is a Command that contains subcommands.

It works as follows:

1. It automatically handles invocation with no arguments by printing help.

2. It handles `-h` and `--help` by printing help.

3. It handles `help [COMMAND...]` by printing help either for the command itself or for the selected subcommmand.

4. It handles `COMMAND...` by redirecting execution to the subcommand.

Construct using NewCommandWithSubCommands.

func NewCommandWithSubCommands

func NewCommandWithSubCommands(name string, help string, commands map[string]Command) CommandWithSubCommands

NewCommandWithSubCommands constructs a CommandWithSubCommands.

The name argument contains the full name of this command (e.g., `rbmk run`).

The help argument contains the help string.

The commands argument contains the implemented subcommands.

func (CommandWithSubCommands) Help

func (c CommandWithSubCommands) Help(argv ...string) error

Help implements Command.

func (CommandWithSubCommands) Main

func (c CommandWithSubCommands) Main(ctx context.Context, argv ...string) error

Main implements Command.

Jump to

Keyboard shortcuts

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