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

KeyError or IndexError raised from click subcommand triggers 'Invalid/No subcommand' message. #1092

Closed
DropD opened this issue Jan 31, 2018 · 1 comment

Comments

@DropD
Copy link
Contributor

DropD commented Jan 31, 2018

in aiida/cmdline/baseclass.py:131:

try:
  the_class = self.routed_subcommands[args[0]]  # the click.Group of the subcommand
  ...
  function_to_call = the_class().run  # calls the group's __call__, which calls it's main()
  ## This is not what is intended. For this type of command we want
  ## function_to_call = the_class
  ## Actually, the .run would lead to an AttributeError, except that click commands terminate 
  ## with sys.exit() or raise an exception before execution gets there
  except IndexError:
    function_to_call = self.no_subcommand  # Gotcha!
    ## If the click subcommand's main() raises an IndexError
  except AttributeError:
    function_to_call = self.invalid_subcommand  # Gotcha!
    ## ditto for AttributeError
  function_to_call(*args[1:])
  ## This will print "<subcmd> is an invalid subcommand ..." 
  ## and then list <subcmd> as a valid subcommand
@sphuber
Copy link
Contributor

sphuber commented Jul 25, 2018

Fixed in #1795

@sphuber sphuber closed this as completed Jul 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants