Gandi / gandi.cli

⚠ ARCHIVED - Command line interface to Gandi.net products using the public API
http://cli.gandi.net/
GNU General Public License v3.0
347 stars 62 forks source link

gandi dnssec create --help raises error #286

Closed guyzmo closed 5 years ago

guyzmo commented 5 years ago

what?

I installed gandi.cli with pip, on a rather old ubuntu (still python 3.4), click is version 7 (pip says it's latest):

% gandi dnssec create --help
Traceback (most recent call last):
  File "/usr/local/bin/gandi", line 10, in <module>
    sys.exit(main())
  File ".../gandi/cli/__main__.py", line 8, in main
    cli(obj={})
  File ".../click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File ".../click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File ".../gandi/cli/core/cli.py", line 163, in invoke
    click.Group.invoke(self, ctx)
  File ".../click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File ".../click/core.py", line 1135, in invoke
    sub_ctx = cmd.make_context(cmd_name, args, parent=ctx)
  File ".../click/core.py", line 641, in make_context
    self.parse_args(ctx, args)
  File ".../click/core.py", line 940, in parse_args
    value, args = param.handle_parse_result(ctx, opts, args)
  File ".../click/core.py", line 1477, in handle_parse_result                                                                                     
    self.callback, ctx, self, value)
  File ".../click/core.py", line 96, in invoke_param_callback                                                                                     
    return callback(ctx, param, value)
  File ".../click/core.py", line 860, in show_help
    echo(ctx.get_help(), color=ctx.color)
  File ".../click/core.py", line 516, in get_help
    return self.command.get_help(self)
  File ".../click/core.py", line 879, in get_help
    self.format_help(ctx, formatter)
  File ".../click/core.py", line 898, in format_help
    self.format_options(ctx, formatter)
  File ".../click/core.py", line 919, in format_options
    rv = param.get_help_record(ctx)
  File ".../click/core.py", line 1700, in get_help_record                                                                                         
    rv = [_write_opts(self.opts)]
  File ".../click/core.py", line 1697, in _write_opts
    rv += ' ' + self.make_metavar()
  File ".../click/core.py", line 1371, in make_metavar
    metavar = self.type.get_metavar(self)
  File ".../click/types.py", line 149, in get_metavar
    return '[%s]' % '|'.join(self.choices)
TypeError: sequence item 0: expected str instance, int found

expected?

Usage: gandi dnssec create [OPTIONS] RESOURCE

  Create DNSSEC key.

Options:
  --flags [256|257]               Flags (ZSK or KSK)
  --algorithm [1|2|3|5|6|7|8|10|12|13|14|15|16|253|254]
                                  Algorithm
  --public_key TEXT               Public key (base64-encoded)
  --help                          Show this message and exit.

  For detailed documentation, use `man gandi`.

Possible fixes?

either it's a case of my click version being too old (I did not upgrade it) and it supports integer choices parameter, but then the setup.py shall specify a minimum version for the depency

or click does not support integers in the choices parameter, and then the choices parameter shall be fixed as follows:

class AlgorithmType(click.Choice):
    """ Choice parameter to create DNSSEC key """

    name = 'algorithm'
    choices = ['1', '2', '3', '5', '6', '7', '8', '10', '12', '13', '14', '15', '16', '253', '254']

    def __init__(self):
        """ Initialize choices list. """
        pass

class FlagsType(click.Choice):
    """ Choice parameter to create DNSSEC key """

    name = 'flags'
    choices = ['256', '257']

    def __init__(self):
        """ Initialize choices list. """
        pass

I checked the second fix, and it works, so I can cook a PR if you can replicate and approve it's an issue.

grigouze commented 5 years ago

@guyzmo I created a PR for your problem https://github.com/Gandi/gandi.cli/pull/287

grigouze commented 5 years ago

@guyzmo It's merged