Skip to main content

Action and Mnemonic command line library

Travis CI Build Status PyPI Python 3.7

This library intends to make command line execution and configuration easy. The library supports (among other features) an mnemonic centric way to tie a command line an action to a Python 3 handler code segment. Features include:

  • Better command line parsing than optparse. This a binding to from a command line option using an action mnemonic to invocation of a handler.
  • Better application level support for configuration than configparser. Specifically, optional configuration and configuration groups.

Obtaining

The easiest way to obtain this package is via pip:

pip install zensols.actioncli

Binaries are also available on pypi.

Usage

Two ways to use this project follow. The easiest way is to use the template method. Either way, first install the library via pip or easyinstall.

Template

The best way to get started is to template out this project with the following commands:

# clone the boilerplate repo
git clone https://github.com/plandes/template
# download the boilerplate tool
wget https://github.com/plandes/clj-mkproj/releases/download/v0.0.7/mkproj.jar
# create a python template and build it out
java -jar mkproj.jar config -s template/python
java -jar mkproj.jar

Straight Python

If you want to skip templating it out (i.e. don't like Java), create a command line module:

from zensols.actioncli import OneConfPerActionOptionsCli
from zensols.actioncli import SimpleActionCli
from zensols.tools import HelloWorld

VERSION='0.1'

class ConfAppCommandLine(OneConfPerActionOptionsCli):
    def __init__(self):
        cnf = {'executors':
               [{'name': 'hello',
                 'executor': lambda params: HelloWorld(**params),
                 'actions':[{'name': 'doit',
                             'meth': 'print_message',
                             'opts': [['-m', '--message', True, # require argument
                                       {'dest': 'message', 'metavar': 'STRING',
                                        'help': 'a message to print'}]]}]}],
               # uncomment to add a configparse (ini format) configuration file
               # 'config_option': {'name': 'config',
               #                   'opt': ['-c', '--config', False,
               #                           {'dest': 'config', 'metavar': 'FILE',
               #                            'help': 'configuration file'}]},
               'whine': 1}
        super(ConfAppCommandLine, self).__init__(cnf, version=VERSION)

def main():
    cl = ConfAppCommandLine()
    cl.invoke()

This uses the OneConfPerActionOptionsCliEnv class, which provides a data driven way of configuring the action based command line. An extention of this class is the OneConfPerActionOptionsCliEnv class, which imports environment variables and allows adding to the configuration via adding a resource like file (i.e. ~/.<program name>rc) type file. See the

See the command line test cases for more examples.

Changelog

An extensive changelog is available here.

License

Copyright (c) 2018 Paul Landes

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Metadata

Release files for zensols.actioncli 1.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for zensols.actioncli 1.1.5
File Interpreter ABI Platform
zensols.actioncli-1.1.5-py3.7.egg Legacy Egg format - - Details
zensols.actioncli-1.1.5-py3-none-any.whl Python 3 none any Details

Total release size: 123.6 kB

Release files / zensols.actioncli-1.1.5-py3.7.egg

Download URL zensols.actioncli-1.1.5-py3.7.egg
Size 87.6 kB
Tags Egg
SHA-256 checksum
How to use checksums
eae94c2cf6cc8f451474d16256153ca5a516be8f3993170bfd13e37431e747d0
BLAKE2b-256 checksum
How to use checksums
e851f9f698bdbc0c55dcc1328ab220d557e5ec2405686334b7a7f9f8888ce475
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.4

Release files / zensols.actioncli-1.1.5-py3-none-any.whl

Download URL zensols.actioncli-1.1.5-py3-none-any.whl
Size 35.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f4b59fbfa1e518f9c381a3d0f5d9335ca7e3e2139b72f9184dfd0ab0bcd7ca6b
BLAKE2b-256 checksum
How to use checksums
e91a8d9ea27914e3f46032d3e29d96ee355c0a9a01439265a102304b9fd54fe6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.4

Release history Release notifications | RSS feed

This release

1.1.5 This release

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.18

2 release files

1.0.16

2 release files

1.0.14

2 release files

1.0.13

2 release files

1.0.12

2 release files

1.0.10

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.6

2 release files

0.4

1 release file

0.3

1 release file

0.2

1 release file

0.1

1 release 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