Some form of flag inheritance for def
and extern
#12363
Description
Related problem
A common pattern in CLI utilities with subcommands is a set of flags, which are shared between all commands (--verbose
, --force
, and so on).
In Nushell, currently, subcommands are independent of their parent commands. This makes implementing nested commands and extern
completions for tools like git
or apk
tricky, because the global options have to be repeated several times.
Describe the solution you'd like
My idea is to add some kind of inheritance, so that a custom function or an extern can inherit some other command's flags. This allows to enable completely separate subcommands (so, aa x
and aa y
will, by default, be unrelated), but still provide the option to share flags as an opt-in.
Describe alternatives you've considered
-
Flags as data. For example, flags could be written down as a
long
,short
,doc
,type
,default
,completer
table and be added to a command:const flags = [ { long: "verbose", short: "v", doc: "Print debug information", }, { long: "format", doc: "The format for the dates", type: string, completer: {|| format_func} }, ... ] def command [ ...flags ] { # stuff }
-
Automatically inheriting flags for subcommands. So
def aa x ...
would inherit the flags ofdef aa
, with an opt-out flag indef
. Not very elegant, and doesn't work when the root command is calledmain
.
Additional context and details
No response