Skip to main content

python cli scripts for humans

Project description

Easy python cli scripts for people that just want get things done.

Captain was lovingly crafted for First Opinion.

Usage

A valid captain cli script needs two things:

  1. a shebang on the first line

    #!/usr/bin/env python
  2. a main function

    def main(foo, bar):
        return 0

That’s it! Whatever arguments you define in the main function will be options on the command line.

def main(foo, bar):
    return 0

can be called on the command line:

$ pyc path/to/script.py --foo=1 --bar=2

Examples

A typical standard python cli script:

import argparse

if __name__ == u'__main__':
    parser = argparse.ArgumentParser(description='fancy script description')
    parser.add_argument("--foo", action='store_true')
    parser.add_argument("--bar", default=0, type=int)
    parser.add_argument("args", nargs='*')
    args = parser.parse_args()

would become:

#!/usr/bin/env python

def main(foo=False, bar=0, *args):
    '''fancy script description'''
    return 0

You can get a list of all available scripts in a directory by running captain with no arguments:

$ captain

Install

Use pip:

$ pip install captain

License

MIT

Project details


Download files

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

Source Distribution

captain-0.1.tar.gz (4.4 kB view details)

Uploaded Source

File details

Details for the file captain-0.1.tar.gz.

File metadata

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

File hashes

Hashes for captain-0.1.tar.gz
Algorithm Hash digest
SHA256 adc7e1684a2aacbe923cea02dbe3a3157f93789b7eeeb0c256ef31f0da00a8e5
MD5 7ed1e09c1d419914a4393308bcde9d40
BLAKE2b-256 527cec81a6a0797589b48f23482a8130a59385a5b2f3c6c59347847f2ef044a8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page