-
Notifications
You must be signed in to change notification settings - Fork 43
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
Repository version user-entered options order fix #847
Conversation
I don't know whether that's needed, but if you want me to add a simple test case, I can insert a |
You may sneak a
With this, we will verify whether your fix works globally or not. |
202cfbc
to
09f90d9
Compare
CHANGES/650.bugfix
Outdated
@@ -0,0 +1 @@ | |||
Option (also resource lookup option) --repository is now an eager (high priority) parameter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A user reading through the changelog would have no idea what this means.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@daviddavis thanks, you're right. Is the new one any better?
pulpcore/cli/common/generic.py
Outdated
@@ -863,11 +863,13 @@ def _type_callback(ctx: click.Context, param: click.Parameter, value: t.Optional | |||
help=_("Name of the repository"), | |||
callback=lookup_callback("name", PulpRepositoryContext), | |||
expose_value=False, | |||
is_eager=True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not convinced, this is a nice solution, because it put's --repository
on the same level as --help
.
I believe we have ways to specify repository versions in a single option with the export code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would that mean that the help message will not be printed if I use both --repository
and --help
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's sure something to test. But I'm hesitant to call "--repository" that special.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mdellweg I though so based on the documentation, but --help still acts as it should. Even if I use --repository with an invalid repository name, and put --help AFTER --repository, I still only get the help message printed.
Maybe --help is not only eager, but also has some special property in Click.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"repo" is a repository that actually exists, "repo2" is nonexistent
pulp file repository version show --repository repo --help
Usage: pulp file repository version show [OPTIONS]
Show details of a repository version.
Options:
--repository-href TEXT HREF of the repository
--repository TEXT A resource to look for identified by <name> or by
<href>.
--version INTEGER Repository version number
--help Show this message and exit.
pulp file repository version show --repository repo2 --help
Usage: pulp file repository version show [OPTIONS]
Show details of a repository version.
Options:
--repository-href TEXT HREF of the repository
--repository TEXT A resource to look for identified by <name> or by
<href>.
--version INTEGER Repository version number
--help Show this message and exit.
Also, adding --version ANYWHERE doesn't change the outcomes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, eager is not the solution, because the real issue in disguise is that _version_callback
is evaluating the repository context prematurely (before all options have been seen), by accessing it's pulp_href
. Leading to api calls before we even know the command is syntactically correct.
Instead, it should hook the contexts up lazily.
09f90d9
to
3a999ae
Compare
pulpcore/cli/common/generic.py
Outdated
@@ -863,11 +863,13 @@ def _type_callback(ctx: click.Context, param: click.Parameter, value: t.Optional | |||
help=_("Name of the repository"), | |||
callback=lookup_callback("name", PulpRepositoryContext), | |||
expose_value=False, | |||
is_eager=True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, eager is not the solution, because the real issue in disguise is that _version_callback
is evaluating the repository context prematurely (before all options have been seen), by accessing it's pulp_href
. Leading to api calls before we even know the command is syntactically correct.
Instead, it should hook the contexts up lazily.
3a999ae
to
d0a9e41
Compare
d0a9e41
to
51c8564
Compare
7f96cbc
to
dcbf95f
Compare
493b594
to
6cc4258
Compare
6cc4258
to
f67ef63
Compare
15aa4b6
to
c537cbb
Compare
0e7552b
to
f6ded88
Compare
The order in which the user enters options (--version, --repository, ..) no longer matters for 'pulp <plugin> repository version' commands, since all API calls are now deferred to after the options' callbacks are processed. closes pulp#650
f6ded88
to
807416a
Compare
The order in which the user enters options (--version, --repository, ..) no longer matters for
'pulp repository version' commands, since all API calls are now deferred to after the
options' callbacks are processed.
closes #650
Review Checklist: