Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Command history missing for default commands #1387

Answered by kmvanbrunt
Sripadvallabh asked this question in Q&A
Discussion options

Due to some requirement, i have made a default command by overriding the default() function as shown below:

 # Default command to be 'run'
 def default(self, stmt):
 self.do_run(stmt.raw)

Because of this, most of the time users would be invoking 'run' command directly with arguments instead of calling 'run ':

(cmd2) <args> 
instead of 
(cmd2) run <args>

The run command doesn't have argparse options so it works seamlessly.

But unfortunately, these commands don't show up in the history when i restart my application & check using 'history' command or by Up & down arrows.

May i know if this is supported?

You must be logged in to vote

Call one of the following:

  1. self.onecmd_plus_hooks(f"run {stmt.raw}")
  2. self.onecmd(f"run {stmt.raw}")

Replies: 1 comment 2 replies

Comment options

Call one of the following:

  1. self.onecmd_plus_hooks(f"run {stmt.raw}")
  2. self.onecmd(f"run {stmt.raw}")
You must be logged in to vote
2 replies
Comment options

Thanks it works.

Comment options

It seems we run into issues when we declare macros for default commands; The macro doesn't get expanded because stmt.raw contains the macro version & not the expanded one which sits inside stmt.args

So the solution looks like:

self.onecmd(f"run {stmt.command} {stmt.args}")

Am i right Kevin?

Answer selected by Sripadvallabh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /