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

Incorect "usage" argument order for github backend #799

Closed
Prinzhorn opened this issue Sep 21, 2022 · 3 comments · Fixed by #847
Closed

Incorect "usage" argument order for github backend #799

Prinzhorn opened this issue Sep 21, 2022 · 3 comments · Fixed by #847
Labels

Comments

@Prinzhorn
Copy link

First time user here. I was finally able to successfully export GitHub data, thanks!

perceval github --help gives

usage: perceval [-h] [--category CATEGORY] [--tag TAG] [--filter-classified] [--from-date FROM_DATE] [--to-date TO_DATE] [--archive-path ARCHIVE_PATH] [--no-archive] [--fetch-archive]
                [--archived-since ARCHIVED_SINCE] [--no-ssl-verify] [-o OUTFILE] [--json-line] [--enterprise-url BASE_URL] [--sleep-for-rate] [--min-rate-to-sleep MIN_RATE_TO_SLEEP] [-t API_TOKEN [API_TOKEN ...]]
                [--github-app-id GITHUB_APP_ID] [--github-app-pk-filepath GITHUB_APP_PK_FILEPATH] [--max-items MAX_ITEMS] [--max-retries MAX_RETRIES] [--sleep-time SLEEP_TIME]
                owner repository

but it's actually

usage: perceval github owner repository [-h] [--category CATEGORY] [--tag TAG] [--filter-classified] [--from-date FROM_DATE] [--to-date TO_DATE] [--archive-path ARCHIVE_PATH] [--no-archive] [--fetch-archive]
                [--archived-since ARCHIVED_SINCE] [--no-ssl-verify] [-o OUTFILE] [--json-line] [--enterprise-url BASE_URL] [--sleep-for-rate] [--min-rate-to-sleep MIN_RATE_TO_SLEEP] [-t API_TOKEN [API_TOKEN ...]]
                [--github-app-id GITHUB_APP_ID] [--github-app-pk-filepath GITHUB_APP_PK_FILEPATH] [--max-items MAX_ITEMS] [--max-retries MAX_RETRIES] [--sleep-time SLEEP_TIME]
  1. It doesn't have the backend in the usage
  2. It has "owner repository" at the end, but they need to appear before the other arguments (it does list "positional arguments" first in the text that follows)

Maybe this is some weird standard way to output the usage, but I found it confusing and I think this would be better if it were in the correct order and included the backend in the usage.

@sduenas sduenas added the bug label Oct 3, 2022
@sduenas
Copy link
Member

sduenas commented Oct 3, 2022

You are right. This is a bug. Thanks for reporting it. It's the same behaviour with the other backeds too.

@vchrombie
Copy link
Member

Hi

  1. It doesn't have the backend in the usage

I fixed this by setting the prog correctly.

  1. It has "owner repository" at the end, but they need to appear before the other arguments (it does list "positional arguments" first in the text that follows)

The order of arguments in the help/usage seems to be automatically generated by the argparse library, and enforcing a fixed order, particularly for positional arguments, might not be straightforward. Do you have any thoughts on this? @sduenas

$ perceval github -h
[2024-08-12 17:58:47,081] - Sir Perceval is on his quest.
usage: perceval github [-h] [--category CATEGORY] [--tag TAG] [--filter-classified] [--from-date FROM_DATE] [--to-date TO_DATE] [--archive-path ARCHIVE_PATH] [--no-archive] [--fetch-archive]
                       [--archived-since ARCHIVED_SINCE] [--no-ssl-verify] [-o OUTFILE] [--json-line] [--enterprise-url BASE_URL] [--sleep-for-rate] [--min-rate-to-sleep MIN_RATE_TO_SLEEP]
                       [-t API_TOKEN [API_TOKEN ...]] [--github-app-id GITHUB_APP_ID] [--github-app-pk-filepath GITHUB_APP_PK_FILEPATH] [--max-items MAX_ITEMS] [--max-retries MAX_RETRIES]
                       [--sleep-time SLEEP_TIME]
                       owner repository

positional arguments:
  owner                 GitHub owner
  repository            GitHub repository

optional arguments:
  -h, --help            show this help message and exit
  
  . . .
  . . .

@vchrombie
Copy link
Member

The order of arguments in the help/usage seems to be automatically generated by the argparse library, and enforcing a fixed order, particularly for positional arguments, might not be straightforward.

Initially, it seemed that because GitHubCommand extends BackendCommand, the arguments defined in the constructor appeared first in the help message and then the backend specific positional arguments. However, it turns out that no matter the order in which the arguments are defined in the code, argparse automatically lists positional arguments at the end of the usage message but ensures they appear first in the description and during actual command execution.

Here is a small POC

import argparse

parser = argparse.ArgumentParser()
parser.add_argument('x', type=int, help='first value')
parser.add_argument('-f', type=int, help='second value')
args = parser.parse_args()
$ python script.py -h
usage: script.py [-h] [-f F] x

positional arguments:
  x           first value

optional arguments:
  -h, --help  show this help message and exit
  -f F        second value

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants