nushell / nushell/nushell

Some form of flag inheritance for `def` and `extern`

Open
#12,363 7 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A:syntax category:enhancement semantics status:needs-design
Dominant language
Rust
Stars
40.5k
Forks
2.3k
Avg merge
1d 19h
Merged PRs (30d)
85

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 of def aa, with an opt-out flag in def. Not very elegant, and doesn't work when the root command is called main.

Additional context and details

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no files, tests, or implementation entry points. It proposes opt-in flag inheritance for def and extern, with shared flags available to nested commands; a concrete design and acceptance criteria are still needed.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.