Documentation
¶
Overview ¶
Package rhombifer a flexible and simple unopinionated library for cli tools
Index ¶
- Variables
- func ExtractFlagValues(flag *Flag, quantity int) ([]string, error)
- func IsFirstArgFlag(arg string) bool
- func SetConfig(c *Config)
- func SetRoot(cmd *Command)
- func Start() error
- type App
- type Command
- func (cmd *Command) AddFlags(flags ...*Flag)
- func (cmd *Command) AddSubs(subs ...*Command)
- func (cmd *Command) CheckForFlag(name string) *Flag
- func (cmd *Command) CheckSubCommand(subcmd string) (*Command, error)
- func (cmd *Command) RequiredFlags() *[]*Flag
- func (cmd *Command) ValidateRequiredFlags(args []string) bool
- type Config
- type Flag
- type Run
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoASubCommand = errors.New("invalid command format") ErrNoSubCommands = errors.New("no subcommands to look through") )
var ( ErroNoRootRunFunc = errs.NewError("root has no Run function. Therefore it can't interpret any flags.") ErroFlagUndefined = errs.NewError("flag is undefined.") ErroFlagHasNoValues = errs.NewError("flag has no values.") ErroFoundFlagsIsNil = errs.NewError("found flags is <nil>.") ErroFlagNotFound = errs.NewError("flag not found.") ErrNoSubCommandPassed = errs.NewError("no subcommand was passed") )
var ( ErrNoValues = errors.New("no values found on flag") ErrNilValues = errors.New("values is <nil>") )
Functions ¶
func ExtractFlagValues ¶
ExtractFlagValues expecified quantity of values from flag
func IsFirstArgFlag ¶
IsFirstArgFlag if the argument being passed in is a flag. Returns true if it is and false if it isn't
func SetConfig ¶
func SetConfig(c *Config)
SetConfig global configurtion. Overwrites any default configuration set. If you just want to adjust just certain behaviors without overwritting the defaults use GetConfig
func SetRoot ¶
func SetRoot(cmd *Command)
SetRoot Takes in a pointer to `cmd` and sets it as the root command. The **root** command is only set once for the application runtime. It means that `root` will be set only the first time this funtion is call. Use it if you need to define the `root` command before initialization
Types ¶
type Command ¶
type Command struct {
// command name
Name string
// short description showed when the help command is run
ShortDesc string
// Long command description
LongDesc string
// flags if any
Flags []*Flag
// Sub commands for this command
Subs map[string]*Command
// Action perform by the command
Run Run
// Signifies if this is the root command
Root bool
// Signifies if there are no more commands after this one
Leaf bool
Values []string
Outputs map[string]any // any computed outputs from the command can be stored here
Parent *Command
// contains filtered or unexported fields
}
func Root ¶
func Root() *Command
Root returns root command. If root has not been initialized it creates a new empty Command and returns the pointer
func (*Command) CheckForFlag ¶
func (*Command) CheckSubCommand ¶
CheckSubCommand check if subcommand exists within the command
func (*Command) RequiredFlags ¶
RequiredFlags get required flags
func (*Command) ValidateRequiredFlags ¶
ValidateRequiredFlags validates if required flags are found in the input string. If any required flag is missing it returns false otherwise true. If no flags are required it returns true.
type Config ¶
type Config struct {
// Determines if the root command allows for flags. By Default is true
AllowFlagsInRoot bool
// Determines if the help command should be run if no subcommand or flags are found. Defaults to false
RunHelpIfNoInput bool
}
Global rhombifer configuration
type Flag ¶
type Flag struct {
// flag name
Name string
// Shot Desctiption
Short string
// Long Description
Long string
// Short Format for flag if any
ShortFormat string
// Is this a require flag
// May remove this and add a require flags to the command itself
Required bool
// Does this flag requires a value
RequiresValue bool
// Defines if the flag takes one value or multiple values
SingleValue bool
// Flag values parsed from the current command being run
Values []string
Command *Command
Run Run
}
func FindFlag ¶
FindFlag found flag and returns the first flag that matches any of the aliases provided. Once a flag has been matched the rest of the aliases are no searched, use FindFlags if that is your intent
func FindFlags ¶
FindFlags found flags in the current executed command and returns all flags specified in the aliases
func NewFlag ¶
NewFlag is a short hand for when you really only need flag present and the description
func (Flag) GetSingleValue ¶
GetSingleValue returns the first value of the flag
func (*Flag) SetRequired ¶
SetRequired sets the flag to require and returns a pointer to instance f
func (*Flag) SetShortFormat ¶
SetShortFormat sets the short format for the flag
func (*Flag) SetValuesRequired ¶
SetValuesRequired sets the values to required for the flag
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package ast
|
Package ast |
|
Package lexer handles lexical analysis
|
Package lexer handles lexical analysis |
|
Package parser
|
Package parser |
|
pkg
|
|
|
text
Packag text provides some utilities functions for formating text
|
Packag text provides some utilities functions for formating text |
|
Package tokens handlers the tokens from the input text parser
|
Package tokens handlers the tokens from the input text parser |