[#2996] [Console] Fix duplicate commands in help output
- The duplicate entries were actually the aliases for commands but the command name not the alias was being returned.
This commit is contained in:
parent
966678196e
commit
8232505961
|
@ -189,7 +189,15 @@ class BaseCommand(object):
|
||||||
opts = {'prog': self.name_with_alias, 'help': self.__doc__, 'description': self.__doc__}
|
opts = {'prog': self.name_with_alias, 'help': self.__doc__, 'description': self.__doc__}
|
||||||
if self.usage:
|
if self.usage:
|
||||||
opts['usage'] = self.usage
|
opts['usage'] = self.usage
|
||||||
parser = subparsers.add_parser(self.name, **opts)
|
|
||||||
|
# A workaround for aliases showing as duplicate command names in help output.
|
||||||
|
for cmd_name in sorted([self.name] + self.aliases):
|
||||||
|
if cmd_name not in subparsers._name_parser_map:
|
||||||
|
if cmd_name in self.aliases:
|
||||||
|
opts['help'] = _('`%s` alias' % self.name)
|
||||||
|
parser = subparsers.add_parser(cmd_name, **opts)
|
||||||
|
break
|
||||||
|
|
||||||
self.add_arguments(parser)
|
self.add_arguments(parser)
|
||||||
|
|
||||||
def add_arguments(self, parser):
|
def add_arguments(self, parser):
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#
|
#
|
||||||
from __future__ import print_function, unicode_literals
|
from __future__ import print_function, unicode_literals
|
||||||
|
|
||||||
|
import fnmatch
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
@ -29,25 +30,25 @@ log = logging.getLogger(__name__)
|
||||||
def load_commands(command_dir):
|
def load_commands(command_dir):
|
||||||
|
|
||||||
def get_command(name):
|
def get_command(name):
|
||||||
return getattr(__import__('deluge.ui.console.cmdline.commands.%s' % name, {}, {}, ['Command']), 'Command')()
|
command = getattr(__import__('deluge.ui.console.cmdline.commands.%s' % name,
|
||||||
|
{}, {}, ['Command']), 'Command')()
|
||||||
|
command._name = name
|
||||||
|
return command
|
||||||
|
|
||||||
try:
|
try:
|
||||||
commands = []
|
dir_list = fnmatch.filter(os.listdir(command_dir), '*.py')
|
||||||
for filename in os.listdir(command_dir):
|
|
||||||
if filename.startswith('_'):
|
|
||||||
continue
|
|
||||||
if not (filename.endswith('.py') or filename.endswith('.pyc')):
|
|
||||||
continue
|
|
||||||
cmd = get_command(filename.split('.')[len(filename.split('.')) - 2])
|
|
||||||
aliases = [filename.split('.')[len(filename.split('.')) - 2]]
|
|
||||||
cmd._name = aliases[0]
|
|
||||||
aliases.extend(cmd.aliases)
|
|
||||||
for a in aliases:
|
|
||||||
commands.append((a, cmd))
|
|
||||||
return dict(commands)
|
|
||||||
except OSError:
|
except OSError:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
commands = []
|
||||||
|
for filename in dir_list:
|
||||||
|
if filename.startswith('_'):
|
||||||
|
continue
|
||||||
|
cmd = get_command(os.path.splitext(filename)[0])
|
||||||
|
for cmd_name in [cmd._name] + cmd.aliases:
|
||||||
|
commands.append((cmd_name, cmd))
|
||||||
|
return dict(commands)
|
||||||
|
|
||||||
|
|
||||||
class LogStream(object):
|
class LogStream(object):
|
||||||
out = sys.stdout
|
out = sys.stdout
|
||||||
|
@ -88,8 +89,8 @@ class Console(UI):
|
||||||
metavar=_('Command'), dest='command')
|
metavar=_('Command'), dest='command')
|
||||||
from deluge.ui.console import UI_PATH # Must import here
|
from deluge.ui.console import UI_PATH # Must import here
|
||||||
self.console_cmds = load_commands(os.path.join(UI_PATH, 'cmdline', 'commands'))
|
self.console_cmds = load_commands(os.path.join(UI_PATH, 'cmdline', 'commands'))
|
||||||
for c in sorted(self.console_cmds):
|
for cmd in sorted(self.console_cmds):
|
||||||
self.console_cmds[c].add_subparser(subparsers)
|
self.console_cmds[cmd].add_subparser(subparsers)
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
if self.ui_args is None:
|
if self.ui_args is None:
|
||||||
|
|
Loading…
Reference in New Issue