diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2019-03-18 22:49:42 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-18 22:49:42 -0400 |
commit | 2f24a8ad3eeb2fdf699d1e2a9d4f05429fe879c4 (patch) | |
tree | b836270cf61175d1e4a434fd8cae08f0ffd998a2 /cmd2/parsing.py | |
parent | 96d176cc3d8198913693a42c7dd983cf69a165bd (diff) | |
parent | 57dd827963491439e40eb5dfe20811c14ea757ff (diff) | |
download | cmd2-git-2f24a8ad3eeb2fdf699d1e2a9d4f05429fe879c4.tar.gz |
Merge branch 'master' into load_generate_transcript
Diffstat (limited to 'cmd2/parsing.py')
-rw-r--r-- | cmd2/parsing.py | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/cmd2/parsing.py b/cmd2/parsing.py index 514f5faf..2dc698b0 100644 --- a/cmd2/parsing.py +++ b/cmd2/parsing.py @@ -5,7 +5,7 @@ import os import re import shlex -from typing import Dict, List, Tuple, Union +from typing import Dict, Iterable, List, Optional, Tuple, Union import attr @@ -242,31 +242,42 @@ class StatementParser: Shortcuts is a list of tuples with each tuple containing the shortcut and the expansion. """ - def __init__( - self, - allow_redirection: bool = True, - terminators: List[str] = None, - multiline_commands: List[str] = None, - aliases: Dict[str, str] = None, - shortcuts: List[Tuple[str, str]] = None, - ): + def __init__(self, + allow_redirection: bool = True, + terminators: Optional[Iterable[str]] = None, + multiline_commands: Optional[Iterable[str]] = None, + aliases: Optional[Dict[str, str]] = None, + shortcuts: Optional[Iterable[Tuple[str, str]]] = None) -> None: + """Initialize an instance of StatementParser. + + The following will get converted to an immutable tuple before storing internally: + * terminators + * multiline commands + * shortcuts + + :param allow_redirection: (optional) should redirection and pipes be allowed? + :param terminators: (optional) iterable containing strings which should terminate multiline commands + :param multiline_commands: (optional) iterable containing the names of commands that accept multiline input + :param aliases: (optional) dictionary contaiing aliases + :param shortcuts (optional) an iterable of tuples with each tuple containing the shortcut and the expansion + """ self.allow_redirection = allow_redirection if terminators is None: - self.terminators = [constants.MULTILINE_TERMINATOR] + self.terminators = (constants.MULTILINE_TERMINATOR,) else: - self.terminators = terminators + self.terminators = tuple(terminators) if multiline_commands is None: - self.multiline_commands = [] + self.multiline_commands = tuple() else: - self.multiline_commands = multiline_commands + self.multiline_commands = tuple(multiline_commands) if aliases is None: - self.aliases = {} + self.aliases = dict() else: self.aliases = aliases if shortcuts is None: - self.shortcuts = [] + self.shortcuts = tuple() else: - self.shortcuts = shortcuts + self.shortcuts = tuple(shortcuts) # commands have to be a word, so make a regular expression # that matches the first word in the line. This regex has three |