Package: cliffy
cliffy :mountain:cliffy is a YAML-defined CLI generator, manager, and builder for python. It offers dynamic abstractions to rapidly build, test, and deploy CLIs.FeaturesRapidly build CLIs with YAML-defined manifestsManage CLIs- load, list, update, and removeBuilt-in shell and Python scripting supportSupports Jinja2 templatingBuild CLIs into self-contained, portable zipappsLoadDefine a manifest# hello.yamlname:helloversion:0.1.0commands:bash:$echo "hello from bash"python:print("hello from python")Load CLI$ cli load hello.yamlParseshello.yamlto generate a Typer CLI and load it into the running Python environment.Run CLI directlyhello -hFor more examples, checkexamplesdirectory.BuildDefine a manifest# requires.yamlname:requiresversion:0.1.0requires:-requests >= 2.30.0-siximports:-import sixcommands:bash:$echo "hello from bash"python:print("hello from python")py:|if six.PY2:print("python 2")if six.PY3:print("python 3")Build CLI$ cli build requires.yaml -o distBuilds a portable zipapp containing the CLI and its package requirements.Run CLI./dist/requires -hUsagecli <command>init <cli name> --raw: Generate a template CLI manifest for a new CLIload <manifest>: Add a new CLI based on the manifestrender <manifest>: View generated CLI script for a manifestlistorls: Output a list of loaded CLIsupdate <cli name>: Reload a loaded CLIremove <cli name>orrm <cli name>: Remove a loaded CLIrun <manifest> -- <args>: Runs a CLI manifest as a one-time operationbuild <cli name or manifest>: Build a CLI manifest or a loaded CLI into a self-contained zipappinfo <cli name>: Display CLI metadataHow it worksDefine CLI manifests in YAML filesRunclicommands to load, build, and manage CLIsWhen loaded, cliffy parses the manifest and generates aTyperCLI that is deployed directly as a scriptAny code starting with$will translate to subprocess calls viaPyBashRun loaded CLIs straight from the terminalWhen ready to share, runbuildto generate portable zipapps built withShivInstallpip install "cliffy[rich]"to includerich-clickfor colorful CLI help output formatted withrich.orpip install cliffyManifest templateGenerated bycli init. For a barebones template, runcli init --raw# cliffy v1 templatemanifestVersion:v1# The name of the CLI# This will be used as the script name when invoking the CLI from the command line.name:cliffy# The version of the CLI# This should follow the standard semantic versioning format (e.g., 'MAJOR.MINOR.PATCH').version:0.1.0# List of external CLI manifest paths to include into the main manifest# Performs a deep merge of manifests sequentially in the order given to assemble a merged manifest# and finally, deep merges the merged manifest with the main manifest.includes:[]# List of Python dependencies required for the CLI# Validated on CLI load and update# Supports basic requirements specifier syntax.requires:[]# A mapping defining manifest variables that can be referenced in any other blocks# Environments variables can be used in this section with ${some_env_var} for dynamic parsing# Supports jinja2 formatted expressions as values# Interpolate defined vars in other blocks jinja2-styled {{ var_name }}.vars:default_mood:happy# A string block or list of strings containing any module imports# These can be used to import any python modules that the CLI depends on.imports:-import os-|from collections import defaultdictimport re# A list containing any helper functions# Each element of the list can be a separate function# These functions should be defined as strings that can be executed by the Python interpreter.functions:-|def greet_name(name: str):print("hello " + name)# A mapping containing any shared type definitions# These types can be referenced by name in the args section to provide type annotations for params and options defined in the args section.types:Language:str = typer.Option("english", "-l", help="Language to greet in", prompt=True)# A mapping containing the arguments and options for each command# Each key in the mapping should correspond to a command in the commands section# The value should be a list of mappings representing the params and options for that command.args:world:[--name|-n:str!]# a REQUIRED optiongreet.all:-names:str!# a REQUIRED param as denoted by the ! at the end-mood:str = "{{default_mood}}"# an OPTIONAL param that uses a manifest var as default---language:Language# an option with a default that uses Language type as arg definition# A mapping containing the command definitions for the CLI# Each command should have a unique key- which can be either a group command or nested subcommands# Nested subcommands are joined by '.' in between each level# A special (*) wildcard can be used to spread the subcommand to all group-level commands# The value is the python code to run when the command is called OR a list of bash commands to run (prefixed with $).commands:# this is a parent command that will get invoked with: hello worldworld:-|"""Help text for list"""greet_name("world")-$ echo "i can also mix-and-match this command script to run bash commands"# this is a nested command that will get invoked with: hello greet allgreet.all:-help:Help text for list.all# you can also define help text like this-$ echo "hello all"# this is a bash command that will get converted to python subprocess call-print("greetings from python")# this python code will get directly invokedDevelopmentpoetry shell
cli -h