Skip to main content

clickYaml

https://img.shields.io/pypi/v/clickyaml.svg Documentation Status https://github.com/vandyG/clickyaml/actions/workflows/python-package.yml/badge.svg?event=push&branch=master

ClickYaml reads a .yaml file and creates click Commands out of it.

Installation

Stable release

To install clickYaml, run this command in your terminal:

$ pip install clickyaml

This is the preferred method to install clickYaml, as it will always install the most recent stable release.

If you don’t have pip installed, this Python installation guide can guide you through the process.

From sources

The sources for clickYaml can be downloaded from the Github repo.

You can either clone the public repository:

$ git clone git://github.com/vandyG/clickyaml

Or download the tarball:

$ curl -OJL https://github.com/vandyG/clickyaml/tarball/master

Once you have a copy of the source, you can install it with:

$ python setup.py install

Usage

Input yaml file example:

simplecommand:
    script: "/home/user/scripts/simplecommand.bash"
    params:
        - !arg
            param_decls: [argument]
        - !opt
            param_decls: ["--option"]

complexcommand:
    script: "/home/user/scripts/complexcommand.bash"
    help: "Complex Command"
    params:
        - !arg
            param_decls: [id]
        - !arg
            param_decls: [type]
        - !arg
            param_decls: [category]
            type: !obj
                class: click.Choice
                choices: ["1","2","3","ALL"]
                case_sensitive: False
        - !opt
            param_decls: ["--email","-E"]
            multiple: True
            envvar: MY_EMAIL
            help: "Specify the mailing list with this option"

Note: There are certain rules on the structure of the yaml file:

  • Each command block needs to have blocks for each parameter of the command that you define. To know the available parameters refer to the click documentation

  • Apart from parameters to click.Command a script block can also be used. Script represents a script that you want to link with your command.

  • There are three types of tags that can be used in the yaml file: !obj, !arg and !opt

  • !obj can be used to create custom objects

  • !arg can be used to create click.Argument objects

  • !opt can be used to create click.Option objects

The clickyaml module takes in the yaml file and creates Commander() objects for each command. A Commander() object houses the command, scripts associated with the command and the callback.

There are two ways to get the commands from yaml data as click.Command objects:

  1. Using get_command()

  2. Using get_commanders()

Get specific commands from the yaml file

from clickyaml import get_command, parse_yaml

parsed_yaml = parse_yaml(path=path_to_yaml)

# this command has a default callback that runs the script associated with the command
command_default = get_command(name="simplecommand",parsed_yaml=parsed_yaml,)

#this command has custom callback that prints the passed arguments
cstm_clbk = lambda **kwargs: print(kwargs)
command_custom = get_command(name="simplecommand",parsed_yaml=parsed_yaml,callback=cstm_clbk)

Get all the Commander objects yaml file in a dictionary

all the commands will be assigned the default callback

from clickyaml import get_commanders

commanders = get_commanders(yaml=yaml_data) # returns all the commands in a dictionary

simplecommand = commanders["simplecommand"].command
complexcommand = commanders["complexcommand"].command

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

History

0.1.0 (2023-02-03)

  • First release on PyPI.

Release files for clickyaml 2.1.0

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

Source distribution (sdist)

Source distribution for clickyaml 2.1.0
File Size Uploaded
clickyaml-2.1.0.tar.gz 14.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for clickyaml 2.1.0
File Interpreter ABI Platform
clickyaml-2.1.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 22.5 kB

Release files / clickyaml-2.1.0.tar.gz

Download URL clickyaml-2.1.0.tar.gz
Size 14.6 kB
Tags Source
SHA-256 checksum
How to use checksums
e5fa825a09d81ccb129c89c7a4847fa0b74336a6c61c50db1c770f7f0458ce14
BLAKE2b-256 checksum
How to use checksums
6f84155b36759466e5a2351dfee245034b8b93c74eebe769402e652b31bed5e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.0

Release files / clickyaml-2.1.0-py2.py3-none-any.whl

Download URL clickyaml-2.1.0-py2.py3-none-any.whl
Size 7.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
c588a327bcc4e46023b91f90b46d81b9d3c67a9c3d1442a681ebfc57edb815cb
BLAKE2b-256 checksum
How to use checksums
1236d0e415821a760f02c463a942eaa7fd7a4ec853c3b6fefa63d78e1712912f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.0

Release history Release notifications | RSS feed

This release

2.1.0 This release

2 release files

2.0.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

2 release files

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