diff options
-rw-r--r-- | cmd2/cmd2.py | 20 | ||||
-rw-r--r-- | cmd2/utils.py | 12 |
2 files changed, 18 insertions, 14 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index 8b7262a2..90ef0ac6 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -2252,16 +2252,12 @@ class Cmd(cmd.Cmd): self.perror(errmsg, traceback_war=False) return - # Unquote redirection and pipes - for i, arg in enumerate(args.command_args): - unquoted_arg = utils.strip_quotes(arg) - if unquoted_arg in constants.REDIRECTION_TOKENS: - args.command_args[i] = unquoted_arg + utils.unquote_redirection_tokens(args.command_args) # Build the alias value string - value = utils.quote_string_if_needed(args.command) + value = args.command for cur_arg in args.command_args: - value += ' ' + utils.quote_string_if_needed(cur_arg) + value += ' ' + cur_arg # Set the alias result = "overwritten" if args.name in self.aliases else "created" @@ -2400,16 +2396,12 @@ class Cmd(cmd.Cmd): self.perror(errmsg, traceback_war=False) return - # Unquote redirection and pipes - for i, arg in enumerate(args.command_args): - unquoted_arg = utils.strip_quotes(arg) - if unquoted_arg in constants.REDIRECTION_TOKENS: - args.command_args[i] = unquoted_arg + utils.unquote_redirection_tokens(args.command_args) # Build the macro value string - value = utils.quote_string_if_needed(args.command) + value = args.command for cur_arg in args.command_args: - value += ' ' + utils.quote_string_if_needed(cur_arg) + value += ' ' + cur_arg # Find all normal arguments arg_list = [] diff --git a/cmd2/utils.py b/cmd2/utils.py index 3527236f..a20f0b66 100644 --- a/cmd2/utils.py +++ b/cmd2/utils.py @@ -304,3 +304,15 @@ class StdSim(object): return self.__dict__[item] else: return getattr(self.inner_stream, item) + + +def unquote_redirection_tokens(args: List[str]) -> None: + """ + Used to unquote redirection tokens in a list of command line arguments + This is used when redirection tokens have to be passed to another command + :param args: the command line args + """ + for i, arg in enumerate(args): + unquoted_arg = strip_quotes(arg) + if unquoted_arg in constants.REDIRECTION_TOKENS: + args[i] = unquoted_arg |