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
    • logger

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
    multiply:
      arguments:
        integers:
          type: float
          nargs: +
          help: list of integers to sum
          action:
            name: mult_
            source: sample

The yaml above would imply that a module named sample includes the actions sum_ and mult_. These actions can be defined using the @arbutus.Arbutus.new_action wrapper. For example:

import arbutus

@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.3.tar.gz (13.8 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.3-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: arbutus-0.0.3.tar.gz
  • Upload date:
  • Size: 13.8 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.3.tar.gz
Algorithm Hash digest
SHA256 741ca16205fac151444952b2f848c0e28229f03afbdb4a4912a51e76b7a40f03
MD5 55b7bbf567e5f3a431a2a9c7f89aa50a
BLAKE2b-256 55e213ce4e5373e45ca80b851df85e77b550a9d2814f792647a9959907783884

See more details on using hashes here.

File details

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

File metadata

  • Download URL: arbutus-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 4.7 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f51a41b646887386f145dfebcaa4a784d9555520e6cbc6ad271f11f35b340122
MD5 b02c4911ab9d2911877af70a75eb5b87
BLAKE2b-256 864e0bb26690404bcf8d1df56506cf94704755732f042d8219e31c8325a587ec

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