Opened 15 years ago

Last modified 9 years ago

#2121 defect new

usage.Options breaks with short subcommand names longer than 1 char

Reported by: msalib Owned by:
Priority: low Milestone:
Component: core Keywords:
Cc: Branch:

Description (last modified by Glyph)

Generating help text for twisted.python.usage.Options when using subcommands that have a short name longer than one character triggers a TypeError. The TypeError is rather opaque and doesn't explain that short names are limited to one character. Even stranger, short names longer than one character work for parameters (at least they don't produce a TypeError).

I suggest the following:

  • the code would produce an error that explains which subcommand is causing problems and that short names are limited to a character.
  • the code for checking subcommand short names should do the same thing as the code that checks parameter short names (which just ignores improper short names)
  • the options howto should get a line added that indicates that short names are limited to a single character.

To test, write the following bit of code into a file, then run it with --help.

from twisted.python.usage import Options
class MySubOptions(Options):
class Options(Options):
    subCommands = [
        ["mine", "m", MySubOptions, "it is mine!"]]
config = Options()

Change History (4)

comment:1 Changed 15 years ago by Glyph

Description: modified (diff)

comment:2 Changed 15 years ago by Glyph

Existing code might be depending on the fact that invalid short names in parameters don't cause errors, so the approach I would suggest is unifying the code path for checking (as you suggest) and emitting a warning, rather than an error.

comment:3 Changed 11 years ago by <automation>

Owner: Glyph deleted

comment:4 Changed 9 years ago by Tom Prince

The documentation at suggests that the shortname of subcommands doesn't need to be single letter.

Note: See TracTickets for help on using tickets.