Flag: External Editor
Using external editor
Get text by launch an external editor
git
tool has a command commit
, which flag -m msg
supports lauching shell editor to get text input with -m msg
. If user gived a command line git commit -m
without msg
, git
will find shell program identified by EDITOR
envvar (constantly it's vim
or nano
) and launch it, and waiting the user's input, and return the input text as message of -m
after editor closed.
cmdr allows you define a flag with the same behavior.
A flag with using ExternalEditor(envVarName)
will get the interactive actions like git -m
.
The envVarName
is the envvar name.
While you have a definition EDITOR=nano
in the OS environment, ExternalEditor("EDITOR")
will launch nano
and wait for the user's input, and return the input text as the flag's value finally.
Sometimes, you may try launch a different editor/viewer via envVarName
like LESS
, or MAN
, or else.
Totally the flag' default value must by a string.
Define
.ExternalEditor(envVarName)
can enable External Editor
feature for a flag.
Run
The above app can have the following result:
额外的话题
How is this guide?
Last updated on