Documentation
¶
Index ¶
- Constants
- Variables
- func HideConsoleWindow()
- func IsAdmin() bool
- func LaunchedFromTerminal() bool
- func ManPage(c *CLI) string
- func MessageWindow(title, message string)
- func NotifyWindow(title, message string)
- func OnUnix() bool
- func OnWindows() bool
- func ValidateName(name string) (err error)
- type Arg
- type BashComplete
- type Bool
- type Byte
- type CLI
- func (me *CLI) Abs(p path.Relative) path.Absolute
- func (me *CLI) AllCommands() []string
- func (me *CLI) Complete(args []string, partial string) (suggestions []string, finished bool, err error)
- func (me *CLI) Delete(p path.Relative, recursive bool) error
- func (me *CLI) ErrorWindow(err error)
- func (me *CLI) Errorf(format string, vars ...any) error
- func (me *CLI) Exec(exe *exec.Exec, args ...string) (err error)
- func (me *CLI) ExecCommand(exe *exec.Exec, cmd string, args ...string) (exec.Command, error)
- func (me *CLI) ExecCommandContext(ctx context.Context, exe *exec.Exec, cmd string, args ...string) (exec.Command, error)
- func (me *CLI) Exists(p path.Relative) bool
- func (me *CLI) FS() fs.FS
- func (me *CLI) GlobalConfigFile() path.Relative
- func (me *CLI) Listen(ch chan<- exec.Signal) error
- func (me *CLI) Load(checkmissing bool) (err error)
- func (me *CLI) LocalConfigFile() path.Relative
- func (me *CLI) Log(format string, vars ...any)
- func (me *CLI) MessageWindow(message string)
- func (me *CLI) Mkdir(p path.Relative, recursive bool) error
- func (me *CLI) ModTime(p path.Relative) (time.Time, error)
- func (me *CLI) Name() string
- func (me *CLI) NewProgressbar(max int64, description string, options ...progressbar.Option) *progressbar.ProgressBar
- func (me *CLI) NewProgressbarBytes(maxBytes int64, description string, options ...progressbar.Option) *progressbar.ProgressBar
- func (me *CLI) NewSpinner(description string, options ...progressbar.Option) *progressbar.ProgressBar
- func (me *CLI) NotifyWindow(message string)
- func (me *CLI) OpenReader(p path.Relative) (io.ReadCloser, error)
- func (me *CLI) OpenWriter(p path.Relative) (io.WriteCloser, error)
- func (me *CLI) Print(vars ...any) error
- func (me *CLI) PrintUsage(hasError bool)
- func (me *CLI) Printf(format string, vars ...any) error
- func (me *CLI) Println(vars ...any) error
- func (me *CLI) ReadDirPaths(p path.Relative) ([]path.Relative, error)
- func (me *CLI) ReadFile(f path.Relative) ([]byte, error)
- func (me *CLI) Reset()
- func (me *CLI) Run() (err error)
- func (me *CLI) RunAndExit()
- func (me *CLI) SelectedCommand() *Command
- func (me *CLI) Size(p path.Relative) int64
- func (me *CLI) Stderr() io.Writer
- func (me *CLI) Stdin() io.Reader
- func (me *CLI) Stdout() io.Writer
- func (me *CLI) UserConfigFile() path.Relative
- func (me *CLI) Vars() []string
- func (me *CLI) Version() *Version
- func (me *CLI) WD() path.Relative
- func (me *CLI) WithArgs(args []string) *CLI
- func (me *CLI) WithAsciiArt() *CLI
- func (me *CLI) WithCopyright(year int, name string) *CLI
- func (me *CLI) WithDescription(descr string) *CLI
- func (me *CLI) WithEnv(env []string) *CLI
- func (me *CLI) WithExec(exe *exec.Exec) *CLI
- func (me *CLI) WithFS(fsys fs.FS) *CLI
- func (me *CLI) WithLogger(l log.Logger) *CLI
- func (me *CLI) WithStderr(wr io.Writer) *CLI
- func (me *CLI) WithStdin(rd io.Reader, viaPipe bool) *CLI
- func (me *CLI) WithStdout(wr io.Writer) *CLI
- func (me *CLI) WithVersion(maj, min, patch int) *CLI
- func (me *CLI) WithWD(wd path.Relative) *CLI
- func (me *CLI) WithoutColoredHelp() *CLI
- func (me *CLI) WithoutCompletionAutoConfig() *CLI
- func (me *CLI) WithoutPagedHelp() *CLI
- func (me *CLI) WriteFile(p path.Relative, data []byte, recursive bool) error
- type Command
- func (me *Command) AddArg(name string, val Value) *Arg
- func (me *Command) AddArgsRemainder(name string, val *String) *Arg
- func (me *Command) AddCommand(name string, callback func(Env) error) *Command
- func (me *Command) AddFlag(name string, val Value) *Flag
- func (me *Command) AddStdinArg(name string, val Value) *Arg
- func (me *Command) AddStdinFlag(name string, val Value) *Flag
- func (me *Command) AllArgs(target *[]string)
- func (me *Command) Help() string
- func (me *Command) Name() string
- func (me *Command) NeedsSubCommand() *Command
- func (me *Command) PrintUsage(hasErr bool)
- func (me *Command) Relax(flags ...*Flag) *Command
- func (me *Command) Require(flags ...*Flag) *Command
- func (me *Command) Run() error
- func (me *Command) Skip(flags ...*Flag) *Command
- func (me *Command) SkipAllBut(except ...*Flag) *Command
- func (me *Command) WithAuthors(authors ...string) *Command
- func (me *Command) WithBugs(text string) *Command
- func (me *Command) WithConcept(text string) *Command
- func (me *Command) WithCopyright(text string) *Command
- func (me *Command) WithDocumentation(text string) *Command
- func (me *Command) WithExample(text string) *Command
- func (me *Command) WithHelp(help string) *Command
- func (me *Command) WithHideFromHelp() *Command
- func (me *Command) WithHistory(text string) *Command
- func (me *Command) WithLicense(text string) *Command
- func (me *Command) WithReportingBugs(text string) *Command
- func (me *Command) WithStdinHandler(stdinHandler func(io.Reader) error) *Command
- type Date
- type DateTime
- type Dir
- func (me *Dir) Complete(app *CLI, prefix string) (suggestions []string, finished bool, err error)
- func (me *Dir) DoesComplete() bool
- func (me *Dir) IsDir() bool
- func (me *Dir) IsPath() bool
- func (me *Dir) Matcher() *regexp.Regexp
- func (me *Dir) Matches(name string) error
- func (me *Dir) New() Value
- func (me Dir) Path(wd path.Relative) path.Relative
- func (me *Dir) Set(s string) (err error)
- func (me Dir) Type() string
- type DirRO
- type DirRW
- type DirRWD
- type DirT
- type Env
- type FSGroupRO
- type FSGroupRW
- type FSGroupRWD
- type File
- func (me *File) Complete(app *CLI, prefix string) (suggestions []string, finished bool, err error)
- func (me *File) DoesComplete() bool
- func (me *File) IsDir() bool
- func (me *File) IsPath() bool
- func (me *File) Matcher() *regexp.Regexp
- func (me *File) Matches(name string) error
- func (me *File) New() Value
- func (me File) Path(wd path.Relative) path.Relative
- func (me *File) Set(s string) (err error)
- func (me File) Type() string
- type FileRO
- type FileRW
- type FileRWD
- type FileT
- type Flag
- type Float32
- type Float64
- type Int
- type InvalidNameError
- type InvalidSelection
- type JSON
- func (me *JSON) Complete(app *CLI, prefix string) (suggestions []string, finished bool, err error)
- func (me *JSON) DoesComplete() bool
- func (me JSON) IsBool() bool
- func (me JSON) IsSlice() bool
- func (me *JSON[T]) New() Value
- func (me *JSON[T]) Set(s string) (err error)
- func (me *JSON) SetName(name string)
- func (me JSON[T]) Type() string
- func (me *JSON) Unset()
- type Map
- func (me *Map) Complete(app *CLI, prefix string) (suggestions []string, finished bool, err error)
- func (me *Map) DoesComplete() bool
- func (me Map) IsBool() bool
- func (me Map) IsSlice() bool
- func (me *Map) New() Value
- func (me *Map) Set(s string) (err error)
- func (me *Map) SetName(name string)
- func (me Map) Type() string
- func (me *Map) Unset()
- type RegExp
- func (me *RegExp) Complete(app *CLI, prefix string) (suggestions []string, finished bool, err error)
- func (me *RegExp) DoesComplete() bool
- func (me RegExp) IsBool() bool
- func (me RegExp) IsSlice() bool
- func (me *RegExp) Matcher() *regexp.Regexp
- func (me *RegExp) New() Value
- func (me *RegExp) Set(s string) (err error)
- func (me *RegExp) SetName(name string)
- func (me *RegExp) Unset()
- type STDIN
- type Select
- func (me Select[T]) Complete(app *CLI, prefix string) (suggestions []string, finished bool, err error)
- func (me Select[T]) DoesComplete() bool
- func (me *Select[T]) IsBool() bool
- func (me Select) IsSlice() bool
- func (me *Select[T]) New() Value
- func (me *Select[T]) Set(s string) (err error)
- func (me *Select) SetName(name string)
- func (me Select[T]) Type() string
- func (me *Select) Unset()
- type SelectFunc
- func (me *SelectFunc[T]) Complete(app *CLI, prefix string) (suggestions []string, finished bool, err error)
- func (me *SelectFunc[T]) DoesComplete() bool
- func (me *SelectFunc[T]) IsBool() bool
- func (me SelectFunc) IsSlice() bool
- func (me *SelectFunc[T]) New() Value
- func (me *SelectFunc[T]) Set(s string) (err error)
- func (me *SelectFunc) SetName(name string)
- func (me *SelectFunc[T]) Type() string
- func (me *SelectFunc) Unset()
- type Slice
- func (me *Slice) Complete(app *CLI, prefix string) (suggestions []string, finished bool, err error)
- func (me *Slice) DoesComplete() bool
- func (me Slice[P]) IsBool() bool
- func (me Slice[P]) IsSlice() bool
- func (me *Slice) New() Value
- func (me *Slice[P]) Set(s string) (err error)
- func (me *Slice) SetName(name string)
- func (me *Slice[P]) String() string
- func (me Slice[P]) Type() string
- func (me *Slice) Unset()
- type String
- type Time
- type TimeFormat
- type URL
- func (me *URL) Complete(app *CLI, prefix string) (suggestions []string, finished bool, err error)
- func (me *URL) DoesComplete() bool
- func (me URL) IsBool() bool
- func (me URL) IsSlice() bool
- func (me *URL) New() Value
- func (me *URL) Set(s string) (err error)
- func (me *URL) SetName(name string)
- func (me URL) Type() string
- func (me *URL) Unset()
- type Uint
- type Value
- type Version
Constants ¶
const ( MaxLenFlagName = 18 MaxLenArgName = 18 MaxLenCommandName = 20 MaxLenAppName = 30 )
Variables ¶
var ErrInterrupt = fmt.Errorf("pseudo error to interrupt processing, e.g. for help command")
var VERSION version.Version
Functions ¶
func HideConsoleWindow ¶ added in v4.0.8
func HideConsoleWindow()
HideConsoleWindow is only functional on windows
func LaunchedFromTerminal ¶ added in v4.0.6
func LaunchedFromTerminal() bool
func MessageWindow ¶ added in v4.0.6
func MessageWindow(title, message string)
MessageWindow prints an error message inside a window, if err != nil
func NotifyWindow ¶ added in v4.0.6
func NotifyWindow(title, message string)
NotifyWindow sends a non-blocking system toast/notification to the desktop. Since it's used as a fallback before exiting, it forces a short pause so the OS has enough time to render and display the toast before the process dies.
func ValidateName ¶
Types ¶
type Arg ¶
type Arg struct {
// contains filtered or unexported fields
}
argument is a parameter that has no flag but is scanned based on the position
func (*Arg) IsRequired ¶
func (*Arg) WithDefault ¶
func (*Arg) WithRequired ¶
type BashComplete ¶
type BashComplete struct {
IncludeFile path.Relative // the filepath (relative to the FS) where the bash script is located that should be included in the .bashrc
FS fs.FS // the filesystem that deals with the include file
Completer myCompleter // the completer has the complete method that is called by the bash completion, when the user presses <tab>
ProgramName string // name of the program (file name)
EnvVar string // the environmental variable that should be set and checked to determine, if completion is activated
Command *Command // the command inside the CLI app,beneath which the complete command will reside (the command that is called from the bash voia the include file)
OnBeforeComplete func() error // is called on complete before the bash_completion.Completer Complete method is called
// contains filtered or unexported fields
}
func (*BashComplete) Setup ¶
func (me *BashComplete) Setup()
type CLI ¶
type CLI struct {
*Command
// contains filtered or unexported fields
}
func (*CLI) AllCommands ¶
func (*CLI) ErrorWindow ¶ added in v4.0.6
func (*CLI) Exec ¶
Exec runs the program with the given environment and the given arguments environmental variables and config files of the env filesystem are being used
func (*CLI) ExecCommand ¶
ExecCommand runs a single command with the given environment. neither environmental variables nor configs are used in this scenario. However, default values are being set. the cmd must be given in command-path syntax (parent/child/...)
func (*CLI) ExecCommandContext ¶
func (me *CLI) ExecCommandContext(ctx context.Context, exe *exec.Exec, cmd string, args ...string) (exec.Command, error)
ExecCommandContext is like ExecCommand but with a context
func (*CLI) GlobalConfigFile ¶
func (*CLI) Listen ¶ added in v4.0.2
somehow we should probably start a goroutine here and get signals from os and transform them into exec.CmdSignals and put them into the channel. but I don't know. somehow we are circumventing the possible testing framework here. IDK what is the best way to handle it
func (*CLI) LocalConfigFile ¶
func (*CLI) MessageWindow ¶ added in v4.0.6
func (*CLI) NewProgressbar ¶
func (me *CLI) NewProgressbar(max int64, description string, options ...progressbar.Option) *progressbar.ProgressBar
NewProgressbar returns a progressbar of github.com/schollz/progressbar/v3 Output defaults to App.Stderr()
func (*CLI) NewProgressbarBytes ¶
func (me *CLI) NewProgressbarBytes(maxBytes int64, description string, options ...progressbar.Option) *progressbar.ProgressBar
NewProgressbarBytes is NewProgressbar for bytes
func (*CLI) NewSpinner ¶
func (me *CLI) NewSpinner(description string, options ...progressbar.Option) *progressbar.ProgressBar
NewSpinner returns a progressbar of github.com/schollz/progressbar/v3 that is a spinner Output defaults to App.Stdout()
func (*CLI) NotifyWindow ¶ added in v4.0.6
func (*CLI) OpenReader ¶
func (*CLI) OpenWriter ¶
func (*CLI) PrintUsage ¶ added in v4.0.15
func (*CLI) RunAndExit ¶
func (me *CLI) RunAndExit()
func (*CLI) SelectedCommand ¶
func (*CLI) UserConfigFile ¶
func (*CLI) WithAsciiArt ¶
func (*CLI) WithCopyright ¶ added in v4.0.12
func (*CLI) WithDescription ¶
func (*CLI) WithVersion ¶
func (*CLI) WithoutColoredHelp ¶ added in v4.0.15
func (*CLI) WithoutCompletionAutoConfig ¶
func (*CLI) WithoutPagedHelp ¶ added in v4.0.15
type Command ¶
type Command struct {
// contains filtered or unexported fields
}
if the name is "", this is the main command
func (*Command) AddArgsRemainder ¶
AddArgsRemainder adds an pseudo argument that collects all remaining arguments in a string. This method may not be called twice and after defining an remainder no further arguments might be added
func (*Command) AddCommand ¶
func (*Command) NeedsSubCommand ¶
func (*Command) PrintUsage ¶ added in v4.0.15
func (*Command) SkipAllBut ¶
func (*Command) WithAuthors ¶
func (*Command) WithConcept ¶
func (*Command) WithCopyright ¶
func (*Command) WithDocumentation ¶
func (*Command) WithExample ¶
func (*Command) WithHideFromHelp ¶
func (*Command) WithHistory ¶
func (*Command) WithLicense ¶
func (*Command) WithReportingBugs ¶
type Dir ¶
type Dir struct {
// contains filtered or unexported fields
}
func (*Dir) DoesComplete ¶
func (me *Dir) DoesComplete() bool
type DirRO ¶
type DirRO struct {
// contains filtered or unexported fields
}
type DirRW ¶
type DirRW struct {
// contains filtered or unexported fields
}
type DirRWD ¶
type DirRWD struct {
// contains filtered or unexported fields
}
func NewDirRWD ¶
func NewDirRWD(fsyses ...FSGroupRWD) *DirRWD
NewDirRWD returns a Dir that is readable, writeable and deletable. The given filesystems must all implement FSReadWriteDelete
type DirT ¶
type FSGroupRO ¶
type FSGroupRO = fs.ExtGroupable[fs.ReadOnly]
func FSReadonly ¶
func FSReadonly() []FSGroupRO
func LocalFSReadonly ¶
func LocalFSReadonly() []FSGroupRO
type FSGroupRW ¶
type FSGroupRW = fs.ExtGroupable[fs.ExtWriteable]
func LocalFS_RW ¶
func LocalFS_RW() []FSGroupRW
type FSGroupRWD ¶
type FSGroupRWD = fs.ExtGroupable[fs.FS]
func LocalFS ¶
func LocalFS() []FSGroupRWD
type File ¶
type File struct {
// contains filtered or unexported fields
}
func (*File) DoesComplete ¶
func (me *File) DoesComplete() bool
type FileRO ¶
type FileRO struct {
// contains filtered or unexported fields
}
type FileRW ¶
type FileRW struct {
// contains filtered or unexported fields
}
type FileRWD ¶
type FileRWD struct {
// contains filtered or unexported fields
}
func NewFileRWD ¶
func NewFileRWD(fsyses ...FSGroupRWD) *FileRWD
NewFileRWD returns a File that is readable, writeable and deletable. The given filesystems must all implement fs.ExtGroupable and fs.FS
type FileT ¶
func NewFileT ¶
func NewFileT[T fs.ReadOnly](fsyses ...fs.ExtGroupable[T]) *FileT[T]
NewFileT returns a File given on the based Type T that at least implements fs.ReadOnly, but might be whatever FS interface on top. The given filesystems must all implement fs.ExtGroupable and the given interface type T
type Flag ¶
type Flag struct {
Arg
// contains filtered or unexported fields
}
flag has -- prefix when called, or - for shortflag
func (*Flag) WithDefault ¶
func (*Flag) WithRequired ¶
func (*Flag) WithShortFlag ¶
type InvalidNameError ¶
type InvalidNameError string
func (InvalidNameError) Error ¶
func (me InvalidNameError) Error() string
type InvalidSelection ¶
func (InvalidSelection) Error ¶
func (me InvalidSelection) Error() string
type JSON ¶
type JSON[T any] struct { Val T // contains filtered or unexported fields }
func (*JSON) DoesComplete ¶
func (me *JSON) DoesComplete() bool
type RegExp ¶
func (*RegExp) DoesComplete ¶
func (me *RegExp) DoesComplete() bool
type Select ¶
type Select[T value.StrConverteable] struct { //Var[string] Options []string OtherAllowed bool // contains filtered or unexported fields }
func NewSelectWithNew ¶
func NewSelectWithNew[T value.StrConverteable](options ...string) Select[T]
func (Select[T]) DoesComplete ¶
type SelectFunc ¶
type SelectFunc[T value.StrConverteable] struct { OtherAllowed bool // contains filtered or unexported fields }
func NewSelectFunc ¶
func NewSelectFunc[T value.StrConverteable](fn func() []string) SelectFunc[T]
func (*SelectFunc[T]) DoesComplete ¶
func (me *SelectFunc[T]) DoesComplete() bool
func (*SelectFunc[T]) IsBool ¶
func (me *SelectFunc[T]) IsBool() bool
func (*SelectFunc[T]) New ¶
func (me *SelectFunc[T]) New() Value
func (*SelectFunc[T]) Set ¶
func (me *SelectFunc[T]) Set(s string) (err error)
func (*SelectFunc[T]) Type ¶
func (me *SelectFunc[T]) Type() string
type Slice ¶
type Slice[P Value] struct { Vals []P // contains filtered or unexported fields }
func (*Slice) DoesComplete ¶
func (me *Slice) DoesComplete() bool
type TimeFormat ¶
type TimeFormat struct {
Format string
// contains filtered or unexported fields
}
func NewTimeFormat ¶
func NewTimeFormat(format string) TimeFormat
func (*TimeFormat) New ¶
func (me *TimeFormat) New() Value
func (*TimeFormat) Set ¶
func (me *TimeFormat) Set(s string) error
func (*TimeFormat) Type ¶
func (me *TimeFormat) Type() string
type Value ¶
type Value interface {
flag.Value
Type() string
Unset()
Err() error
IsSet() bool
IsSlice() bool
IsBool() bool
New() Value
DoesComplete() bool // should return true for bool, select and files/dirs and false otherwise
Complete(app *CLI, prefix string) (suggestions []string, finished bool, err error)
}
Source Files
¶
- arg.go
- args.go
- cli.go
- cli_other.go
- cmd_bash_completion.go
- cmd_config.go
- cmd_help.go
- cmd_man.go
- cmd_version.go
- command.go
- complete_app.go
- complete_bash.go
- complete_path.go
- config.go
- env.go
- file.go
- flag.go
- fs.go
- helper.go
- man.go
- message_window.go
- progress.go
- run.go
- type_dir.go
- type_file.go
- type_json.go
- type_map.go
- type_other.go
- type_path.go
- type_regexp.go
- type_select.go
- type_selectfunc.go
- type_slice.go
- type_timeformat.go
- type_url.go
- type_var.go
- validation.go
- value.go
- version.go