datalad / datalad

Keep code, data, containers under control with git and git-annex

Home Page:http://datalad.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Extension command line argument in conflict with `datalad` level argument

candleindark opened this issue · comments

https://github.com/datalad/datalad-extension-template/blob/793c5543b8f1385e007ceb2b8cd1db667b9d38e6/datalad_helloworld/hello_cmd.py#L37

The -l command argument above doesn't work. datalad seems to be interpreting it as a datalad level argument instead of an extension level argument.

❯ datalad hello-cmd -l de
usage: datalad [-c (:name|name=value)] [-C PATH] [--cmd] [-l LEVEL] [--on-failure {ignore,continue,stop}] [--report-status {success,failure,ok,notneeded,impossible,error}] [--report-type {dataset,file}]
               [-f {generic,json,json_pp,tailored,disabled,'<template>'}] [--dbg] [--idbg] [--version]
               {create-sibling-github,create-sibling-gitlab,create-sibling-gogs,create-sibling-gin,create-sibling-gitea,create-sibling-ria,create-sibling,siblings,update,subdatasets,drop,remove,addurls,copy-file,download-url,foreach-dataset,install,rerun,run-procedure,create,save,status,clone,get,push,run,diff,configuration,wtf,clean,add-archive-content,add-readme,export-archive,export-archive-ora,export-to-figshare,no-annex,check-dates,unlock,uninstall,create-test-dataset,sshrun,shell-completion}
               ...
datalad: error: argument {create-sibling-github,create-sibling-gitlab,create-sibling-gogs,create-sibling-gin,create-sibling-gitea,create-sibling-ria,create-sibling,siblings,update,subdatasets,drop,remove,addurls,copy-file,download-url,foreach-dataset,install,rerun,run-procedure,create,save,status,clone,get,push,run,diff,configuration,wtf,clean,add-archive-content,add-readme,export-archive,export-archive-ora,export-to-figshare,no-annex,check-dates,unlock,uninstall,create-test-dataset,sshrun,shell-completion}: invalid choice: 'hello-cmd' (choose from 'create-sibling-github', 'create-sibling-gitlab', 'create-sibling-gogs', 'create-sibling-gin', 'create-sibling-gitea', 'create-sibling-ria', 'create-sibling', 'siblings', 'update', 'subdatasets', 'drop', 'remove', 'addurls', 'copy-file', 'download-url', 'foreach-dataset', 'install', 'rerun', 'run-procedure', 'create', 'save', 'status', 'clone', 'get', 'push', 'run', 'diff', 'configuration', 'wtf', 'clean', 'add-archive-content', 'add-readme', 'export-archive', 'export-archive-ora', 'export-to-figshare', 'no-annex', 'check-dates', 'unlock', 'uninstall', 'create-test-dataset', 'sshrun', 'shell-completion')

Changing -l to -x, args=("-x", "--language"), works just fine.

❯ datalad hello-cmd -x de
demo(ok): /Users/isaac/Developer/Dartmouth/workshop/datalad-extension-template [Tachchen!]

could be -L or even just --language alone. Care to submit a PR with the one you like?

could be -L or even just --language alone. Care to submit a PR with the one you like?

Sure we can do that. But that's not my concern though. Why shouldn't -l work? It should be interpreted as a command argument for the extension.

I thought it was a generic known issue, but I searched myself into

  • #6980
    which we actually fixed for, so sounds like yet another bug for this flavor ;-)

I think it belongs to the main repo, will transfer

here is some food for thought:

❯ DATALAD_LOG_LEVEL=2 datalad  hello-cmd -l de
[Level 5] Instantiating ssh manager 
...
[Level 8] argument -l/--log-level: invalid choice: 'de' (choose from 'critical', 'error', 'warning', 'info', 'debug', '1', '2', '3', '4', '5', '6', '7', '8', '9') [parser.py:single_subparser_possible:356,argparse.py:_parse_known_args:2126,argparse.py:consume_optional:2066,argparse.py:take_action:1974,argparse.py:_get_values:2509,argparse.py:_check_value:2565] 
[DEBUG  ] Early parsing failed with ArgumentError(argument -l/--log-level: invalid choice: 'de' (choose from 'critical', 'error', 'warning', 'info', 'debug', '1', '2', '3', '4', '5', '6', '7', '8', '9')) 
...

and

❯ DATALAD_LOG_LEVEL=2 datalad hello-cmd 2>&1 | grep hellow
[DEBUG] Loading entrypoint helloworld from datalad.extensions 
[DEBUG] Loaded entrypoint helloworld from datalad.extensions 
[Level 5] Importing module datalad_helloworld.hello_cmd  
[DEBUG] Building doc for <class 'datalad_helloworld.hello_cmd.HelloWorld'> 
[DEBUG] Determined class of decorated function: <class 'datalad_helloworld.hello_cmd.HelloWorld'> 
[Level 2] Returning generator_func from eval_func for <class 'datalad_helloworld.hello_cmd.HelloWorld'> 
❯ DATALAD_LOG_LEVEL=2 datalad hello-cmd -l de 2>&1 | grep hellow
❯ 

so if we get that early fail - we seems to not bother importing extensions via entry points.