Skip to content

Conversation

@asmacdo
Copy link
Contributor

@asmacdo asmacdo commented Oct 16, 2025

What does this PR do?

Fixes #786

Prevents extra environment variables from being listed in the helptext when default_env=True

  • version actions
  • subcommands (ie PREFIX_<subcommand>)

Example:

Example code
from jsonargparse import ArgumentParser

parser = ArgumentParser(
    prog='cli',
    description='Minimal CLI example',
    default_env=True,
)
parser.add_argument('--version', action='version', version='1.0.0')

subcommands = parser.add_subcommands()
subparser = ArgumentParser()
subcommands.add_subcommand('greet', subparser, help='Greet someone')

parser.print_help()
Fixed output
python example_issue_786.py 
usage: cli [-h] [--version] {greet} ...

Minimal CLI example

options:
  ARG:   -h, --help     Show this help message and exit.
  ARG:   --version      show program's version number and exit

subcommands:
  For more details of each subcommand, add it as an argument followed by --help.

  ENV:   CLI_SUBCOMMAND

  Available subcommands:
    greet               Greet someone
Original output
python example_issue_786.py
usage: cli [-h] [--version] {greet} ...

Minimal CLI example

options:
  ARG:   -h, --help     Show this help message and exit.
  ARG:   --version
  ENV:   CLI_VERSION
                        show program's version number and exit

subcommands:
  For more details of each subcommand, add it as an argument followed by --help.

  ENV:   CLI_SUBCOMMAND

  Available subcommands:
    ARG:   greet
  ENV:   CLI_GREET
                        Greet someone

Before submitting

  • Did you read the contributing guideline?
    - [ ] Did you update the documentation? (readme and public docstrings)
    IMO does not need, but lmk if theres something
  • Did you write unit tests such that there is 100% coverage on related code? (required for bug fixes and new features)
  • Did you verify that new and existing tests pass locally?
  • Did you make sure that all changes preserve backward compatibility?
  • Did you update the CHANGELOG including a pull request link? (not for typos, docs, test updates, or minor internal changes/refactors)

asmacdo and others added 3 commits October 16, 2025 10:24
When using `default_env=True`, the `action="version"` arguments no longer
gets an unused environment variable in helptext.

Co-Authored-By: Claude <noreply@anthropic.com>
When using `default_env=True`, subcommands in the help output no longer
show unusable ARG or ENV PREFIX_<subcommand>.

Co-Authored-By: Claude <noreply@anthropic.com>
@codecov
Copy link

codecov bot commented Oct 16, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (36679f3) to head (d75ea61).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #787   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           22        22           
  Lines         7060      7062    +2     
=========================================
+ Hits          7060      7062    +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@mauvilsa mauvilsa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect!

@mauvilsa mauvilsa merged commit 1f901fe into omni-us:main Oct 16, 2025
29 checks passed
@mauvilsa mauvilsa added the bug Something isn't working label Oct 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

extra env vars in help text when using default_env=True

2 participants