Merge lp:~pwlars/lava-test/help into lp:lava-test/0.0

Proposed by Paul Larson
Status: Merged
Merged at revision: 11
Proposed branch: lp:~pwlars/lava-test/help
Merge into: lp:lava-test/0.0
Diff against target: 109 lines (+51/-10)
2 files modified
abrek/builtins.py (+48/-10)
abrek/command.py (+3/-0)
To merge this branch: bzr merge lp:~pwlars/lava-test/help
Reviewer Review Type Date Requested Status
James Westby (community) Approve
Review via email: mp+29121@code.launchpad.net

Description of the change

Simple help command and help provided for the existing commands

To post a comment you must log in.
Revision history for this message
James Westby (james-w) wrote :

36 + print getdoc(cmd)

should you use the help() function you put on cmd?

39 + except IndexError:

I would not use try/except, and just check len(argv), as the intent
is clearer, and it won't mask other issues.

I would also be happy to see some tests of at least the
infrastructure, if not the commands themselves.

Thanks,

James

review: Approve
lp:~pwlars/lava-test/help updated
12. By Paul Larson

use AbrekCmd.help()

13. By Paul Larson

return instead of print help

Revision history for this message
Paul Larson (pwlars) wrote :

> 36 + print getdoc(cmd)
>
> should you use the help() function you put on cmd?
Ah yes, fixed that

> 39 + except IndexError:
>
> I would not use try/except, and just check len(argv), as the intent
> is clearer, and it won't mask other issues.
also fixed

> I would also be happy to see some tests of at least the
> infrastructure, if not the commands themselves.
I'll add some new tests shortly

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'abrek/builtins.py'
2--- abrek/builtins.py 2010-06-29 22:33:29 +0000
3+++ abrek/builtins.py 2010-07-02 22:19:21 +0000
4@@ -1,43 +1,81 @@
5 import sys
6
7-from abrek.command import AbrekCmd
8-from abrek.testdef import testloader
9-
10-class cmd_version(AbrekCmd):
11+import abrek
12+
13+class cmd_version(abrek.command.AbrekCmd):
14+ """ Show the version of abrek
15+
16+ Usage: abrek version
17+ """
18 def run(self, argv):
19 import abrek
20 print abrek.__version__
21
22-class cmd_install(AbrekCmd):
23+class cmd_help(abrek.command.AbrekCmd):
24+ """ Get help on abrek commands
25+
26+ Usage: abrek help [command]
27+
28+ If the command name is ommited, calling the help command will return a
29+ list of valid commands.
30+ """
31+ def run(self, argv):
32+ if len(argv) != 1:
33+ print "Available commands:"
34+ for cmd in abrek.command.get_all_cmds():
35+ print " %s" % cmd
36+ print
37+ print "To access extended help on a command use 'abrek help " \
38+ "[command]'"
39+ else:
40+ cmd = abrek.command.get_command(argv[0])
41+ if cmd:
42+ print cmd.help()
43+ else:
44+ print "No command found for '%s'" % argv[0]
45+
46+class cmd_install(abrek.command.AbrekCmd):
47+ """ Install a test
48+
49+ Usage: abrek install TEST_NAME
50+ """
51 def run(self, argv):
52 if len(argv) != 1:
53 print "please specify the name of the test to install"
54 sys.exit(1)
55- test = testloader(argv[0])
56+ test = abrek.testdef.testloader(argv[0])
57 try:
58 test.install()
59 except RuntimeError as strerror:
60 print "Test installation error: %s" % strerror
61 sys.exit(1)
62
63-class cmd_run(AbrekCmd):
64+class cmd_run(abrek.command.AbrekCmd):
65+ """ Run tests
66+
67+ Usage: abrek run TEST_NAME
68+ """
69 def run(self, argv):
70 if len(argv) != 1:
71 print "please specify the name of the test to run"
72 sys.exit(1)
73- test = testloader(argv[0])
74+ test = abrek.testdef.testloader(argv[0])
75 try:
76 test.run()
77 except Exception as strerror:
78 print "Test execution error: %s" % strerror
79 sys.exit(1)
80
81-class cmd_uninstall(AbrekCmd):
82+class cmd_uninstall(abrek.command.AbrekCmd):
83+ """ Uninstall a test
84+
85+ Usage: abrek uninstall TEST_NAME
86+ """
87 def run(self, argv):
88 if len(argv) != 1:
89 print "please specify the name of the test to uninstall"
90 sys.exit(1)
91- test = testloader(argv[0])
92+ test = abrek.testdef.testloader(argv[0])
93 try:
94 test.uninstall()
95 except Exception as strerror:
96
97=== modified file 'abrek/command.py'
98--- abrek/command.py 2010-06-21 17:23:54 +0000
99+++ abrek/command.py 2010-07-02 22:19:21 +0000
100@@ -9,6 +9,9 @@
101 def run(self, argv):
102 raise NotImplementedError("%s: command defined but not implemented!" %
103 self.name())
104+ def help(self):
105+ from inspect import getdoc
106+ return getdoc(self)
107
108 def _convert_command_name(cmd):
109 return cmd[4:].replace('_','-')

Subscribers

People subscribed via source and target branches