diff --git a/README.rst b/README.rst index 177f15143..66acc1d1d 100644 --- a/README.rst +++ b/README.rst @@ -132,12 +132,12 @@ System Requirements Python Packages --------------- * six >= 1.7.0 -* prettytable >= 0.7.0 -* click >= 5, < 7 -* requests >= 2.18.4 -* prompt_toolkit >= 0.53 +* ptable >= 0.9.2 +* click >= 7 +* requests >= 2.20.0 +* prompt_toolkit >= 2 * pygments >= 2.0.0 -* urllib3 >= 1.22 +* urllib3 >= 1.24 Copyright --------- diff --git a/SoftLayer/shell/completer.py b/SoftLayer/shell/completer.py index 1f59f3a53..fb94fd50e 100644 --- a/SoftLayer/shell/completer.py +++ b/SoftLayer/shell/completer.py @@ -24,18 +24,17 @@ def get_completions(self, document, complete_event): return _click_autocomplete(self.root, document.text_before_cursor) -# pylint: disable=stop-iteration-return def _click_autocomplete(root, text): """Completer generator for click applications.""" try: parts = shlex.split(text) except ValueError: - raise StopIteration + return location, incomplete = _click_resolve_command(root, parts) if not text.endswith(' ') and not incomplete and text: - raise StopIteration + return if incomplete and not incomplete[0:2].isalnum(): for param in location.params: diff --git a/SoftLayer/shell/core.py b/SoftLayer/shell/core.py index 32c250584..55a56e888 100644 --- a/SoftLayer/shell/core.py +++ b/SoftLayer/shell/core.py @@ -13,8 +13,8 @@ import traceback import click -from prompt_toolkit import auto_suggest as p_auto_suggest -from prompt_toolkit import shortcuts as p_shortcuts +from prompt_toolkit.auto_suggest import AutoSuggestFromHistory +from prompt_toolkit import PromptSession from SoftLayer.CLI import core from SoftLayer.CLI import environment @@ -48,12 +48,14 @@ def cli(ctx, env): os.makedirs(app_path) complete = completer.ShellCompleter(core.cli) + session = PromptSession() + while True: try: - line = p_shortcuts.prompt( + line = session.prompt( completer=complete, complete_while_typing=True, - auto_suggest=p_auto_suggest.AutoSuggestFromHistory(), + auto_suggest=AutoSuggestFromHistory(), ) # Parse arguments diff --git a/SoftLayer/testing/__init__.py b/SoftLayer/testing/__init__.py index d5279c03f..87d7f5e41 100644 --- a/SoftLayer/testing/__init__.py +++ b/SoftLayer/testing/__init__.py @@ -157,7 +157,7 @@ def set_mock(self, service, method): """Set and return mock on the current client.""" return self.mocks.set_mock(service, method) - def run_command(self, args=None, env=None, fixtures=True, fmt='json'): + def run_command(self, args=None, env=None, fixtures=True, fmt='json', stdin=None): """A helper that runs a SoftLayer CLI command. This returns a click.testing.Result object. @@ -169,7 +169,7 @@ def run_command(self, args=None, env=None, fixtures=True, fmt='json'): args.insert(0, '--format=%s' % fmt) runner = testing.CliRunner() - return runner.invoke(core.cli, args=args, obj=env or self.env) + return runner.invoke(core.cli, args=args, input=stdin, obj=env or self.env) def call_has_props(call, props): diff --git a/setup.py b/setup.py index abe08c52e..692ef789d 100644 --- a/setup.py +++ b/setup.py @@ -34,7 +34,7 @@ 'ptable >= 0.9.2', 'click >= 7', 'requests >= 2.20.0', - 'prompt_toolkit >= 0.53', + 'prompt_toolkit >= 2', 'pygments >= 2.0.0', 'urllib3 >= 1.24' ], diff --git a/tests/CLI/modules/shell_tests.py b/tests/CLI/modules/shell_tests.py deleted file mode 100644 index bf71d7004..000000000 --- a/tests/CLI/modules/shell_tests.py +++ /dev/null @@ -1,27 +0,0 @@ -""" - SoftLayer.tests.CLI.modules.shell_tests - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - :license: MIT, see LICENSE for more details. -""" -from SoftLayer import testing - -import mock - - -class ShellTests(testing.TestCase): - @mock.patch('prompt_toolkit.shortcuts.prompt') - def test_shell_quit(self, prompt): - prompt.return_value = "quit" - result = self.run_command(['shell']) - self.assertEqual(result.exit_code, 0) - - @mock.patch('prompt_toolkit.shortcuts.prompt') - @mock.patch('shlex.split') - def test_shell_help(self, prompt, split): - split.side_effect = [(['help']), (['vs', 'list']), (False), (['quit'])] - prompt.return_value = "none" - result = self.run_command(['shell']) - if split.call_count is not 5: - raise Exception("Split not called correctly. Count: " + str(split.call_count)) - self.assertEqual(result.exit_code, 1) diff --git a/tools/requirements.txt b/tools/requirements.txt index cd4a89429..0d7746444 100644 --- a/tools/requirements.txt +++ b/tools/requirements.txt @@ -2,6 +2,6 @@ six >= 1.7.0 ptable >= 0.9.2 click >= 7 requests >= 2.20.0 -prompt_toolkit >= 0.53 +prompt_toolkit >= 2 pygments >= 2.0.0 urllib3 >= 1.24 \ No newline at end of file diff --git a/tools/test-requirements.txt b/tools/test-requirements.txt index 56ba8fe65..2869de5e6 100644 --- a/tools/test-requirements.txt +++ b/tools/test-requirements.txt @@ -8,6 +8,6 @@ six >= 1.7.0 ptable >= 0.9.2 click >= 7 requests >= 2.20.0 -prompt_toolkit >= 0.53 +prompt_toolkit >= 2 pygments >= 2.0.0 urllib3 >= 1.24 \ No newline at end of file