apple / apple/swift-argument-parser

Prevent subcommand from inheriting flags/options from parent?

Open
#36 1 comment 5 reactions 0 assignees View on GitHub
enhancement
Dominant language
Swift
Stars
3.8k
Forks
411
Avg merge
7d 14h
Merged PRs (30d)
15

Description

I see that when a subcommand's help text is generated, it's based on a stack, which eventually includes its ancestor's flags/options, etc. So the following definition

```swift
struct Math: ParsableCommand {
static var configuration = CommandConfiguration(subcommands: [Add.self])

@Flag()
var version: Bool
}

extension Math {
struct Add: ParsableCommand {}
}
```

means the help text for `add` will be the following:

```
USAGE: math add

OPTIONS:
--version
-h, --help Show help information.
```

There should be a way to prevent `--version` to be included here IMO.

Contributor guide

Open the contributing guide

Research direction

Start by tracing how subcommand help text is generated and how the ancestor flags/options are collected on the stack. Confirm the behavior with the Math and Add example, then determine a way for a subcommand to exclude inherited options. Done means `math add --help` no longer lists the parent’s `--version` flag while retaining the subcommand’s own help option.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.