ClickYaml reads a `.yaml` file and creates click Commands out of it.
Project description
clickYaml
ClickYaml reads a .yaml file and creates click Commands out of it.
Free software: MIT license
Documentation: https://clickyaml.readthedocs.io.
Installation
To install clickYaml, run this command in your terminal:
pip install clickyaml
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
There are two ways to get the commands from yaml data as click.Command objects:
Using get_command()
Using get_commands()
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 commands yaml file in a dictionary
all the commands will be assigned the default callback
from clickyaml import get_commands
commands = get_commands(yaml=yaml_data) # returns all the commands in a dictionary
simplecommand = Commands["simplecommand"]
complexcommand = Commands["complexcommand"]
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.
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
Built Distribution
Hashes for clickyaml-2.0.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 23f580c591b7fd81acd8dfc50fc74ef550974034ac7f54c48370baa78bed82c1 |
|
MD5 | 54b7ab3d7d40b97894bdfa41ff8344f6 |
|
BLAKE2b-256 | c0b3a397f8bc968101a826ab4f72e0e3e36ce8a97b64326bb032196e49eb3fee |