Command: DynCommand
loading dynamic commands at runtime
Lists dynamic commands at runtime
cmdr
allows scanning and collecting subcmds at runtime.
Sample in concise
The example app concise
demostrates dyn-cmd
in codes of cmd jump
.
At same time, jump
still adds its normal subcmd to
programatically.
外部脚本文件
cmdr 在 ci/
中附加了一些短小的 Shell 脚本文件以便对 concise app 进行演示支持。
The shell scripts, cpu
, memory
and disk
in the directory ./ci/usr.local.lib/concise/ext/
will be added as subcmd of jump
.
The special directory ./ci/usr.local.lib/concise/ext/
is for development. For the product mode, cmdr will locate the system folder at /usr/local/lib/concise/ext/
.
Run
The result of the example app is,
The dyncmds have been listed in help screen, and they will be launched properly.
Backstages
The backstage of these dyncmds is in litecmd.go
. At cmdr preparing time, it loads the dyncmds from certain a target folder, make them invokeable (by InvokeShell(...)
). For the detail, see also function onEvalJumpSubCommands
.
Basically, loading dyncmds needs specifying the callback to OnEvaluateSubCommands(cb)
,
cmdr will request the callback handler at these time:
preprocess()
at bootstrap time- printing help screen
parse()
parsing the commandlineexec()
invoking the parsed result- ...
An expcetion, the callback handler will be ignored in ~~tree
listing.
Another case is OnEvaluateSubCommandsOnce()
, which will be called back just once.
DynFlags ?
cmdr
supports calculating dynflags indeed.
Please looking for app.Flg().OnEvaluateFlags() / OnEvaluateFlagsOnce()
.
额外的话题
How is this guide?
Last updated on