Skip to main content

Argparse frontend library to help making software usage message

Project description

helpgen helps you to make easily help/usage message of command line tools.

Example

Next is a short example of how to use the library :

#!/usr/bin/env python

import sys

from helpgen.decorators import Action
from helpgen.parser import ActionParser


@Action('test')
def action_test():
    """run a test"""

    print("I AM A TEST \o/")


@Action('hello', args=['word'])
def action_hello(word):
    """display a word"""

    print("The word is : %s" % (word,))


def main():
    parser = ActionParser(description="helpgen test script")
    parser.compile()

    try:
        parser.process()
    except:
        return 1
    else:
        return 0

if __name__ == "__main__":
    sys.exit(main())

This peace of code will produce these help messages :

  • generic help message:

$ ./test.py -h
usage: test.py [-h] {test,hello} ...

helpgen test script

positional arguments:
  {test,hello}
    test        run a test
    hello       display a word

optional arguments:
  -h, --help    show this help message and exit
  • help message for test sub command:

$ ./test.py test -h
usage: test.py test [-h]

optional arguments:
  -h, --help  show this help message and exit
  • help message for hello sub command:

$ ./test.py hello -h
usage: test.py hello [-h] word

positional arguments:
  word

optional arguments:
  -h, --help  show this help message and exit
  • and, it works fine :

$ ./test.py test
I AM A TEST \o/
$ ./test.py hello "\_o<~ KOIN"
The word is : \_o<~ KOIN

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

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

Source Distribution

helpgen-0.1.tar.gz (1.5 kB view details)

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for helpgen-0.1.tar.gz
Algorithm Hash digest
SHA256 467479ed2cdee53f42eb60d1d5e5239b673246f89e56f52f8dce78ac4382c409
MD5 6b0d5fde8944baf04a918d45a7116536
BLAKE2b-256 242aa7e569b9ac610f473f656867dae18a7d8e82a8ec3f96e957ee59c3f2a82b

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