cliapi ( pronounced calliope ): A Python framework for creating Unix, "getopt()" style CLI scripts composed from a set of APIs.
...at its core, cliapi is a data driven, state machine for dynamically generating CLIs.
cliapi Features:
-
entire CLI is generated by applying python decorators together with a "dictionary with backing API store". This decorator is applied for each API supported by a "plugin provider".
-
multiple data queries within the same CLI will result in "at most" a single API call.
-
consistent "command line behavior" is enforced by the cliapi framework across all plugin providers. Several common commands are automatically inherited by all the providers:
- "--list-providers" Lists all the available plugin providers.
- "--provider=" specify a particular provider plugin for all CLI commands.
- "--all" Lists all data returned by all APIs supported by a single provider.
- "--list-apis" Lists all the APIs available by a particular plugin provider.
- "--query=" extracts specified API data using pythonic dictionary syntax.
-
other behaviors enforced by the cliapi framework:
- error handling and help is also consistent across all plugin providers.
- multiple queries in same command will return a JSON list in "query order" by default
- single query will return a single JSON element.
Key cliapi developer concepts:
-
provider: an associated set of APIs accessed from the CLI in a particular context or cloud environment e.g. "azure", "gce", "ec2", ... but can essentially be any mix of apis
-
api: an API for interfacing to remote or local services. If the interface can be implemented as a python function with an (*args, **kwargs) style calling convention AND it returns a JSON serializable object, THEN it can easily become a configurable CLI query. With the cliapi decorator, both required and optional parameters are expressible through the CLI. Help is also handled by the cliapi framework.
-
scoops: a dictionary which maps a CLI query name to a particular API data scoop. "scoops" are really just "sandboxed python eval()" statements. This allows scoops to be expressed as Python slices, comprehensions, ect. It also allows restricted ad-hoc queries on the command line when a specific value is desired but is not currently supported as an option in the CLI.
-
fetchers: a dictionary which maps from a particular API name to the actual python function which provides the backing store for the contents of the top-level API dictionary.
Default Cliapi Directory structure
├── cliapi_lib.py
├── readme.md
├── cliapi.py
├── __init__.py
├── providers
│ ├── azure.py
│ └── test.py
└── what_cloud.py