summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cliapp/app.py4
-rw-r--r--example2.py10
2 files changed, 12 insertions, 2 deletions
diff --git a/cliapp/app.py b/cliapp/app.py
index 9812f0d..1aa35cb 100644
--- a/cliapp/app.py
+++ b/cliapp/app.py
@@ -287,6 +287,10 @@ class Application(object):
return cliapp.TextFormat(*a, **kw)
+ def get_subcommand_usage(self, cmd): # pragma: no cover
+ return 'usage: %s %s %s' % (self.settings.progname,
+ cmd, self.cmd_synopsis[cmd])
+
def _help_helper(self, args, show_all): # pragma: no cover
try:
width = int(os.environ.get('COLUMNS', '78'))
diff --git a/example2.py b/example2.py
index 972e880..fcee592 100644
--- a/example2.py
+++ b/example2.py
@@ -28,8 +28,8 @@ import cliapp
class ExampleApp(cliapp.Application):
cmd_synopsis = {
- 'greet': '[USER]...',
- 'insult': '[USER]...',
+ 'greet': 'USER...',
+ 'insult': 'USER...',
}
def cmd_greet(self, args):
@@ -39,6 +39,9 @@ class ExampleApp(cliapp.Application):
but terse form of greeting.
'''
+ if len(args) == 0:
+ raise cliapp.AppException(self.get_subcommand_usage('greet'))
+
for arg in args:
self.output.write('greetings, %s\n' % arg)
@@ -49,6 +52,9 @@ class ExampleApp(cliapp.Application):
a prat, and needs to be told off. This is the command for that.
'''
+ if len(args) == 0:
+ raise cliapp.AppException(self.get_subcommand_usage('insult'))
+
for arg in args:
self.output.write('you suck, %s\n' % arg)