avocado.cli.app: Display --help output on empty args list

Instead of displaying a not very helpful 'too few args'
message, let's display the full --help output on an
empty args list. Comes with a functional test.
Signed-off-by: NLucas Meneghel Rodrigues <lmr@redhat.com>
上级 f569ccd4
...@@ -17,6 +17,7 @@ The core Avocado application. ...@@ -17,6 +17,7 @@ The core Avocado application.
""" """
import os import os
import sys
from argparse import ArgumentParser from argparse import ArgumentParser
...@@ -64,7 +65,12 @@ class AvocadoApp(object): ...@@ -64,7 +65,12 @@ class AvocadoApp(object):
description='valid subcommands', description='valid subcommands',
help='subcommand help') help='subcommand help')
self.load_plugin_manager(args.plugins_dir) self.load_plugin_manager(args.plugins_dir)
args, _ = self.app_parser.parse_known_args()
default_args = None
if not sys.argv[1:]:
default_args = ['--help']
args, _ = self.app_parser.parse_known_args(args=default_args)
self.plugin_manager.activate(args) self.plugin_manager.activate(args)
self.args = self.app_parser.parse_args() self.args = self.app_parser.parse_args()
......
...@@ -154,6 +154,15 @@ class RunnerOperationTest(unittest.TestCase): ...@@ -154,6 +154,15 @@ class RunnerOperationTest(unittest.TestCase):
self.assertEqual(result.exit_status, expected_rc) self.assertEqual(result.exit_status, expected_rc)
self.assertEqual(result.stderr, expected_output) self.assertEqual(result.stderr, expected_output)
def test_empty_args_list(self):
os.chdir(basedir)
cmd_line = './scripts/avocado'
result = process.run(cmd_line, ignore_status=True)
expected_rc = 0
unexpected_output = 'too few arguments'
self.assertEqual(result.exit_status, expected_rc)
self.assertNotIn(unexpected_output, result.stdout)
def test_empty_test_list(self): def test_empty_test_list(self):
os.chdir(basedir) os.chdir(basedir)
cmd_line = './scripts/avocado run' cmd_line = './scripts/avocado run'
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册