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
| Name | Description |
|---|---|
EXIT_FAILED | Exit status when an object failed: a data not read, a submission refused, an error of the API. |
EXIT_INVALID | Exit status when the file or a setting is invalid: nothing was sent. |
EXIT_OK | Exit status of a success. |
Runner | Runs a command: (arguments, client, output) -> exit status. |
Classes
| Name | Description |
|---|---|
Output | Where a command writes: its result on stdout, its progress on stderr. |
Functions
| Name | Description |
|---|---|
build_parser | Build the parser of the command line. |
main | Run the command line. |
retry_line | Say that a request is sent again, as every command shows it. |
run_apply | Make madbot hold what the file describes; submit only with --submit. |
run_browse | List what a source of the file holds, with the external identifiers. |
run_connections | List the connections of the account, with their plugin and shared parameters. |
run_field | Show what a metadata field accepts, with an example, and its place in a submission. |
run_fields | Write the metadata part of a submission, to complete in the file. |
run_plan | Show what apply would do, without writing anything. |
run_plugins | List the plugins of the instance, or show what one asks for in a deposit file. |
run_status | Tell where the deposit of the file stands in madbot. |
run_version | Print the version of the client and of the API it talks to, once the token is accepted. |
EXIT_FAILEDattributemodule attribute#
EXIT_FAILED = 1Exit status when an object failed: a data not read, a submission refused, an error of the API.
EXIT_INVALIDattributemodule attribute#
EXIT_INVALID = 2Exit status when the file or a setting is invalid: nothing was sent.
EXIT_OKattributemodule attribute#
EXIT_OK = 0Exit 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
as_jsonattributeinstance attribute#
as_json = as_jsonerrattributeinstance attribute#
err = err or sys.stderroutattributeinstance attribute#
out = out or sys.stdouterrormethod#
def error(text: str) -> NonePrint an error.
Parameters
| Name | Type | Description |
|---|---|---|
text | str | The error. |
linemethod#
def line(text: str = '') -> NonePrint a line of the result, unless the result is JSON.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
text | str | '' | The line. |
resultmethod#
def result(value: Any) -> NonePrint the result as JSON, when asked.
Parameters
| Name | Type | Description |
|---|---|---|
value | Any | The result. |
build_parserfunction#
def build_parser() -> argparse.ArgumentParserBuild 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) -> intRun the command line.
Parameters
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) -> strSay that a request is sent again, as every command shows it.
Parameters
Returns
str- The line.
run_applyfunction#
def run_apply(args: argparse.Namespace, client: Client, output: Output) -> intMake madbot hold what the file describes; submit only with --submit.
Parameters
| Name | Type | Description |
|---|---|---|
args | argparse.Namespace | The arguments: the checked deposit file, its file name,
submit, retry_failed and quiet. |
client | Client | The client. |
output | Output | Where to write. |
Returns
int- 0, or 1 when an object failed.
run_browsefunction#
def run_browse(args: argparse.Namespace, client: Client, output: Output) -> intList what a source of the file holds, with the external identifiers.
Parameters
| Name | Type | Description |
|---|---|---|
args | argparse.Namespace | The arguments: the checked deposit file, the source key, the
path and connect. |
client | Client | The client. |
output | Output | Where to write. |
Returns
int- The exit status.
run_connectionsfunction#
def run_connections(args: argparse.Namespace, client: Client, output: Output) -> intList the connections of the account, with their plugin and shared parameters.
Parameters
| Name | Type | Description |
|---|---|---|
args | argparse.Namespace | The arguments: the workspace, or None for all of them. |
client | Client | The client. |
output | Output | Where to write. |
Returns
int- The exit status.
run_fieldfunction#
def run_field(args: argparse.Namespace, client: Client, output: Output) -> intShow what a metadata field accepts, with an example, and its place in a submission.
Parameters
| Name | Type | Description |
|---|---|---|
args | argparse.Namespace | The 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. |
client | Client | The client. |
output | Output | Where to write. |
Returns
int- The exit status.
run_fieldsfunction#
def run_fields(args: argparse.Namespace, client: Client, output: Output) -> intWrite the metadata part of a submission, to complete in the file.
Parameters
| Name | Type | Description |
|---|---|---|
args | argparse.Namespace | The arguments: the checked deposit file, the submission title
and the level of the fields to write. |
client | Client | The client. |
output | Output | Where to write. |
Returns
int- The exit status.
run_planfunction#
def run_plan(args: argparse.Namespace, client: Client, output: Output) -> intShow what apply would do, without writing anything.
Parameters
| Name | Type | Description |
|---|---|---|
args | argparse.Namespace | The arguments: the checked deposit file and verbose. |
client | Client | The client. |
output | Output | Where 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) -> intList the plugins of the instance, or show what one asks for in a deposit file.
Parameters
| Name | Type | Description |
|---|---|---|
args | argparse.Namespace | The arguments: the slug of a plugin, or None. |
client | Client | The client. |
output | Output | Where to write. |
Returns
int- The exit status.
run_statusfunction#
def run_status(args: argparse.Namespace, client: Client, output: Output) -> intTell where the deposit of the file stands in madbot.
Parameters
| Name | Type | Description |
|---|---|---|
args | argparse.Namespace | The arguments: the checked deposit file. |
client | Client | The client. |
output | Output | Where 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) -> intPrint the version of the client and of the API it talks to, once the token is accepted.
Parameters
| Name | Type | Description |
|---|---|---|
_args | argparse.Namespace | The arguments. |
client | Client | The client. |
output | Output | Where to write. |
Returns
int- The exit status.

