diff options
author | 2014-08-23 19:17:08 +0200 | |
---|---|---|
committer | 2014-08-23 19:17:08 +0200 | |
commit | 5c640fdb7884f318b306fb10bd6b499b1b7c0f40 (patch) | |
tree | b5bfd342946f9626632a4875d74e7fc0f943068a | |
parent | config loader, yesno(): use str_to_bool() (diff) | |
download | R_overlay-5c640fdb7884f318b306fb10bd6b499b1b7c0f40.tar.gz R_overlay-5c640fdb7884f318b306fb10bd6b499b1b7c0f40.tar.bz2 R_overlay-5c640fdb7884f318b306fb10bd6b499b1b7c0f40.zip |
console/interpreter: minor improvements
* added --clear option to "history" command
* "set" can now be called without VAR=VALUE
-rw-r--r-- | roverlay/console/interpreter.py | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/roverlay/console/interpreter.py b/roverlay/console/interpreter.py index 107a14a..00b6ea9 100644 --- a/roverlay/console/interpreter.py +++ b/roverlay/console/interpreter.py @@ -334,6 +334,12 @@ class ConsoleInterpreter ( cmd.Cmd ): parser.add_argument ( "files", metavar='<file>', nargs='*', help='files to read', type=self.argparse_filepath, ) + + parser = self.get_argparser ( "history", create=True ) + parser.add_argument ( "-c", "--clear", + default=False, action='store_true', + help="clear history" + ) # --- end of setup_argparser (...) --- def setup_interpreter ( self ): @@ -466,7 +472,7 @@ class ConsoleInterpreter ( cmd.Cmd ): if self.state == ConsoleInterpreterStatus.STATE_CMD_EXEC: if self.is_onerror(): self.clear_onerror() - elif self.lastcmd and self.lastcmd != "history": + elif self.lastcmd and self.lastcmd.split(None,1)[0] != "history": self._history.append ( line ) self.state.goto ( "READY" ) @@ -549,8 +555,12 @@ class ConsoleInterpreter ( cmd.Cmd ): def do_history ( self, line ): """Shows the command history.""" - sys.stdout.write ( '\n'.join ( l for l in self._history ) ) - sys.stdout.write ( '\n' ) + args = self.parse_cmdline ( "history", line ) + if args.clear: + self._history.reset() + else: + sys.stdout.write ( '\n'.join ( l for l in self._history ) ) + sys.stdout.write ( '\n' ) # --- end of history (...) --- def do_pwd ( self, line ): @@ -657,19 +667,22 @@ class ConsoleInterpreter ( cmd.Cmd ): # --- end of do_declare (...) --- def do_set ( self, line ): - """Sets a variable. + """Sets a variable or prints all variables. - Usage: set VAR=VALUE + Usage: set [VAR=VALUE] Examples: * set PS1=cmd % * set dep=fftw 3 """ - name, sepa, value = line.partition ( '=' ) - if not sepa: - sys.stderr.write ( "set, bad syntax: {}\n".format ( line ) ) + if not line: + self.do_declare ( line ) else: - self.set_var ( name.strip(), value ) + name, sepa, value = line.partition ( '=' ) + if not sepa: + sys.stderr.write ( "set, bad syntax: {}\n".format ( line ) ) + else: + self.set_var ( name.strip(), value ) # --- end of do_set (...) --- def do_unset ( self, line ): |