rhombifer

package module
v0.16.17 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2026 License: MIT Imports: 12 Imported by: 0

README

Rhombi (Rhombifer) is a light weight framework for creating CLI applications.

Documentation

Overview

Package rhombifer a flexible and simple unopinionated library for cli tools

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoASubCommand = errors.New("invalid command format")
	ErrNoSubCommands = errors.New("no subcommands to look through")
)
View Source
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")
)
View Source
var (
	ErrNoValues  = errors.New("no values found on flag")
	ErrNilValues = errors.New("values is <nil>")
)

Functions

func ExtractFlagValues

func ExtractFlagValues(flag *Flag, quantity int) ([]string, error)

ExtractFlagValues expecified quantity of values from flag

func IsFirstArgFlag

func IsFirstArgFlag(arg string) bool

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

func Start

func Start() error

Start kick starts the CLI with certain expectations. For more flexebility handle the start of the application your self This may change if future versions

Types

type App

type App struct{}

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 HelpCommand

func HelpCommand() *Command

HelpCommand a default built in `help` command.

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) AddFlags

func (cmd *Command) AddFlags(flags ...*Flag)

AddFlags adds a flag to the a command

func (*Command) AddSubs

func (cmd *Command) AddSubs(subs ...*Command)

AddSubs adds subs commands to the command

func (*Command) CheckForFlag

func (cmd *Command) CheckForFlag(name string) *Flag

func (*Command) CheckSubCommand

func (cmd *Command) CheckSubCommand(subcmd string) (*Command, error)

CheckSubCommand check if subcommand exists within the command

func (*Command) RequiredFlags

func (cmd *Command) RequiredFlags() *[]*Flag

RequiredFlags get required flags

func (*Command) ValidateRequiredFlags

func (cmd *Command) ValidateRequiredFlags(args []string) bool

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

func GetConfig

func GetConfig() *Config

GetConfig returns rhombifer global configuration. It can be used to adjust default behaviors.

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

func FindFlag(aliases ...string) (*Flag, error)

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

func FindFlags(aliases ...string) ([]*Flag, error)

FindFlags found flags in the current executed command and returns all flags specified in the aliases

func GetFlags

func GetFlags() ([]*Flag, error)

GetFlags found flags for the current executed command

func NewFlag

func NewFlag(name, shortdesc string) *Flag

NewFlag is a short hand for when you really only need flag present and the description

func (*Flag) AddValues

func (f *Flag) AddValues(args ...string) error

AddValues add values to the flag

func (*Flag) Exec

func (f *Flag) Exec(fn Run) *Flag

Exec sets a run function if any and returns a pointer to instane f

func (*Flag) GetNames

func (f *Flag) GetNames() (short, long string)

GetNames returns the short and long format name for the flag

func (Flag) GetSingleValue

func (f Flag) GetSingleValue() (string, error)

GetSingleValue returns the first value of the flag

func (*Flag) SetRequired

func (f *Flag) SetRequired() *Flag

SetRequired sets the flag to require and returns a pointer to instance f

func (*Flag) SetShortFormat

func (f *Flag) SetShortFormat(sf string) *Flag

SetShortFormat sets the short format for the flag

func (*Flag) SetValuesRequired

func (f *Flag) SetValuesRequired() *Flag

SetValuesRequired sets the values to required for the flag

type Run

type Run func(args ...string) error

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

Jump to

Keyboard shortcuts

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