Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8700723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:13:59+00:00 2026-06-13T02:13:59+00:00

How can I create an alias for a command in a line-oriented command interpreter

  • 0

How can I create an alias for a command in a line-oriented command interpreter implemented using the cmd module?

To create a command, I must implement the do_cmd method. But I have commands with long names (like constraint) and I want to provide aliases (in fact, shortcuts) for these commands (like co). How can I do that?

One possibility that came to my mind is to implement the do_alias (like do_co) method and just calling do_cmd (do_constraint) in this method. But this brings me new commands in the help of the CLI.

Is there any other way to achieve this? Or may be is there a way to hide commands from the help output?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T02:14:01+00:00Added an answer on June 13, 2026 at 2:14 am

    You can overwrite the default method and search for a suitable command handler (as already suggested by Brian):

    import cmd
    
    class WithAliasCmd(cmd.Cmd):
    
        def default(self, line):
            cmd, arg, line = self.parseline(line)
            func = [getattr(self, n) for n in self.get_names() if n.startswith('do_' + cmd)]
            if func: # maybe check if exactly one or more elements, and tell the user
                func[0](arg)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

keytool -list -alias alias_name -keystore my-release-key.keystore using above command when i try to create
Can we create deep alias for foreign key table using criteria? For example if
When the type name is too long, in C# i can create alias like
How can I create a Windows shortcut alias for an existing exe file from
I can create an alias in solaris as below: alias x86 some_command I need
How can I turn the following command into a bash alias? find . -name
Can you create an alias on field at time of creation? Example CREATE TABLE
I'm trying to create a LLDB alias that evaluates an expression using the argument
in tcsh we can create a alias for example alias kate 'kate \!* &'
The rails command can be executed in jruby/bin folder only. I want to create

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.