cli

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArgsTail

func ArgsTail(args []Arg) []string

ArgsTail extracts the names from a slice of Arg structs and returns them as a slice of strings.

Parameters: - args: A slice of Arg structs from which the names will be extracted.

Returns: - A slice of strings containing the names of the provided Arg structs.

func FlagValue

func FlagValue(name string, flags []Flag) string

FlagValue retrieves the value of a flag by its name from a slice of Flag structs. If the flag is not found, it returns an empty string.

Parameters:

  • name: The name of the flag to search for.
  • flags: A slice of Flag structs to search within.

Returns:

The value of the flag if found, otherwise an empty string.

func FlagsTail

func FlagsTail(flags []Flag) []string

FlagsTail takes a slice of Flag structs and returns a slice of strings containing the names of those flags.

Parameters:

flags []Flag: A slice of Flag structs.

Returns:

[]string: A slice of strings containing the names of the flags.

func FlagsWithNamesTail

func FlagsWithNamesTail(flags []Flag) []string

FlagsWithNamesTail takes a slice of Flag structs and returns a slice of strings, where each string is a formatted pair of the flag's name and value in the form "name=value".

Parameters:

flags []Flag - A slice of Flag structs, each containing a Name and a Value.

Returns:

[]string - A slice of strings, each representing a flag's name and value pair.

func HasArg

func HasArg(name string, args []Arg) bool

HasArg checks if an argument with the specified name exists in the provided slice of arguments.

Parameters: - name: The name of the argument to search for. - args: A slice of Arg structures to search within.

Returns: - bool: True if an argument with the specified name is found, otherwise false.

func HasFlag

func HasFlag(name string, flags []Flag) bool

HasFlag checks if a flag with the specified name exists in the provided slice of flags.

Parameters: - name: The name of the flag to search for. - flags: A slice of Flag objects to search within.

Returns: - bool: True if a flag with the specified name is found, otherwise false.

func HasSubsequence

func HasSubsequence(args []Arg, subSeq []string) bool

HasSubsequence checks if the given subsequence of strings (subSeq) is present in the tail of the provided arguments (args).

Parameters:

  • args: A slice of Arg representing the arguments to be checked.
  • subSeq: A slice of strings representing the subsequence to look for.

Returns:

  • bool: True if the subsequence is found in the tail of the arguments, false otherwise.

func Settings

func Settings() ([]Arg, []Flag)

Settings parses command-line arguments and flags.

It skips the program name and processes the remaining arguments. Arguments that start with "--" are considered flags, and the function checks if the next argument is a value for the flag. If so, it pairs the flag with its value; otherwise, it pairs the flag with an empty string. Arguments that do not start with "--" are considered positional arguments.

Returns two slices: one containing the positional arguments and the other containing the flags with their respective values.

Types

type Arg

type Arg struct {
	Name string
}

type Flag

type Flag struct {
	Name  string
	Value string
}

Jump to

Keyboard shortcuts

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