Skip to main content

cli-contracts-runtime

The runtime for the Python programs and command wrappers that cli-contracts generates from a CLI contract (templates: builtin:python). A generated program holds its command tree and handler protocol; this package parses an invocation over the tree by the same rules as the TypeScript program generated from the same contract (which uses commander), and writes the same help, errors, --introspect policy and extract output.

pip install cli-contracts-runtime

Python 3.10 or later. The package uses the standard library only.

Usage

Generate the package (cli-contracts.config.yaml):

generators:
  python:
    enabled: true
    output: ./tool/cli
    templates: builtin:python

Implement the handlers and run the program:

import sys

import cli_contracts_runtime

from tool import cli


class Handlers:
    # One method per command of the contract; it returns the exit code (None for 0).
    def users_import(self, file, options, parent_opts):
        if options.get("dryRun"):
            print("dry run:", file)
        return 0


def on_usage_error(err, command):
    # Optional: for an invocation the program rejects, writes what the contract declares for invalid arguments and returns the exit code.
    sys.stderr.write('{"code":"INVALID_ARGS","message":%s}\n' % cli_contracts_runtime.quote(err.message))
    return 2


if __name__ == "__main__":
    cli.create_program(Handlers(), "1.0.0", on_usage_error).main()

The options a handler receives are a dict of the options given or defaulted, keyed as the program keys them (dry-run → dryRun); parent_opts holds those of the command and its ancestors. A command that takes --adapter may return the prompt it built, or (exit_code, prompt); the program writes the prompt with --show-prompt.

create_program returns a cli_contracts_runtime.Program; its run(argv, stdout, stderr) runs an invocation (argv without the program name) without exiting and returns its exit code.

License

MIT

Metadata

Release files for cli-contracts-runtime 0.36.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 cli-contracts-runtime 0.36.0
File Size Uploaded Provenance Actions
cli_contracts_runtime-0.36.0.tar.gz 14.3 kB Without provenance Details for cli_contracts_runtime-0.36.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cli-contracts-runtime 0.36.0
File Interpreter ABI Platform Actions
cli_contracts_runtime-0.36.0-py3-none-any.whl Python 3 none any Details for cli_contracts_runtime-0.36.0-py3-none-any.whl

Total release size: 30.4 kB

Release files / cli_contracts_runtime-0.36.0.tar.gz

Download URL cli_contracts_runtime-0.36.0.tar.gz
Size 14.3 kB
Tags Source
SHA-256 checksum
How to use checksums
a0c61baf01cebb8849a5d3c453cdb1c51a42d9243a4cdaa600ee9a1af247b5c9
BLAKE2b-256 checksum
How to use checksums
a1a748ca9c73e186ebdf8d5996245f7fcd1a9da4a01fe2ff853da686964b7fea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.16

Release files / cli_contracts_runtime-0.36.0-py3-none-any.whl

Download URL cli_contracts_runtime-0.36.0-py3-none-any.whl
Size 16.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6b97ce10e1a1fd4732ec6d814a404f23020fbce507273e4637aa96a698251fd8
BLAKE2b-256 checksum
How to use checksums
4cad95470245d3111e41bb77b2c7964913ce65e8fdb91d00746acb221619d018
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.16

Security for cli-contracts-runtime 0.36.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.36.0 This release

2 release files No provenance

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