Command-line Applications

https://d33wubrfki0l68.cloudfront.net/b6a8e99951ff1577e83f05367cb44cf2e327dfd9/08dbe/_images/34435690330_11930b5987_k_d.jpg
Command-line applications, also referred to as Console Applications, are computer programsdesigned to be used from a text interface, such as a shell). Command-line applicationsusually accept various inputs as arguments, often referred to as parameters orsub-commands, as well as options, often referred to as flags or switches.

Some popular command-line applications include:

  • grep - A plain-text data search utility
  • curl - A tool for data transfer with URL syntax
  • httpie - A command-line HTTPclient, a user-friendly cURL replacement
  • Git - A distributed version control system
  • Mercurial - A distributed version controlsystem primarily written in Python

Click

click is a Python package for creatingcommand-line interfaces in a composable way with as little code as possible.This “Command-Line Interface Creation Kit” is highly configurable but comeswith good defaults out of the box.

docopt

docopt is a lightweight, highly Pythonic package thatallows creating command-line interfaces easily and intuitively, by parsingPOSIX-style usage instructions.

Plac

Plac is a simple wrapperover the Python standard library argparse,which hides most of its complexity by using a declarative interface: theargument parser is inferred rather than written down imperatively. Thismodule targets unsophisticated users, programmers, sysadmins,scientists, and in general people writing throw-away scripts for themselves,who choose to create a command-line interface because it is quick and simple.

Cliff

Cliff is a framework forbuilding command-line programs. It uses setuptools entry points to providesubcommands, output formatters, and other extensions. The framework is meantto be used to create multi-level commands such as svn and git, wherethe main program handles some basic argument parsing and then invokes asub-command to do the work.

Cement

Cement is an advanced CLI ApplicationFramework. Its goal is to introduce a standard and feature-full platform forboth simple and complex command line applications as well as support rapiddevelopment needs without sacrificing quality. Cement is flexible, and its usecases span from the simplicity of a micro-framework to the complexity of amega-framework.

Python Fire

Python Fire is a library forautomatically generating command-line interfaces from absolutely any Pythonobject. It can help debug Python code more easily from the command line,create CLI interfaces to existing code, allow you to interactively explorecode in a REPL, and simplify transitioning between Python and Bash (or anyother shell).

原文: https://docs.python-guide.org/scenarios/cli/