From fb5f8e9db392d9964e8f7be1da46b060b1ab2a66 Mon Sep 17 00:00:00 2001 From: "Adam J. Gamble" Date: Mon, 19 Nov 2012 22:19:24 +0000 Subject: [PATCH] Help option added. * fixed: load_all_commands broken path * added help(ful) summary to format.py --- colly/commands/__init__.py | 2 +- colly/commands/format.py | 5 ++--- colly/commands/help.py | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 colly/commands/help.py diff --git a/colly/commands/__init__.py b/colly/commands/__init__.py index 05287ca..0352b34 100644 --- a/colly/commands/__init__.py +++ b/colly/commands/__init__.py @@ -44,5 +44,5 @@ def load_all_commands(): load_command(name) def command_names(): - names = set((pkg[1] for pkg in walk_packages(path=commands.__path__))) + names = set((pkg[1] for pkg in walk_packages(path=__path__))) return list(names) diff --git a/colly/commands/format.py b/colly/commands/format.py index 757ce6b..0cd2cfc 100644 --- a/colly/commands/format.py +++ b/colly/commands/format.py @@ -1,5 +1,3 @@ -""" Turn collated CSV file into JSON, or other format -""" import sys import logging @@ -12,7 +10,8 @@ def headings_callback(option, opt, value, parser): class FormatCommand(Command): name = 'format' - usage= "%prog FILE [OPTIONS]" #: overwrites baseparser + usage = "%prog FILE [OPTIONS]" #: overwrites baseparser + summary = "Turn collated CSV file into JSON, or other format" def __init__(self): super(FormatCommand, self).__init__() diff --git a/colly/commands/help.py b/colly/commands/help.py new file mode 100644 index 0000000..e457c48 --- /dev/null +++ b/colly/commands/help.py @@ -0,0 +1,19 @@ +from colly.commands import (Command, command_dict, load_all_commands) +from colly.optbase import parser + +class HelpCommand(Command): + name = 'help' + usage = '%prog' + summary = 'Show available commands' + + def run(self, options, args): + load_all_commands() + parser.print_help() # general help, opts common to all commands + print '\nCommands available:' + commands = list(set(command_dict.values())) + commands.sort(key=lambda x: x.name) + for command in commands: + print ' %s: %s' % (command.name, command.summary) + return 0 + +HelpCommand() -- 2.11.4.GIT