Skip to main content

Create a powerful and efficient CLI application using simple and user-friendly yaml config

Project description

Argyaml

Argyaml is a small module for creating powerful and scalable CLI applications based on a simple and user-friendly yaml configuration file.

Motivation

Argyaml is built over the argparse module, which is a part of python standard library starting python 3.2. While it works well for tiny projects that need to quickly access a few arguments and provide automatically generated help and usage messages for user, it gets very complicated and painful when it comes to large projects or your application grows in complexity.

Features

  • Independent specification of CLI commands and arguments.
  • No boilerplate code.
  • Ability to set default options for commands, groups, and arguments.
  • Automatic and optimized invocation of command handlers.
  • Handler template files generator.

Install

# pip
pip install argyaml

# poetry
poetry add argyaml

Getting started

# cli-config.yaml
prog: todo
description: My beautiful todo app
next:
  - command: new
    next:
      - command: task
        description: Create a new task
        next:
          - argument: [name]
            help: the name of task
  - command: list
    next:
      - argument: [-t, --task]
        help: display tasks only
        action: 'store_true'
from argyaml import BaseHandler

base = BaseHandler()
base.args # <-- parsed and ready-to-use arguments

Learn more about config file.

Using Handlers

Generate template files using argyaml generate:

# pip
python -m argyaml generate

If you are using Poetry, add the following script to your pyproject.toml and then execute it using poetry run:

# pyproject.toml
[tool.poetry.scripts]
gen = "argyaml.__main__:generate"
# poetry
poetry run gen

This will generate the following files:

handlers/
  _new_task.py
  _list.py

Now, whenever new task command is called, the corresponding handler init function will be invoked with all additional aruments stored in the self.args object.

# _new_task.py
from argyaml import BaseHandler

class Handler(BaseHandler.meta()):
    def __init__(self):
        print(f"Successfully created task '{self.args['name']}'!")

Modify the main file to run the base handler:

from argyaml import BaseHandler

base = BaseHandler()
base.run()

Learn more about BaseHandler and argyaml generator.

Contributing

Feel free to open issues. Pull requests are welcome.

License

This project is licensed under the MIT License.

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

argyaml-0.1.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

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

argyaml-0.1.0-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file argyaml-0.1.0.tar.gz.

File metadata

  • Download URL: argyaml-0.1.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.10.6 Linux/5.15.0-58-generic

File hashes

Hashes for argyaml-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8822917c0305fd8272dd63ec1d1f03c00a36a57162ed394e35964139f7f36dd4
MD5 c4ec97f04492af5632ec908cd192281c
BLAKE2b-256 2ac3599fd5065771ff412fd778c6426d61fdd7c56eb1a4d847f2879e669300b5

See more details on using hashes here.

File details

Details for the file argyaml-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: argyaml-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.10.6 Linux/5.15.0-58-generic

File hashes

Hashes for argyaml-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5e20a316ca484a03f0d01d07dc1bfddf3bc1fc3b5d6da3f45248d109e91ba743
MD5 559d82da5a66a02b6c09f40edd07fb25
BLAKE2b-256 2f36fe10edce74b833bd2e413e5b712c874512aa4be2fdf588823dbe052255bd

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