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 7646487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:13:16+00:00 2026-05-31T10:13:16+00:00

Is there a Python module for doing gem/git-style command line arguments? What I mean

  • 0

Is there a Python module for doing gem/git-style command line arguments? What I mean by gem/git style is:

$ ./MyApp.py
The most commonly used MyApp commands are:
  add        Add file contents to the index
  bisect     Find by binary search the change that introduced a bug
  branch     List, create, or delete branches
  checkout   Checkout a branch or paths to the working tree
  ...

$ ./MyApp.py branch
  * current-branch
    master

With no arguments, the output tells you how you can proceed. And there is a special “help” command:

$ ./MyApp.py help branch

Which gets you deeper tips about the “branch” command.

Edit:
And by doing I mean it does the usage printing for you, exits with invalid input, runs your functions according to your CLI specification. Sort of a “URL mapper” for the command line.

  • 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-05-31T10:13:18+00:00Added an answer on May 31, 2026 at 10:13 am

    Yes, argparse with add_subparsers().

    It’s all well explained in the Sub-commands section.

    Copying one of the examples from there:

    >>> parser = argparse.ArgumentParser()
    >>> subparsers = parser.add_subparsers()
    >>> checkout = subparsers.add_parser('checkout', aliases=['co'])
    >>> checkout.add_argument('foo')
    >>> parser.parse_args(['checkout', 'bar'])
    Namespace(foo='bar')
    

    Edit: Unfortunately there’s no self generated special help command, but you can get the verbose help message (that you seem to want) with -h or --help like one normally would after the command:

    $ ./MyApp.py branch --help
    

    By verbose I don’t mean that is like a man page, it’s like every other --help kind of help: listing all the arguments, etc…

    Example:

    >>> parser = argparse.ArgumentParser()
    >>> subparsers = parser.add_subparsers(description='Sub description')
    >>> checkout = subparsers.add_parser('checkout', description='Checkout description')
    >>> checkout.add_argument('foo', help='This is the foo help')
    >>> parser.parse_args(['checkout', '--help'])
    usage:  checkout [-h] foo
    
    Checkout description
    
    positional arguments:
      foo         This is the foo help
    
    optional arguments:
      -h, --help  show this help message and exit
    

    If you need to, it should be easy to implement an help command that redirects to --help.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a Python module that can be used in the same way as
In Python's module named string , there is a line that says whitespace =
Is there any python module to convert PDF files into text? I tried one
Is there a way to make a python module load a dll in my
Is there an easy-to-use python module that'd do english or finnish text validation? It'd
I am using python unit test module. I am wondering is there anyway to
There is simple JSON serialization module with name simplejson which easily serializes Python objects
Are there any modules for Python, that can be used as a TFTP server?
In Python there is a really neat function called zip which can be used
Is there an equivalent in Java for Python's bisect module ? With Python's bisect

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.