question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Invalid Command name when command starts with same character as a shortcut.

See original GitHub issue

I don’t know if quit already exists in the library, but I have a command do_quit that just exits out of the command line. And then I use shortcuts to shortcut q -> quit and exit -> quit.

However, doing this results in this error:

ValueError: Invalid command name 'quit': cannot start with a shortcut: @@, ?, !, @, q

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kmvanbruntcommented, Aug 10, 2019

@xNinjaKittyx There is a distinction between shortcuts and aliases that makes shortcuts very convenient. A shortcut does not require a space between it and its arguments. So the following command lines are valid:

  • !ls
  • ?macro

The parser checks if a command line begins with a shortcut, and if so, splits them as follows:

  • ! ls
  • ? macro

Because of this, there is no way to run your quit command directly.

Since quit begins with the shortcut q,the parser splits it this way: q uit At that point, the parser resolves q into quit which results in a final command line of

quit uit

In your case, the behavior was being masked because your quit function probably just ignores the argument uit being passed to it.

If your application had another command that started with q but wasn’t related to quit, you would have seen the issue faster. I added the error message to 0.9.16 to prevent this exact problem.

If you still want to type q and run quit, then you want an alias. For your shortcuts, you will run two commands. alias create q quit alias create exit quit

You can create these at startup in a few ways:

  1. Have a startup script that runs your alias creation commands
  2. Run self.runcmds_plus_hooks() with these commands in a list.

You will see the output of the alias creation when the application starts.

Alias ‘q’ created Alias ‘exit’ created

If you don’t want to see that output, then redirect the commands to /dev/null or your operating system’s equivalent. You can also pass add_to_history=False to self.runcmds_plus_hooks() if you don’t want the alias creation commands to be stored in history.

By the way. cmd2 already has a do_quit() method. If ours already does what you need, then you can remove yours.

0reactions
xNinjaKittyxcommented, Aug 13, 2019

Cool, I like that one. Thanks everyone.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Invalid command name "exit" while executing "exit"
from PyCharm. I tried running the same script in IDLE (Python 3.6) and Terminal (Python 2.7), and they all produced the same problem...
Read more >
ISPD224 Invalid command - IBM
The command name is invalid. Command names must start with an alphabetic character, or @, #, or $. The remaining characters must be...
Read more >
command name is invalid | The AI Search Engine You Control
Press Windows + X, locate and open Command Prompt (Admin). ( See Image 6) Image 6: Open Command Prompt (Admin) b.
Read more >
cmd2/cmd2.py at master · python-cmd2/cmd2 - GitHub
Special-character shortcut commands (beyond cmd's "?" and "!") ... Verify commands don't have invalid names (like starting with a shortcut).
Read more >
Documentation - iTerm2 - macOS Terminal Replacement
You can search by tab title, command name, host name, user name, profile name, ... When you first start iTerm2, a window opens...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found