Skip to main content

Simplification of CLI construction in Python based on argparse: just add branches and arguments. CLI construction from yaml file also available.

Project description

Contributors Forks Stargazers Issues MIT License


seedling

arbutus

Simplification of CLI construction in Python based on argparse: just add branches and arguments. CLI construction from yaml file also available.

If you are interested in participating, please feel free to contribute.

Explore the docs »

Report Bug Request Feature



Python

Contents

Getting Started

Requirements

  • Python 3.8 or above
    • argparse
    • logging

Installation

pip install arbutus

Usage

Once installed, the cli can be defined using a yaml file, using the keywords branches to define new branch names and arguments to define new arguments and it's characteristics. For example:

main:
  branches:
    sum:
      arguments:
        integers:
          type: float
          nargs: +
          help: list of integers to sum
          action:
            name: sum_
            source: sample
    store:
      arguments:
        something:
          type: str
          nargs: +
          help: string or strings to store
          action: store

The yaml above would imply that a module named sample includes the action sum_, and makes use of the store action. These actions can be defined using the @Arbutus.new_action wrapper. For example:

from arbutus import Arbutus

@Arbutus.new_action
def sum_(*args, **kwargs):
    total = 0
    for number in kwargs['values']:
        total += number
    print(total)

Finally, the CLI itself can be constructed by calling the from_yaml method:

import arbutus

if __name__ == '__main__':
    cli = arbutus.Arbutus()
    cli.from_yaml('sample/cli.yaml')
    cli.parse_args()

The CLI can then be called like:

# This would display general help about the CLI functionality
python3 sample/sample.py -h
# This would display general help about the sum test functionality
python3 sample/sample.py sum -h
# This would throw the result of running the sum function with the passed arguments
python3 sample/sample.py sum 12 25 3

Roadmap

See the open issues for a full list of proposed features (and known issues).

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Alvaro U. Bravo - alvaroubravo@gmail.com

Project Links:

(back to top)

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

arbutus-0.0.4.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

arbutus-0.0.4-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file arbutus-0.0.4.tar.gz.

File metadata

  • Download URL: arbutus-0.0.4.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.10

File hashes

Hashes for arbutus-0.0.4.tar.gz
Algorithm Hash digest
SHA256 1bf4d09348116639a12d45a3445fdc1a1fb61c4fbb4d4f7bc2c3f631a2321961
MD5 c2d5bcc0e6c29234960b627e795bf6ee
BLAKE2b-256 8c887d1bc581a6fa73f2b9265c9cdc7cac7a4fc38811657c88a654e0608a2187

See more details on using hashes here.

File details

Details for the file arbutus-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: arbutus-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.10

File hashes

Hashes for arbutus-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 60b6f6550fe1f4230a5a78b5ea7bd66de9fe9266fccdbdf3f17cdbfc05f489e0
MD5 1115b81af0433883ad6416b27dac0459
BLAKE2b-256 3e6b9337f08f65f16d58db3943712d2e6bfd5a35333800b981d3344d94cd345a

See more details on using hashes here.

Supported by

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