cli

package
v0.0.0-...-3bfe646 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArgsParser

type ArgsParser interface {
	// ParseArgs parses the specified command line arguments into a parse context.
	ParseArgs(args []string) (*kingpin.ParseContext, error)
}

ArgsParser parses command line arguments.

type ArgsParserFunc

type ArgsParserFunc func(args []string) (*kingpin.ParseContext, error)

ArgsParserFunc is a functional wrapper for ArgsParser to enable ordinary functions as ArgsParsers.

func (ArgsParserFunc) ParseArgs

func (r ArgsParserFunc) ParseArgs(args []string) (*kingpin.ParseContext, error)

ParseArgs parses the specified command line arguments into a parse context.

type CommandArgs

type CommandArgs struct {
	// Parser is used to parse provided command-line.
	Parser ArgsParser
	// FlagsToAdd is a list of additional flags to add to resulting command.
	FlagsToAdd []Flag
	// FlagsToReplace is a list of flags to replace in the command.
	// A flag is only replaced if it has been provided.
	FlagsToReplace []Flag
	// FlagsToRemove is a list of flags to omit from the resulting command.
	FlagsToRemove []string
}

CommandArgs manipulates command-line arguments.

func (*CommandArgs) Update

func (r *CommandArgs) Update(command []string) (args []string, err error)

Update returns new command line for the provided command taking into account flags that need to be added or removed as configured. Positional arguments are moved to the end.

If a flag needs to be replaced (possibly to update the value), it needs to be placed into both FlagsToAdd and FlagsToRemove.

The resulting command line adheres to command line format accepted by systemd. See https://www.freedesktop.org/software/systemd/man/systemd.service.html#Command%20lines for details

type Flag

type Flag interface {
	// Format formats the flag for command line
	Format() []string
	// Name returns the flag's name
	Name() string
}

Flag represents a command-line flag

func NewArg

func NewArg(name, value string) Flag

NewArg creates a new positional argument

func NewBoolFlag

func NewBoolFlag(name string, value bool) Flag

NewBoolFlag creates a new boolean command-line flag.

func NewFlag

func NewFlag(name, value string) Flag

NewFlag creates a new named command-line option with a value.

Jump to

Keyboard shortcuts

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