Skip to content

Support global/flexible position-independent command-line options#216

Open
fadeevab wants to merge 1 commit intogoogle:masterfrom
fadeevab:feat/global-args
Open

Support global/flexible position-independent command-line options#216
fadeevab wants to merge 1 commit intogoogle:masterfrom
fadeevab:feat/global-args

Conversation

@fadeevab
Copy link
Contributor

@fadeevab fadeevab commented Feb 16, 2026

It makes argh to support "global arguments" like --verbose/-v options, which are position-independent and subcommand-independent.

Motivation
Most competitors like clap support "flexible" arguments positioned in any place of the command line, while argh feels pretty much limited in this case. In contrast, argh is more limited and typically expects global options to appear before any subcommand, which often feels unnatural and clunky.

Before

cli --verbose jump --height 5 ✅
cli jump --verbose --height 5 ❌
cli jump --height 5 --verbose ❌

After

cli --verbose jump --height 5 ✅
cli jump --verbose --height 5 ✅
cli jump --height 5 --verbose ✅

Algorithm

  1. #[argh(global)] on the top-level command makes all its options position-independent.
  2. The top-level parent options are passed down to subcommands' parsing recursion.
  3. If a switch is not found, it's being searched in the parent's options.

It make argh to be user-friendly, e.g. it's useful for --verbose/-v options

1. #[argh(global)] on the top level command make all its option to be position-independent.
2. The top-level parent options are passed down the subcommand parsing recursion.
3. If a switch not found, it's being searched in the parent's options.
@fadeevab
Copy link
Contributor Author

@elipsitz Hi, I believe this feature is long overdue. Could you please take a look?

@elipsitz
Copy link
Contributor

@fadeevab I’m not a maintainer of this library, I think you meant to tag someone else.

@fadeevab
Copy link
Contributor Author

@erickt Hi, I believe this feature is long overdue. Could you please take a look?

P.S.: @elipsitz Yeah, sorry, it was a misclick on the GitHub user suggestion.

@fadeevab
Copy link
Contributor Author

@erickt I updated the motivation for the PR with the examples:

Before

cli --verbose jump --height 5 ✅
cli jump --verbose --height 5 ❌
cli jump --height 5 --verbose ❌

After

cli --verbose jump --height 5 ✅
cli jump --verbose --height 5 ✅
cli jump --height 5 --verbose ✅

@fadeevab fadeevab changed the title feat: add support for global arguments in subcommands Support global/flexible position-independent command-line options Feb 17, 2026
@fadeevab
Copy link
Contributor Author

@erickt What are your overall thoughts? Should it make sense? Or do you have the least changes policy now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants