diff options
author | Jenkins <jenkins@review.openstack.org> | 2015-02-25 23:52:23 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2015-02-25 23:52:23 +0000 |
commit | fb2df8bd4215965fdc13d9cf3c6cdaa0c88e1509 (patch) | |
tree | 98d4aa597fb60f4cd89b5bed27d872230cb8f145 | |
parent | 01c8d8f05cb404d9f06745f24c431f83edec54bf (diff) | |
parent | da46b647aadd9ffdaab62ed82dcd660e39078904 (diff) | |
download | cliff-fb2df8bd4215965fdc13d9cf3c6cdaa0c88e1509.tar.gz |
Merge "Add deprecated attribute to commands"
-rw-r--r-- | cliff/command.py | 3 | ||||
-rw-r--r-- | cliff/help.py | 2 | ||||
-rw-r--r-- | cliff/tests/test_help.py | 19 | ||||
-rw-r--r-- | cliff/tests/utils.py | 6 |
4 files changed, 30 insertions, 0 deletions
diff --git a/cliff/command.py b/cliff/command.py index 7dfe749..cba75b5 100644 --- a/cliff/command.py +++ b/cliff/command.py @@ -13,6 +13,9 @@ class Command(object): :param app: Application instance invoking the command. :paramtype app: cliff.app.App """ + + deprecated = False + def __init__(self, app, app_args): self.app = app self.app_args = app_args diff --git a/cliff/help.py b/cliff/help.py index 9d96111..0b29bf2 100644 --- a/cliff/help.py +++ b/cliff/help.py @@ -27,6 +27,8 @@ class HelpAction(argparse.Action): continue try: cmd = factory(app, None) + if cmd.deprecated: + continue except Exception as err: app.stdout.write('Could not instantiate %r: %s\n' % (ep, err)) if namespace.debug: diff --git a/cliff/tests/test_help.py b/cliff/tests/test_help.py index db106a5..19eaedc 100644 --- a/cliff/tests/test_help.py +++ b/cliff/tests/test_help.py @@ -91,3 +91,22 @@ def test_show_help_for_help(): pass help_text = stdout.getvalue() assert 'usage: test help [-h]' in help_text + + +def test_list_deprecated_commands(): + # FIXME(dhellmann): Are commands tied too closely to the app? Or + # do commands know too much about apps by using them to get to the + # command manager? + stdout = StringIO() + app = App('testing', '1', + utils.TestCommandManager(utils.TEST_NAMESPACE), + stdout=stdout) + app.NAME = 'test' + try: + app.run(['--help']) + except SystemExit: + pass + help_output = stdout.getvalue() + assert 'two words' in help_output + assert 'three word command' in help_output + assert 'old cmd' not in help_output diff --git a/cliff/tests/utils.py b/cliff/tests/utils.py index bcab2a2..2fde1e0 100644 --- a/cliff/tests/utils.py +++ b/cliff/tests/utils.py @@ -22,9 +22,15 @@ class TestCommand(Command): return +class TestDeprecatedCommand(TestCommand): + + deprecated = True + + class TestCommandManager(CommandManager): def load_commands(self, namespace): if namespace == TEST_NAMESPACE: for key in ('one', 'two words', 'three word command'): self.add_command(key, TestCommand) + self.add_command('old cmd', TestDeprecatedCommand) |