Repository navigation
Conversation
`kaggle competitions pages <competition>` and the explicit forms
`pages list|create|update|delete <competition>` all failed with
"argument command: invalid choice: '<competition>'". The `pages` parser
carried an optional `competition` positional alongside its
{list,create,update,delete} subcommands; argparse hands the first token
to the subparsers action, so the competition slug was parsed as a
(non-existent) subcommand. Only the hidden `-c` alias worked.
Move the `competition` positional onto the `list` subparser and route a
bare `pages <competition>` to `list` via a small _SubParsersAction
subclass, so every documented form works while the deprecated `-c`
option is unchanged. Add parser-level tests for the positional forms.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
| @@ -521,11 +552,17 @@ def parse_competitions(subparsers) -> None: | |||
| help=Help.command_competitions_pages, | |||
There was a problem hiding this comment.
Small optional thing: since the competition positional moved to the list subparser, kaggle competitions pages -h no longer shows it. The usage line is now just {list,create,update,delete} ..., so there's no hint that pages <competition> works. Maybe add a short description here? Totally fine to skip if you think it's not worth it.
| help=Help.command_competitions_pages, | |
| help=Help.command_competitions_pages, | |
| description="pages <competition> is shorthand for pages list <competition>.", |
There was a problem hiding this comment.
Good catch, thanks! Applied in f82140f, so kaggle competitions pages -h now shows:
pages <competition> is shorthand for pages list <competition>.
Moving the competition positional onto the list subparser removed it from the pages usage line. Add a parser description so pages -h still shows that pages <competition> is shorthand for pages list <competition>.
Summary
kaggle competitions pages <competition>is currently unusable.pages <comp>,pages list <comp>, and the documentedpages create <comp> ...all fail witherror: argument command: invalid choice: '<comp>'. Only the deprecated-c/--competitionflag works.Cause
The
competitions pagesparser attached an optionalcompetitionpositional (via the shared options parent) on the same parser that also registers the{list,create,update,delete}subparsers. argparse routes the first positional token to the subparsers action, so a competition slug is parsed as a subcommand name and rejected.Fix
competitionpositional from the shared options parent; re-add it only on thelistsubparser.<competition>token tolist <competition>, while preservingpages-level options (e.g.--contentbefore the slug).-c/--competitionworking unchanged.Tests
Added parser-level tests in
tests/unit/test_cli_competitions.pycovering the bare positional, an option before the positional, the no-args default, and thelist/create/update/deletepositional forms.pytest tests/unit/test_cli_competitions.py→ 69 passedtests/unit→ 1535 passedblack --line-length 120 --checkclean;mypy src/kaggle/cli.py→ Success