Documentation ¶
Index ¶
- Constants
- func App() cli.Runner
- func Exec(rootCmd *cli.RootCommand, opts ...cli.Opt) (err error)
- func New(opts ...cli.Opt) cli.App
- func WithExternalLoaders(loaders ...cli.Loader) cli.Opt
- func WithForceDefaultAction(b bool) cli.Opt
- func WithStore(conf store.Store) cli.Opt
- func WithTasksBeforeParse(tasks ...cli.Task) cli.Opt
- func WithTasksBeforeRun(tasks ...cli.Task) cli.Opt
- func WithUnmatchedAsError(b bool) cli.Opt
Constants ¶
const Version = "v2.0.3" // Version fir hedzr/cmdr/v2
Variables ¶
This section is empty.
Functions ¶
func App ¶
App returns a light version of builder.Runner (a.k.a. *worker.Worker).
Generally it's a unique instance in one system.
It's available once New() / Exec() called, else nil.
func Exec ¶
func Exec(rootCmd *cli.RootCommand, opts ...cli.Opt) (err error)
Exec starts a new cmdr app (parsing cmdline args based on the given rootCmd) from scratch.
It's a reserved API for back-compatible with cmdr v1.
It'll be removed completely at the recently future version.
Deprecated since 2.1
func New ¶
New starts a new cmdr app.
With the returned builder.App, you may build root and sub-commands fluently.
app := cmdr.New(). Info("demo-app", "0.3.1"). Author("hedzr") app.AddCmd(func(b config.CommandBuilder) { b.Titles("jump"). Description("jump command"). Examples(``). Deprecated(``). Hidden(false). AddCmd(func(b config.CommandBuilder) { b.Titles("to"). Description("to command"). Examples(``). Deprecated(``). Hidden(false). OnAction(func(cmd *obj.Command, args []string) (err error) { return // handling command action here }). Build() }). Build() }).AddFlg(func(b config.FlagBuilder) { b.Titles("dry-run", "n").Default(false).Build() }) app.Flg("dry-run", "n"). Default(false). Build() // no matter even if you're adding the duplicated one. // // simple run the parser of app and trigger the matched command's action // _ = app.Run( // cmdr.WithForceDefaultAction(false), // true for debug in developing time // ) if err := app.Run( cmdr.WithForceDefaultAction(false), // true for debug in developing time ); err != nil { logz.Error("Application Error:", "err", err) }
After the root command and all its children are built, use app.[config.App.Run] to parse end-user's command-line arguments, and invoke the bound action on the hit subcommand.
It is not necessary to attach an action onto a parent command, because its subcommands are the main characters - but you still can do that.
func WithForceDefaultAction ¶
func WithUnmatchedAsError ¶
Types ¶
This section is empty.
Directories ¶
Path | Synopsis |
---|---|
atoa
Package atoa - converters for any to any
|
Package atoa - converters for any to any |
Package conf are used to store the app-level constants (app name/vaersion) for cmdr and your app.
|
Package conf are used to store the app-level constants (app name/vaersion) for cmdr and your app. |
internal
|
|
pkg
|
|
dir
Package dir provides a series of directory/file operations
|
Package dir provides a series of directory/file operations |