API reference#

Generated from the docstrings and type annotations in src/. Only the names on this page are public and follow semantic versioning (while 0.x, a breaking change bumps the minor version and is listed in the changelog); every other module is internal. tests/test_api_reference.py fails if a name in graftkit.__all__ or graftkit.testing.__all__ is missing.

Extensions#

A repository adds commands with an Extension, exposed as an entry point in the graftkit.extensions group (<name> = "<package>.graftkit:EXTENSION") and named by [cli] extension = "<name>" in its graftkit.toml.

Extension

What a repository adds to the core: a name and a factory of its commands.

Repo

The repository root a command runs in, as the core hands it to every command.

Declaring commands#

Re-exported from cli-interview-kit: how commands, flags and interview questions are declared.

Command

One command.

Example

A command line that runs a command, shown in --help and --describe.

Option

A plain option or positional argument; not an interview question.

Interview

A command's questions and consents, and where their dynamic parts come from.

Question

One interview question.

Consent

A confirmation a command may need before it acts.

Invocation

What a command's run function receives.

Console

Styled output and interactive prompts for a command.

CliError

An expected failure, reported as its message without a traceback.

non_empty

Reject a blank answer.

when

Return a condition: key is one of values.

Testing#

Helpers for testing an extension, or the core. The pytest plugin, registered as graftkit wherever the package is installed, provides them as fixtures: graftkit_root(config) makes a temporary root with the developer’s GRAFTKIT_* variables and user config kept out, graftkit_run(root, *args, ...) is run, fake_github is a fresh FakeGitHub and fake_git a fresh FakeGit.

run

Run the CLI in a root, in this process, and capture what it printed.

Result

What a command run printed and returned.

make_root

Create a root: a folder holding graftkit.toml.

assert_conformant

Fail unless an extension follows the command standard.

FakeGitHub

An in-memory Fetcher: publish releases, then let the skills commands read them.

FakeGit

An in-memory Git: clones are folders it creates, pull requests are recorded.

FakeClone

A clone FakeGit made: where it came from and the state a test gives it.

PullRequest

A pull request FakeGit opened.

isolate

Keep the developer's environment out of a test: root, user config, settings, cache.