cliapp

package
v0.0.0-...-9799ab4 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2023 License: GPL-3.0 Imports: 4 Imported by: 2

README

saves time writting CLI application boilerplait: 
simply define tree of commands and feed it alon with os.Args to
RunCmd function

examples are in tests dir

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckAppCmdNode

func CheckAppCmdNode(in *AppCmdNode, depth []string)

func PrintAppResult

func PrintAppResult(in *AppResult) int

func PrintHelp

func PrintHelp(
	depth_level []string,
	root *AppCmdNode,
	render_for *AppCmdNode,
)

func RunApp

func RunApp(
	rootnode *AppCmdNode,
	pass_data interface{},
)

NOTE: this function does not returns: os.Exit is called before the return.

use RunCmd to avoid os.Exit

Types

type AdditionalInfo

type AdditionalInfo struct {
	OptsAndArgs      []string
	AvailableOptions GetOptCheckList
	DepthLevel       []string
	Subnode          *AppCmdNode
	Rootnode         *AppCmdNode
	Arg0             string
	PassData         interface{}
}

type AppCmdNode

type AppCmdNode struct {
	Name             string
	ShortDescription string
	Version          string
	VersionInfo      string
	DevStatus        string
	Description      string
	License          string
	Date             string
	Developers       []string
	URIs             []string
	ManPages         []string
	InfoPages        []string
	SubCmds          []*AppCmdNode

	Callable func(
		getopt_result *GetOptResult,
		adds *AdditionalInfo,
	) *AppResult

	AvailableOptions GetOptCheckList

	CheckArgs bool
	MinArgs   int // -1 == allow 0 arguments
	MaxArgs   int // -1 == no limit to arguments; 0 = no arguments allowed
}

type AppResult

type AppResult struct {
	Code             int
	Message          string
	DoNotPrintResult bool
}

func RunCmd

func RunCmd(
	arg0 string,
	opts_and_args []string,
	rootnode *AppCmdNode,
	pass_data interface{},
) *AppResult

type GetOptCheckList

type GetOptCheckList []*GetOptCheckListItem

func (GetOptCheckList) GetByName

func (self GetOptCheckList) GetByName(name string) *GetOptCheckListItem

func (GetOptCheckList) HelpString

func (self GetOptCheckList) HelpString() string

type GetOptCheckListItem

type GetOptCheckListItem struct {
	/*
		must be with leading '-' (minuses) and without trailing '=' equals
	*/
	Name string

	/*
		set this to true if Default value have meaning
	*/
	HaveDefault bool

	/*
		default value in case if defined without value
	*/
	Default string

	/*
		put here true, if user MUST set this flag
	*/
	IsRequired bool

	/* insist on value to flag.
	if this is true, and value not passed to option,
	then if HaveDefault is true then Default is used as value.
	*/
	MustHaveValue bool

	Description string // this text will be printed beside option on --help parameter
}

func (*GetOptCheckListItem) HelpString

func (self *GetOptCheckListItem) HelpString() string

type GetOptResult

type GetOptResult struct {
	NodeInfo *AppCmdNode
	Args     []string
	Opts     []*RetOptItem
}

result after arguments processd

func GetOpt

func GetOpt(args []string) *GetOptResult

NOTE: spaces, around option names, theyr values and arguments are not

stripped.
spaces considered to be stripped already by some other lexer

func (*GetOptResult) CheckOptResult

func (self *GetOptResult) CheckOptResult() []error

check result accordingly with AvailableOptions passed to

func (*GetOptResult) DoesHaveNamedRetOptItem

func (self *GetOptResult) DoesHaveNamedRetOptItem(name string) bool

check if option with name 'name' has been supplied

func (*GetOptResult) DoesNamedRetOptItemHaveValue

func (self *GetOptResult) DoesNamedRetOptItemHaveValue(name string) bool

check if option with name 'name' has been supplied and it have some value

func (*GetOptResult) GetAllNamedRetOptItems

func (self *GetOptResult) GetAllNamedRetOptItems(name string) []RetOptItem

return all options with name 'name'

func (*GetOptResult) GetLastNamedRetOptItem

func (self *GetOptResult) GetLastNamedRetOptItem(name string) *RetOptItem

If arguments contained many options with name 'name', then return only last of them

func (*GetOptResult) GetOptionByName

func (self *GetOptResult) GetOptionByName(name string) *GetOptCheckListItem

func (*GetOptResult) String

func (self *GetOptResult) String() string

type RetOptItem

type RetOptItem struct {
	Name      string
	HaveValue bool
	Value     string
}

Jump to

Keyboard shortcuts

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