Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

This is a helper module for making intuitive command line programs with
zero effort. Let's say you have a function that looks like this:
example_function(string1, string2='something', string3='something else')

The simplest way to make it into a script is to do:
if __name__ == "__main__":
import sys
example_function(*sys.argv[1:])

But this fails when someone writes script.py --help on the command line.
("--help" will just be passed as the first argument to example_function)
It also causes pain if you try to do it with a function like this:
example_function2(string1, int1=5, int2=4, float1=0.3)

What commandline allows you to do is (without changing example_function):
if __name__ == "__main__":
import commandline
commandline.run_as_main(example_function)

and it will do option parsing, and also convert all arguments to the same type
as the default arguments (as in example_function2).

Limitations
============

Note that it currently can't print help information for arguments other than their default values,
but it will print your docstring for you if that's of any use.
Help for arguments will probably come with python3000's function annotations.
http://www.python.org/dev/peps/pep-3107/

The code is a bit ugly at the moment.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

commandline-0.1dev.tar.gz (4.5 kB view details)

Uploaded Source

File details

Details for the file commandline-0.1dev.tar.gz.

File metadata

  • Download URL: commandline-0.1dev.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for commandline-0.1dev.tar.gz
Algorithm Hash digest
SHA256 915d81ec0207d49112f3b6dfdf6536c1f098b6a737b2129450a73bf293b15207
MD5 0137ec7b20bdabbdda7917c52b2b127a
BLAKE2b-256 41c65a5ccf349a2afaf938c0dee7e7672a16f9dcc4ca156b110ffcf0aaff0031

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1dev This release

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page