420 Commits

Author SHA1 Message Date
Mahesh Bansod
a062eaf7f5 fix: Default vals on new line if possible values 2026-01-01 19:24:29 +05:30
Mahesh Bansod
15509afcbc test: Demonstrate default value ui bug on no desc 2026-01-01 19:12:10 +05:30
Ed Page
596e98ce71 Merge pull request #6129 from cooronx/feat_default_values_if_and_default_values_ifs
feat: Add default_values_if and default_values_ifs
2025-11-19 14:49:38 -06:00
cooronx
c2ced1aed1 feat: Add default_values_if and default_values_ifs to match default_values 2025-11-19 20:32:43 +08:00
Ed Page
1823cef9d6 fix(parser): Don't panic when subcommands conflict with groups
Mentioned in #6182
2025-11-17 10:24:47 -06:00
Ed Page
dcc28467d1 test(parser): Show panic 2025-11-17 10:23:34 -06:00
Ed Page
126440ca84 fix(help): Correctly calculate padding for short-only args
This manifests in two ways
- If a value is taken, we double the padding
- If `ArgAction::Count` is used, we don't account for `...` and crash

Fixes #6164
2025-10-29 09:12:41 -05:00
Ed Page
9e3c05ef38 test(help): Show panic with short, valueless arg 2025-10-29 09:06:04 -05:00
Ed Page
c9898d0fec test(help): Verify short with value 2025-10-29 09:02:41 -05:00
Ed Page
11eea417fc test(help): Show next_line_help behavior
Inspired by #6061
2025-08-07 17:16:27 -05:00
Gil Shoshan
debaa30eb5 fix(help): Visible long flag aliases in help and tests 2025-07-30 02:01:39 +03:00
Gil Shoshan
4f9f007de7 test(help): Add cases for subcommand aliases 2025-07-30 02:01:39 +03:00
Ed Page
cb8255d2f3 feat(builder): Allow quoted id's for arg macro
Fixes #6024
2025-06-09 09:48:08 -05:00
Vincent Ging Ho Yim
c758212a47 feat(help): Merge lists of short and long aliases 2025-05-26 16:33:00 +10:00
Vincent Ging Ho Yim
6d0bfa0e4d feat(help): Show short aliases before long ones
This is consistent with the order of the short and long argument
variants at the start of each line.
2025-05-26 16:32:23 +10:00
Vincent Ging Ho Yim
da2cc8d044 feat(help): Prefix argument short aliases in output with - 2025-05-11 00:14:16 +10:00
Vincent Ging Ho Yim
487aec34b1 feat(help): Prefix argument aliases in output with -- 2025-05-11 00:14:16 +10:00
Ed Page
ecb282491a Revert "feat(help): Only print short when required"
Concern was raised over the alignment in #5963 and decided to defer this
for now.  This wasn't part of the original issue and hadn't been
discussed before.

This reverts commit 78e41f6666.
2025-04-11 14:33:29 -05:00
Thinh Bui
5ac11366e1 update quote 2025-04-01 17:50:54 -07:00
Brandon Fowler
78e41f6666 feat(help): Only print short when required 2025-03-31 21:29:25 -04:00
Brandon Fowler
0f7dbbc27e fix(help): Align mixed argument types
Fixes #3835
2025-03-31 21:29:24 -04:00
Brandon Fowler
bdfa79a0ad test(help): Test mixed argument types 2025-03-31 21:19:52 -04:00
Brandon Fowler
21b0a302b6 fix(help): Don't add \n when a flat subcommand has no args
Fixes [#5960](https://github.com/BrandonXLF/clap/issues/5960)
2025-03-26 20:22:14 -04:00
Ilya Grigoriev
b1044d4d08 feat(builder): Add clap::Error::remove
The test covers both `Error::insert` and `Error::remove`.
2025-03-10 15:32:35 -05:00
Ed Page
b3146db1db test(parser): Correct misleading test names 2025-02-19 11:47:25 -06:00
Ed Page
389fbe87d2 feat(builder): Allow flags to take num_args=0..=1 2025-02-17 12:29:55 -06:00
Ed Page
c395d02703 test(parser): Show flag behavior 2025-02-17 12:24:14 -06:00
Ed Page
80ea3e7c24 fix(assert): Clean up num_args/action assert 2025-02-14 16:03:26 -06:00
Ed Page
a0187c6f3b test(assert): Verify num_args/action compat 2025-02-14 15:58:43 -06:00
Ed Page
0ef80bb9bc fix(parser): Dont report missing flags as present
When we switched flags to `ArgAction::SetTrue`,
we overlooked updating `args_present`.
Because of the default value for `ArgAction::SetTrue`,
`args_present` will always report true when a flag is defined.

I went with the trivial implementation for now.  We could proactively
track this but was unsure about correctness vs overhead and so I thought
I'd have those using it pay for it.

Looking over uses on github, this will fix a couple bugs but should
otherwise be unnoticeable.

Fixes #5860
2025-02-11 13:26:26 -06:00
Ed Page
225e0d8bd8 test(parser): Verify args_present behavior 2025-02-11 13:22:05 -06:00
Ed Page
c721b6cdc8 fix(parser): Set correct source on ignore-errors with did-you-mean
Fixes #5867
2025-01-07 10:35:14 -06:00
Ed Page
49cd3172c0 test(parser): Verify ignore_errors with did-you-mean 2025-01-07 10:32:03 -06:00
Ed Page
a97e179951 test(builder): Switch more to assert_error 2025-01-07 10:19:06 -06:00
Ed Page
c12ab65ebc test(error): Extract error assertion 2025-01-07 10:01:16 -06:00
Ed Page
1bafe3f3bf test(error): Switch to snapshots 2025-01-07 09:44:55 -06:00
Omer Tuchfeld
29d9e8844f fix(assert): Prevent arguments from requiring self
It's non-sensical for an argument to require itself, so it must be a
mistake, and should be prevented.

This is arguably a breaking change, but of the spacebar heating kind.

Signed-off-by: Omer Tuchfeld <omer@tuchfeld.dev>
2024-12-03 20:02:45 +01:00
Omer Tuchfeld
52aad0ea1a test(asserts): Add test for self requires
Add a test that shows that clap doesn't complain when a flag requires
itself.

This test demonstrates existing broken behavior, ideally it should
panic.

It will be fixed in the next commit.

Signed-off-by: Omer Tuchfeld <omer@tuchfeld.dev>
2024-12-03 20:02:40 +01:00
Ed Page
479df35abd fix(parser): Fill in defaults on ignored error
This came up in #5812 and is especially problematic for derives.

Not really a fan of this solution but its the least invasive.
I also considered going wild with error recovery or moving towards a
solution for #1546.
2024-11-12 21:09:55 -06:00
Ed Page
6827841930 test(parser): Show bad ignore_errors defaulting case 2024-11-12 15:04:53 -06:00
Ed Page
76d0049330 test(parser): Verify defaulting on errors 2024-11-12 15:04:53 -06:00
Ed Page
3f5c05ce38 test(parser): Ensure we are actually testing ignore_errors 2024-11-12 15:04:53 -06:00
Ed Page
360bb3bc11 fix(help): Properly wrap subcommand about
Fixes #5607
2024-07-31 16:17:40 -05:00
Ed Page
58b5bd89ea test(help): Show bad subcommand wrapping 2024-07-31 16:17:40 -05:00
Ed Page
7b5b61b021 test(help): Switch to snapbox 2024-07-31 15:58:24 -05:00
Zanie Blue
2eb842cc3b feat: Show user defined help flags in hints
This allows display of user-defined help flags during "try 'help'" style
messages
2024-07-08 19:01:22 -05:00
Zanie Blue
b24deb101f test: Add coverage for help flag hints 2024-07-08 19:01:22 -05:00
Ed Page
cf5c95862e fix(parser): Report correct num_args on too-few
Fixes #5526
2024-06-10 09:16:53 -05:00
Ed Page
e0c9619c27 test(parser): Snapshot num_args errors 2024-06-10 09:15:48 -05:00
Ed Page
08656d046e fix(parser): Allow exclusive to override required_*
There are other cases for `required` that aren't being handled
- Groups
- Conflicts

I'm concerned there might be weird corner cases and didn't want the
analysis for that to block fixing this.

Fixes #5507
2024-06-06 15:01:04 -05:00