The command line interface (also known as CLI) is a means to interact with a command line script. Python comes with several different libraries that allow you to write a command line interface for your scripts, but the standard way for creating a CLI in Python is currently the Python argparse
library.
The Python argparse
library:
- Allows the use of positional arguments
- Allows the customization of the prefix chars
- Supports variable numbers of parameters for a single option
- Supports subcommands (A main command line parser can use other command line parsers depending on some arguments.)
Using the Python argparse
library has four steps:
- Import the Python argparse library
- Create the parser
- Add optional and positional arguments to the parser
- Execute .parse_args()
You can create a new repo using this template via the gh
cli:
# gh repo create [<name>] [flags]
gh repo create gitops-labs/my-repo \
--template gitops-labs/template
What things you need to install the software and how to install them.
brew install gh
A step by step series of examples that tell you how to get a development env running.
Say what the step will be
Give the example
And repeat
until finished
End with an example of getting some data out of the system or using it for a little demo.
Add notes about how to use the system.
- How to Build Command Line Interfaces in Python With argparse
- Do-nothing scripting: the key to gradual automation
- Comparing Python Command-Line Parsing Libraries – Argparse, Docopt, and Click
- AWS cloudendure migration factory solution
- How to Write Python Command-Line Interfaces like a Pro
- argparse — Parser for command-line options, arguments and sub-commands
- Argparse Tutorial
- https://mike.depalatis.net/blog/simplifying-argparse.html
- https://github.com/alephnull/rfw/blob/master/rfw/rfwc.py
- https://gist.github.com/mivade/384c2c41c3a29c637cb6c603d4197f9f
- https://github.com/mivade/arghelp