Skip to content

Commit 46df1c1

Browse files
committed
Merged from master and resolved conflicts in cmd2.py
2 parents fe4b3fd + de70108 commit 46df1c1

26 files changed

+66
-600
lines changed

CHANGELOG.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
## 0.9.11 (TBD, 2019)
22
* Enhancements
33
* Added ``matches_sort_key`` to override the default way tab completion matches are sorted
4-
* Deprecations
5-
* Deprecated support for bash completion since this feature had slow performance. Also it relied on
6-
``AutoCompleter`` which has since developed a dependency on ``cmd2`` methods.
74
* Potentially breaking changes
85
* Made ``cmd2_app`` a positional and required argument of ``AutoCompleter`` since certain functionality now
96
requires that it can't be ``None``.
107
* ``AutoCompleter`` no longer assumes ``CompletionItem`` results are sorted. Therefore you should follow the
118
``cmd2`` convention of setting ``self.matches_sorted`` to True before returning the results if you have already
129
sorted the ``CompletionItem`` list. Otherwise it will be sorted using ``self.matches_sort_key``.
10+
* Removed support for bash completion since this feature had slow performance. Also it relied on
11+
``AutoCompleter`` which has since developed a dependency on ``cmd2`` methods.
12+
* Removed ability to call commands in ``pyscript`` as if they were functions (e.g ``app.help()``) in favor
13+
of only supporting one ``pyscript`` interface. This simplifies future maintenance.
1314

1415
## 0.9.10 (February 22, 2019)
1516
* Bug Fixes

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ Instructions for implementing each feature follow.
117117
- Syntax for calling `cmd2` commands in a `pyscript` is essentially identical to what they would enter on the command line
118118
- See the [Python](https://cmd2.readthedocs.io/en/latest/freefeatures.html#python) section of the `cmd2` docs for more info
119119
- Also see the [python_scripting.py](https://github.com/python-cmd2/cmd2/blob/master/examples/python_scripting.py)
120-
example in conjunciton with the [conditional.py](https://github.com/python-cmd2/cmd2/blob/master/examples/scripts/conditional.py) script
120+
example in conjunction with the [conditional.py](https://github.com/python-cmd2/cmd2/blob/master/examples/scripts/conditional.py) script
121121

122122
- Parsing commands with `argparse`
123123
- Two decorators provide built-in capability for using `argparse.ArgumentParser` to parse command arguments

cmd2/argparse_completer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ def __init__(self, *args, **kwargs) -> None:
988988
self._custom_error_message = ''
989989

990990
# Begin cmd2 customization
991-
def set_custom_message(self, custom_message: str='') -> None:
991+
def set_custom_message(self, custom_message: str = '') -> None:
992992
"""
993993
Allows an error message override to the error() function, useful when forcing a
994994
re-parse of arguments with newly required parameters

cmd2/cmd2.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def cat_decorator(func):
177177

178178

179179
def with_argument_list(func: Callable[[Statement], Optional[bool]],
180-
preserve_quotes: bool=False) -> Callable[[List], Optional[bool]]:
180+
preserve_quotes: bool = False) -> Callable[[List], Optional[bool]]:
181181
"""A decorator to alter the arguments passed to a do_* cmd2 method. Default passes a string of whatever the user
182182
typed. With this decorator, the decorated method will receive a list of arguments parsed from user input using
183183
shlex.split().
@@ -197,7 +197,7 @@ def cmd_wrapper(self, cmdline):
197197
return cmd_wrapper
198198

199199

200-
def with_argparser_and_unknown_args(argparser: argparse.ArgumentParser, preserve_quotes: bool=False) -> \
200+
def with_argparser_and_unknown_args(argparser: argparse.ArgumentParser, preserve_quotes: bool = False) -> \
201201
Callable[[argparse.Namespace, List], Optional[bool]]:
202202
"""A decorator to alter a cmd2 method to populate its ``args`` argument by parsing arguments with the given
203203
instance of argparse.ArgumentParser, but also returning unknown args as a list.
@@ -240,7 +240,7 @@ def cmd_wrapper(instance, cmdline):
240240

241241

242242
def with_argparser(argparser: argparse.ArgumentParser,
243-
preserve_quotes: bool=False) -> Callable[[argparse.Namespace], Optional[bool]]:
243+
preserve_quotes: bool = False) -> Callable[[argparse.Namespace], Optional[bool]]:
244244
"""A decorator to alter a cmd2 method to populate its ``args`` argument by parsing arguments
245245
with the given instance of argparse.ArgumentParser.
246246
@@ -342,9 +342,9 @@ class Cmd(cmd.Cmd):
342342
'quiet': "Don't print nonessential feedback",
343343
'timing': 'Report execution times'}
344344

345-
def __init__(self, completekey: str='tab', stdin=None, stdout=None, persistent_history_file: str='',
346-
persistent_history_length: int=1000, startup_script: Optional[str]=None, use_ipython: bool=False,
347-
transcript_files: Optional[List[str]]=None) -> None:
345+
def __init__(self, completekey: str = 'tab', stdin=None, stdout=None, persistent_history_file: str = '',
346+
persistent_history_length: int = 1000, startup_script: Optional[str] = None, use_ipython: bool = False,
347+
transcript_files: Optional[List[str]] = None) -> None:
348348
"""An easy but powerful framework for writing line-oriented command interpreters, extends Python's cmd package.
349349
350350
:param completekey: (optional) readline name of a completion key, default to Tab
@@ -562,7 +562,7 @@ def decolorized_write(self, fileobj: IO, msg: str) -> None:
562562
msg = utils.strip_ansi(msg)
563563
fileobj.write(msg)
564564

565-
def poutput(self, msg: Any, end: str='\n', color: str='') -> None:
565+
def poutput(self, msg: Any, end: str = '\n', color: str = '') -> None:
566566
"""Smarter self.stdout.write(); color aware and adds newline of not present.
567567
568568
Also handles BrokenPipeError exceptions for when a commands's output has
@@ -590,8 +590,8 @@ def poutput(self, msg: Any, end: str='\n', color: str='') -> None:
590590
if self.broken_pipe_warning:
591591
sys.stderr.write(self.broken_pipe_warning)
592592

593-
def perror(self, err: Union[str, Exception], traceback_war: bool=True, err_color: str=Fore.LIGHTRED_EX,
594-
war_color: str=Fore.LIGHTYELLOW_EX) -> None:
593+
def perror(self, err: Union[str, Exception], traceback_war: bool = True, err_color: str = Fore.LIGHTRED_EX,
594+
war_color: str = Fore.LIGHTYELLOW_EX) -> None:
595595
""" Print error message to sys.stderr and if debug is true, print an exception Traceback if one exists.
596596
597597
:param err: an Exception or error message to print out
@@ -624,7 +624,7 @@ def pfeedback(self, msg: str) -> None:
624624
else:
625625
self.decolorized_write(sys.stderr, "{}\n".format(msg))
626626

627-
def ppaged(self, msg: str, end: str='\n', chop: bool=False) -> None:
627+
def ppaged(self, msg: str, end: str = '\n', chop: bool = False) -> None:
628628
"""Print output using a pager if it would go off screen and stdout isn't currently being redirected.
629629
630630
Never uses a pager inside of a script (Python or text) or when output is being redirected or piped or when
@@ -906,7 +906,7 @@ def delimiter_complete(self, text: str, line: str, begidx: int, endidx: int, mat
906906

907907
def flag_based_complete(self, text: str, line: str, begidx: int, endidx: int,
908908
flag_dict: Dict[str, Union[Iterable, Callable]],
909-
all_else: Union[None, Iterable, Callable]=None) -> List[str]:
909+
all_else: Union[None, Iterable, Callable] = None) -> List[str]:
910910
"""
911911
Tab completes based on a particular flag preceding the token being completed
912912
:param text: the string prefix we are attempting to match (all returned matches must begin with it)
@@ -1161,7 +1161,7 @@ def get_exes_in_path(starts_with: str) -> List[str]:
11611161
return list(exes_set)
11621162

11631163
def shell_cmd_complete(self, text: str, line: str, begidx: int, endidx: int,
1164-
complete_blank: bool=False) -> List[str]:
1164+
complete_blank: bool = False) -> List[str]:
11651165
"""Performs completion of executables either in a user's path or a given path
11661166
:param text: the string prefix we are attempting to match (all returned matches must begin with it)
11671167
:param line: the current input line with leading whitespace removed
@@ -2587,7 +2587,7 @@ def do_help(self, args: argparse.Namespace) -> None:
25872587
# No special behavior needed, delegate to cmd base class do_help()
25882588
super().do_help(args.command)
25892589

2590-
def _help_menu(self, verbose: bool=False) -> None:
2590+
def _help_menu(self, verbose: bool = False) -> None:
25912591
"""Show a list of commands which help can be displayed for.
25922592
"""
25932593
# Get a sorted list of help topics
@@ -2730,7 +2730,8 @@ def do_quit(self, _: argparse.Namespace) -> bool:
27302730
self._should_quit = True
27312731
return self._STOP_AND_EXIT
27322732

2733-
def select(self, opts: Union[str, List[str], List[Tuple[Any, Optional[str]]]], prompt: str='Your choice? ') -> str:
2733+
def select(self, opts: Union[str, List[str], List[Tuple[Any, Optional[str]]]],
2734+
prompt: str = 'Your choice? ') -> str:
27342735
"""Presents a numbered menu to the user. Modeled after
27352736
the bash shell's SELECT. Returns the item chosen.
27362737
@@ -2786,7 +2787,7 @@ def cmdenvironment(self) -> str:
27862787
Output redirection and pipes allowed: {}"""
27872788
return read_only_settings.format(str(self.terminators), self.allow_cli_args, self.allow_redirection)
27882789

2789-
def show(self, args: argparse.Namespace, parameter: str='') -> None:
2790+
def show(self, args: argparse.Namespace, parameter: str = '') -> None:
27902791
"""Shows current settings of parameters.
27912792
27922793
:param args: argparse parsed arguments from the set command
@@ -3604,7 +3605,7 @@ def set_window_title(self, title: str) -> None: # pragma: no cover
36043605
else:
36053606
raise RuntimeError("another thread holds terminal_lock")
36063607

3607-
def cmdloop(self, intro: Optional[str]=None) -> None:
3608+
def cmdloop(self, intro: Optional[str] = None) -> None:
36083609
"""This is an outer wrapper around _cmdloop() which deals with extra features provided by cmd2.
36093610
36103611
_cmdloop() provides the main loop equivalent to cmd.cmdloop(). This is a wrapper around that which deals with

0 commit comments

Comments
 (0)