# madbot_cli.cli

*module*

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.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/cli.py#L1-1)

## madbot_cli.cli.EXIT_FAILED

*attribute* · *module attribute*

```python
EXIT_FAILED = 1
```

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

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/cli.py#L25-25)

## madbot_cli.cli.EXIT_INVALID

*attribute* · *module attribute*

```python
EXIT_INVALID = 2
```

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

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/cli.py#L27-27)

## madbot_cli.cli.EXIT_OK

*attribute* · *module attribute*

```python
EXIT_OK = 0
```

Exit status of a success.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/cli.py#L23-23)

## madbot_cli.cli.Runner

*attribute* · *module attribute*

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

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

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/cli.py#L567-567)

## madbot_cli.cli.Output

*class*

```python
class Output
```

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

**Parameters**

- `as_json` (`bool`) — Print the result as JSON.
- `out` (`TextIO`) (default: `None`) — The result; `sys.stdout` by default.
- `err` (`TextIO`) (default: `None`) — The progress and the errors; `sys.stderr` by default.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/cli.py#L31-86)

### madbot_cli.cli.Output.as_json

*attribute* · *instance attribute*

```python
as_json = as_json
```

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/cli.py#L49-49)

### madbot_cli.cli.Output.err

*attribute* · *instance attribute*

```python
err = err or sys.stderr
```

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/cli.py#L51-51)

### madbot_cli.cli.Output.out

*attribute* · *instance attribute*

```python
out = out or sys.stdout
```

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/cli.py#L50-50)

### madbot_cli.cli.Output.error

*method*

```python
def error(text: str) -> None
```

Print an error.

**Parameters**

- `text` (`str`) — The error.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/cli.py#L65-74)

### madbot_cli.cli.Output.line

*method*

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

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

**Parameters**

- `text` (`str`) (default: `''`) — The line.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/cli.py#L53-63)

### madbot_cli.cli.Output.result

*method*

```python
def result(value: Any) -> None
```

Print the result as JSON, when asked.

**Parameters**

- `value` (`Any`) — The result.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/cli.py#L76-86)

## madbot_cli.cli.build_parser

*function*

```python
def build_parser() -> argparse.ArgumentParser
```

Build the parser of the command line.

**Returns**

- (`argparse.ArgumentParser`) — The parser, with a sub-command per action.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/cli.py#L393-564)

## madbot_cli.cli.main

*function*

```python
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**

- `argv` (`sequence of str`) (default: `None`) — The arguments; ``sys.argv[1:]`` by default.
- `client` (`Client`) (default: `None`) — The client to use instead of one made from the environment, as tests do.
- `out` (`TextIO`) (default: `None`) — Where the result goes; stdout by default.
- `err` (`TextIO`) (default: `None`) — Where 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.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/cli.py#L571-623)

## madbot_cli.cli.retry_line

*function*

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

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

**Parameters**

- `reason` (`str`) — Why the last attempt failed.
- `delay` (`float`) — Seconds before the next attempt.
- `attempt` (`int`) — The number of the next attempt.

**Returns**

- (`str`) — The line.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/cli.py#L147-165)

## madbot_cli.cli.run_apply

*function*

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

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

**Parameters**

- `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.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/cli.py#L168-212)

## madbot_cli.cli.run_browse

*function*

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

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

**Parameters**

- `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.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/cli.py#L266-296)

## madbot_cli.cli.run_connections

*function*

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

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

**Parameters**

- `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.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/cli.py#L330-352)

## madbot_cli.cli.run_field

*function*

```python
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**

- `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.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/cli.py#L355-390)

## madbot_cli.cli.run_fields

*function*

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

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

**Parameters**

- `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.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/cli.py#L240-263)

## madbot_cli.cli.run_plan

*function*

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

Show what apply would do, without writing anything.

**Parameters**

- `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.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/cli.py#L121-144)

## madbot_cli.cli.run_plugins

*function*

```python
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**

- `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.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/cli.py#L299-327)

## madbot_cli.cli.run_status

*function*

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

Tell where the deposit of the file stands in madbot.

**Parameters**

- `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.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/cli.py#L215-237)

## madbot_cli.cli.run_version

*function*

```python
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**

- `_args` (`argparse.Namespace`) — The arguments.
- `client` (`Client`) — The client.
- `output` (`Output`) — Where to write.

**Returns**

- (`int`) — The exit status.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/cli.py#L89-118)
