We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
I was testing click and created a subcommand that expects a list of hostnames as arguments. See:
import click @click.command() @click.argument('hostnames', nargs=-1) def subcommand(hostnames): print('Executing subcommand') print(hostnames) @click.group() def main(): pass main.add_command(subcommand) if __name__ == '__main__': main()
Calling python3 clicktst.py subcommand host1 host2 returns: (None,) instead of the list of hostnames.
python3 clicktst.py subcommand host1 host2
To correct this you need to change Argument.consume_value from
def consume_value(self, ctx, opts, args): found = True if self.nargs == 1: try: value = args.pop(0) except IndexError: found = False elif self.nargs < 0: value = tuple(args) found = not value args = [] else: values = args[:self.nargs] values += [None] * (self.nargs - len(values)) args = args[self.nargs:] value = tuple(values) found = not value if not found: value = self.value_from_envvar(ctx) if self.nargs != 1: value = (value,) return value, args
to
def consume_value(self, ctx, opts, args): found = True if self.nargs == 1: try: value = args.pop(0) except IndexError: found = False elif self.nargs < 0: value = tuple(args) found = bool(value) args = [] else: values = args[:self.nargs] values += [None] * (self.nargs - len(values)) args = args[self.nargs:] value = tuple(values) found = not value if not found: value = self.value_from_envvar(ctx) if self.nargs != 1: value = (value,) return value, args
The difference is on the line 1217: found = not value becomes found = bool(value)
found = not value
found = bool(value)
The text was updated successfully, but these errors were encountered:
#20
Sorry, something went wrong.
That bug was already fixed. Sorry for that.
No branches or pull requests
I was testing click and created a subcommand that expects a list of hostnames as arguments. See:
Calling
python3 clicktst.py subcommand host1 host2
returns:(None,)
instead of the list of hostnames.
To correct this you need to change Argument.consume_value
from
to
The difference is on the line 1217:
found = not value
becomesfound = bool(value)
The text was updated successfully, but these errors were encountered: