Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use last command's help/version flags. #220

Merged
merged 2 commits into from
Aug 27, 2024
Merged

Conversation

BrianPugh
Copy link
Owner

Kind of resolves #219.

The issue was that if a command wants to use a parameter like --version or --help, the version/help flag system swallows it and gets priority. Previously, only the help/version flags of the root app were used; now the help/version flags of the resolved command are used (more intuitive/correct).

@OrHayat with this PR, you can use version in your command as the following:

# notice the `version_flags`
@app.command(name="print-control-file", version_flags=[])
def print_control(version:Annotated[str|None,Parameter(help="control file version")]):
    x=f"""Package: <package name>
Version:{version}-release
Architecture: amd64
Section: admin
Priority: optional
Depends: python3,lsof
Recommends:
"""
    print(x)

I think I would like for the command to automatically have precedence over the help/version flags, but I don't think that will be possible until cyclopts v3.

Keeping this as a draft as I'm not totally satisfied with the solution; I want to think about it a little more.

Copy link

codecov bot commented Aug 21, 2024

Codecov Report

Attention: Patch coverage is 92.30769% with 1 line in your changes missing coverage. Please review.

Project coverage is 95.50%. Comparing base (729f2b9) to head (8035bcc).

Files Patch % Lines
cyclopts/core.py 91.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #220      +/-   ##
==========================================
+ Coverage   95.49%   95.50%   +0.01%     
==========================================
  Files          23       23              
  Lines        2107     2114       +7     
  Branches      539      542       +3     
==========================================
+ Hits         2012     2019       +7     
  Misses         46       46              
  Partials       49       49              
Flag Coverage Δ
unittests 95.22% <92.30%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@BrianPugh
Copy link
Owner Author

alright, so I have decided to go forward with this. Worst case, it's more intuitive before and allows for the very reasonable use-case in #219.

In cyclopts v3 I will probably try to have the command's parameters get priority over version/help-flags.

@BrianPugh BrianPugh marked this pull request as ready for review August 27, 2024 13:29
@BrianPugh
Copy link
Owner Author

there is a bit of ??? around which app's version_print and help_print should be used, but I think we can punt on that issue for now.

@BrianPugh BrianPugh merged commit 34df4c7 into main Aug 27, 2024
17 checks passed
@BrianPugh BrianPugh deleted the version-help-flag-parameters branch August 27, 2024 13:32
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.

the --help and --version parameters seems to not get parsed correctly because they are default commands
1 participant