Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

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

## 0.9.10 (February 22, 2019)
* Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Instructions for implementing each feature follow.
- Syntax for calling `cmd2` commands in a `pyscript` is essentially identical to what they would enter on the command line
- See the [Python](https://cmd2.readthedocs.io/en/latest/freefeatures.html#python) section of the `cmd2` docs for more info
- Also see the [python_scripting.py](https://github.com/python-cmd2/cmd2/blob/master/examples/python_scripting.py)
example in conjunciton with the [conditional.py](https://github.com/python-cmd2/cmd2/blob/master/examples/scripts/conditional.py) script
example in conjunction with the [conditional.py](https://github.com/python-cmd2/cmd2/blob/master/examples/scripts/conditional.py) script

- Parsing commands with `argparse`
- Two decorators provide built-in capability for using `argparse.ArgumentParser` to parse command arguments
Expand Down
2 changes: 1 addition & 1 deletion cmd2/argparse_completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ def __init__(self, *args, **kwargs) -> None:
self._custom_error_message = ''

# Begin cmd2 customization
def set_custom_message(self, custom_message: str='') -> None:
def set_custom_message(self, custom_message: str = '') -> None:
"""
Allows an error message override to the error() function, useful when forcing a
re-parse of arguments with newly required parameters
Expand Down
35 changes: 18 additions & 17 deletions cmd2/cmd2.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def cat_decorator(func):


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


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


def with_argparser(argparser: argparse.ArgumentParser,
preserve_quotes: bool=False) -> Callable[[argparse.Namespace], Optional[bool]]:
preserve_quotes: bool = False) -> Callable[[argparse.Namespace], Optional[bool]]:
"""A decorator to alter a cmd2 method to populate its ``args`` argument by parsing arguments
with the given instance of argparse.ArgumentParser.

Expand Down Expand Up @@ -365,9 +365,9 @@ class Cmd(cmd.Cmd):
'quiet': "Don't print nonessential feedback",
'timing': 'Report execution times'}

def __init__(self, completekey: str='tab', stdin=None, stdout=None, persistent_history_file: str='',
persistent_history_length: int=1000, startup_script: Optional[str]=None, use_ipython: bool=False,
transcript_files: Optional[List[str]]=None) -> None:
def __init__(self, completekey: str = 'tab', stdin=None, stdout=None, persistent_history_file: str = '',
persistent_history_length: int = 1000, startup_script: Optional[str] = None, use_ipython: bool = False,
transcript_files: Optional[List[str]] = None) -> None:
"""An easy but powerful framework for writing line-oriented command interpreters, extends Python's cmd package.

:param completekey: (optional) readline name of a completion key, default to Tab
Expand Down Expand Up @@ -585,7 +585,7 @@ def decolorized_write(self, fileobj: IO, msg: str) -> None:
msg = utils.strip_ansi(msg)
fileobj.write(msg)

def poutput(self, msg: Any, end: str='\n', color: str='') -> None:
def poutput(self, msg: Any, end: str = '\n', color: str = '') -> None:
"""Smarter self.stdout.write(); color aware and adds newline of not present.

Also handles BrokenPipeError exceptions for when a commands's output has
Expand Down Expand Up @@ -613,8 +613,8 @@ def poutput(self, msg: Any, end: str='\n', color: str='') -> None:
if self.broken_pipe_warning:
sys.stderr.write(self.broken_pipe_warning)

def perror(self, err: Union[str, Exception], traceback_war: bool=True, err_color: str=Fore.LIGHTRED_EX,
war_color: str=Fore.LIGHTYELLOW_EX) -> None:
def perror(self, err: Union[str, Exception], traceback_war: bool = True, err_color: str = Fore.LIGHTRED_EX,
war_color: str = Fore.LIGHTYELLOW_EX) -> None:
""" Print error message to sys.stderr and if debug is true, print an exception Traceback if one exists.

:param err: an Exception or error message to print out
Expand Down Expand Up @@ -647,7 +647,7 @@ def pfeedback(self, msg: str) -> None:
else:
self.decolorized_write(sys.stderr, "{}\n".format(msg))

def ppaged(self, msg: str, end: str='\n', chop: bool=False) -> None:
def ppaged(self, msg: str, end: str = '\n', chop: bool = False) -> None:
"""Print output using a pager if it would go off screen and stdout isn't currently being redirected.

Never uses a pager inside of a script (Python or text) or when output is being redirected or piped or when
Expand Down Expand Up @@ -929,7 +929,7 @@ def delimiter_complete(self, text: str, line: str, begidx: int, endidx: int, mat

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

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

def _help_menu(self, verbose: bool=False) -> None:
def _help_menu(self, verbose: bool = False) -> None:
"""Show a list of commands which help can be displayed for.
"""
# Get a sorted list of help topics
Expand Down Expand Up @@ -2753,7 +2753,8 @@ def do_quit(self, _: argparse.Namespace) -> bool:
self._should_quit = True
return self._STOP_AND_EXIT

def select(self, opts: Union[str, List[str], List[Tuple[Any, Optional[str]]]], prompt: str='Your choice? ') -> str:
def select(self, opts: Union[str, List[str], List[Tuple[Any, Optional[str]]]],
prompt: str = 'Your choice? ') -> str:
"""Presents a numbered menu to the user. Modeled after
the bash shell's SELECT. Returns the item chosen.

Expand Down Expand Up @@ -2809,7 +2810,7 @@ def cmdenvironment(self) -> str:
Output redirection and pipes allowed: {}"""
return read_only_settings.format(str(self.terminators), self.allow_cli_args, self.allow_redirection)

def show(self, args: argparse.Namespace, parameter: str='') -> None:
def show(self, args: argparse.Namespace, parameter: str = '') -> None:
"""Shows current settings of parameters.

:param args: argparse parsed arguments from the set command
Expand Down Expand Up @@ -3608,7 +3609,7 @@ def set_window_title(self, title: str) -> None: # pragma: no cover
else:
raise RuntimeError("another thread holds terminal_lock")

def cmdloop(self, intro: Optional[str]=None) -> None:
def cmdloop(self, intro: Optional[str] = None) -> None:
"""This is an outer wrapper around _cmdloop() which deals with extra features provided by cmd2.

_cmdloop() provides the main loop equivalent to cmd.cmdloop(). This is a wrapper around that which deals with
Expand Down Expand Up @@ -3863,7 +3864,7 @@ def append(self, new: str) -> None:
list.append(self, new)
new.idx = len(self)

def get(self, getme: Optional[Union[int, str]]=None) -> List[HistoryItem]:
def get(self, getme: Optional[Union[int, str]] = None) -> List[HistoryItem]:
"""Get an item or items from the History list using 1-based indexing.

:param getme: optional item(s) to get (either an integer index or string to search for)
Expand Down
Loading