Skip to content

madbot_cli.cli

The madbot-cli command.

Exit statuses: 0 on success, 1 when an object failed, 2 when the file or a setting is invalid. Every command accepts --json to print a result a program can read, and --verbose to show the request and the answer of the API under an error, which is otherwise said in a sentence.

Attributes

NameDescription
EXIT_FAILEDExit status when an object failed: a data not read, a submission refused, an error of the API.
EXIT_INVALIDExit status when the file or a setting is invalid: nothing was sent.
EXIT_OKExit status of a success.
RunnerRuns a command: (arguments, client, output) -> exit status.

Classes

NameDescription
OutputWhere a command writes: its result on stdout, its progress on stderr.

Functions

NameDescription
build_parserBuild the parser of the command line.
mainRun the command line.
retry_lineSay that a request is sent again, as every command shows it.
run_applyMake madbot hold what the file describes; submit only with --submit.
run_browseList what a source of the file holds, with the external identifiers.
run_connectionsList the connections of the account, with their plugin and shared parameters.
run_fieldShow what a metadata field accepts, with an example, and its place in a submission.
run_fieldsWrite the metadata part of a submission, to complete in the file.
run_planShow what apply would do, without writing anything.
run_pluginsList the plugins of the instance, or show what one asks for in a deposit file.
run_statusTell where the deposit of the file stands in madbot.
run_versionPrint the version of the client and of the API it talks to, once the token is accepted.

EXIT_FAILEDattributemodule attribute#

EXIT_FAILED = 1

Exit status when an object failed: a data not read, a submission refused, an error of the API.

EXIT_INVALIDattributemodule attribute#

EXIT_INVALID = 2

Exit status when the file or a setting is invalid: nothing was sent.

EXIT_OKattributemodule attribute#

EXIT_OK = 0

Exit status of a success.

Runnerattributemodule attribute#

Runner = Callable[[argparse.Namespace, Client, Output], int]

Runs a command: (arguments, client, output) -> exit status.

Outputclass#

class Output(as_json: bool, out: TextIO | None = None, err: TextIO | None = None)

Where a command writes: its result on stdout, its progress on stderr.

Parameters

NameTypeDefaultDescription
as_jsonboolrequiredPrint the result as JSON.
outTextIONoneThe result; sys.stdout by default.
errTextIONoneThe progress and the errors; sys.stderr by default.

as_jsonattributeinstance attribute#

as_json = as_json

errattributeinstance attribute#

err = err or sys.stderr

outattributeinstance attribute#

out = out or sys.stdout

errormethod#

def error(text: str) -> None

Print an error.

Parameters

NameTypeDescription
textstrThe error.

linemethod#

def line(text: str = '') -> None

Print a line of the result, unless the result is JSON.

Parameters

NameTypeDefaultDescription
textstr''The line.

resultmethod#

def result(value: Any) -> None

Print the result as JSON, when asked.

Parameters

NameTypeDescription
valueAnyThe result.

build_parserfunction#

def build_parser() -> argparse.ArgumentParser

Build the parser of the command line.

Returns

argparse.ArgumentParser
The parser, with a sub-command per action.

mainfunction#

def main(argv: Sequence[str] | None = None, *, client: Client | None = None, out: TextIO | None = None, err: TextIO | None = None) -> int

Run the command line.

Parameters

NameTypeDefaultDescription
argvsequence of strNoneThe arguments; sys.argv[1:] by default.
clientClientNoneThe client to use instead of one made from the environment, as tests do.
outTextIONoneWhere the result goes; stdout by default.
errTextIONoneWhere the progress and errors go; stderr by default.

Returns

int
The exit status: 0 on success, 1 when an object failed, 2 when the file or a setting is invalid.

retry_linefunction#

def retry_line(reason: str, delay: float, attempt: int) -> str

Say that a request is sent again, as every command shows it.

Parameters

NameTypeDescription
reasonstrWhy the last attempt failed.
delayfloatSeconds before the next attempt.
attemptintThe number of the next attempt.

Returns

str
The line.

run_applyfunction#

def run_apply(args: argparse.Namespace, client: Client, output: Output) -> int

Make madbot hold what the file describes; submit only with --submit.

Parameters

NameTypeDescription
argsargparse.NamespaceThe arguments: the checked deposit file, its file name, submit, retry_failed and quiet.
clientClientThe client.
outputOutputWhere to write.

Returns

int
0, or 1 when an object failed.

run_browsefunction#

def run_browse(args: argparse.Namespace, client: Client, output: Output) -> int

List what a source of the file holds, with the external identifiers.

Parameters

NameTypeDescription
argsargparse.NamespaceThe arguments: the checked deposit file, the source key, the path and connect.
clientClientThe client.
outputOutputWhere to write.

Returns

int
The exit status.

run_connectionsfunction#

def run_connections(args: argparse.Namespace, client: Client, output: Output) -> int

List the connections of the account, with their plugin and shared parameters.

Parameters

NameTypeDescription
argsargparse.NamespaceThe arguments: the workspace, or None for all of them.
clientClientThe client.
outputOutputWhere to write.

Returns

int
The exit status.

run_fieldfunction#

def run_field(args: argparse.Namespace, client: Client, output: Output) -> int

Show what a metadata field accepts, with an example, and its place in a submission.

Parameters

NameTypeDescription
argsargparse.NamespaceThe arguments: the slug of the field, its source, the text to search and within, the deposit file and the title of a submission, or None.
clientClientThe client.
outputOutputWhere to write.

Returns

int
The exit status.

run_fieldsfunction#

def run_fields(args: argparse.Namespace, client: Client, output: Output) -> int

Write the metadata part of a submission, to complete in the file.

Parameters

NameTypeDescription
argsargparse.NamespaceThe arguments: the checked deposit file, the submission title and the level of the fields to write.
clientClientThe client.
outputOutputWhere to write.

Returns

int
The exit status.

run_planfunction#

def run_plan(args: argparse.Namespace, client: Client, output: Output) -> int

Show what apply would do, without writing anything.

Parameters

NameTypeDescription
argsargparse.NamespaceThe arguments: the checked deposit file and verbose.
clientClientThe client.
outputOutputWhere to write.

Returns

int
0, or 1 when data of the file cannot be found in their source.

run_pluginsfunction#

def run_plugins(args: argparse.Namespace, client: Client, output: Output) -> int

List the plugins of the instance, or show what one asks for in a deposit file.

Parameters

NameTypeDescription
argsargparse.NamespaceThe arguments: the slug of a plugin, or None.
clientClientThe client.
outputOutputWhere to write.

Returns

int
The exit status.

run_statusfunction#

def run_status(args: argparse.Namespace, client: Client, output: Output) -> int

Tell where the deposit of the file stands in madbot.

Parameters

NameTypeDescription
argsargparse.NamespaceThe arguments: the checked deposit file.
clientClientThe client.
outputOutputWhere to write.

Returns

int
0, or 1 when a data was not read or a submission is in error.

run_versionfunction#

def run_version(_args: argparse.Namespace, client: Client, output: Output) -> int

Print the version of the client and of the API it talks to, once the token is accepted.

Parameters

NameTypeDescription
_argsargparse.NamespaceThe arguments.
clientClientThe client.
outputOutputWhere to write.

Returns

int
The exit status.