# CLI and telesphorepo.toml

> Every command of the Telesphorepo CLI, the keys of telesphorepo.toml, the rules that publish by version, and the variables of a CI job.

Source: https://docs.telesphorepo.com/cli/

The commands of the Telesphorepo CLI, the project file it reads, and the variables it reads in CI. Each server serves the CLI of its own version: [install the CLI](/install-cli/) from yours. Run `telesphorepo help` and a command to see its examples.

## CLI commands

| Command                                    | What it does                                                       |
| ------------------------------------------ | ------------------------------------------------------------------ |
| [`setup LINK`](#setup)                     | Sets up the project of this folder                                 |
| [`publish [FILE...]`](#publish)            | Publishes the project, or uploads files                            |
| [`get URL...`](#get)                       | Downloads files, from private repositories too                     |
| [`login [SERVER]`](#login)                 | Approves this computer for a server, or switches accounts          |
| [`logout [SERVER]`](#logout)               | Revokes the device of the active account and removes its files     |
| [`status`](#status)                        | Shows the accounts of this computer and the project of this folder |
| [`update [SERVER]`](#update)               | Installs the CLI of the server                                     |
| [`version`, `help`](#cli-version-and-help) | Prints the version, or the help of a command                       |

### setup

Sets up the project of this folder from the setup line on the **Publish to this repository** tab. A setup line works once, for 10 minutes. The CLI approves this computer, or uses the approval it has, and writes `telesphorepo.toml`. For a Docker repository it writes no file, and offers to add its credential helper to the Docker config instead. On a terminal, it then offers a CI file: GitHub Actions, Jenkinsfile or Jenkins freestyle job.

```sh
telesphorepo setup 'https://repo.example.com/#/setup/trsu_...'
telesphorepo setup 'https://repo.example.com/#/setup/trsu_...' --name "build box"
```

`--name` names the computer. The default is its host name.

### publish

Publishes the project of this folder with its own build tool: Maven, Gradle, npm, Python, Cargo, .NET or a Helm chart. With files, it uploads them: to a raw, Debian, Arch Linux or RPM repository, `.nupkg` files to NuGet, or wheels and sdists to Python with no build. A Docker repository publishes with `docker push` and the credential helper. The steps are in [Publish from your computer](/publish-from-a-project/#publish).

```sh
telesphorepo publish
telesphorepo publish build/hello_1.0_amd64.deb
telesphorepo publish dist/app-1.0-py3-none-any.whl
```

| Flag              | What it does                                                                                                      |
| ----------------- | ----------------------------------------------------------------------------------------------------------------- |
| `--version V`     | The version that [the rules](#publish-by-version) of `telesphorepo.toml` match, in place of the one the CLI reads |
| `--into FOLDER`   | Raw: uploads into this folder, in place of `path`                                                                 |
| `--if-new`        | Raw: uploads only when the path holds no file                                                                     |
| `--if-match ETAG` | Raw: uploads one file only over the file of this ETag, from a GET of it. Takes `*` for any file                   |

When the server holds another file than `--if-new` or `--if-match` says, the CLI stores nothing and exits with code 3. Read the file again, and publish again. [Use raw files for an updater](https://github.com/Telesphorepo/Telesphorepo/blob/main/docs/updater.md) shows the whole pattern.

### get

Downloads files into this folder, as the web UI links them. On a computer approved for the server, it reads as the active account, so private repositories work with no token to copy. `-o FILE` names the file of one address, and `-o -` writes it to the standard output.

```sh
telesphorepo get https://repo.example.com/raw/releases/app/1.0/app.tar.gz
telesphorepo get -o app.tar.gz https://repo.example.com/raw/releases/app/latest.tar.gz
```

### login

Approves this computer for a server, with no project. Open the link that the CLI prints, sign in, and approve the code: the computer belongs to the account that approves it. One computer can hold several accounts of one server, such as an admin and a publisher. On a terminal, `login` lists them and asks which one is active.

```sh
telesphorepo login https://repo.example.com
telesphorepo login https://repo.example.com --name "build box"
```

### logout

Revokes the approval of the active account, and deletes its key. The last account of a server also removes the Docker helper entries of that server. With no server, it uses the server of the project in this folder, else the one server of this computer.

```sh
telesphorepo logout https://repo.example.com
```

### status

Shows each account of this computer, whether the server accepts it, and the Docker helper entries. For this folder, it shows `telesphorepo.toml`, the command that `telesphorepo publish` runs and, with rules, the version and the repository it picks. It shows no secret.

```sh
telesphorepo status
```

### update

Installs the CLI of the server: the server of this project, else the one you name, else the one server of this computer. The CLI checks the SHA-256 of the download. A newer CLI stays, because it works with an older server.

```sh
telesphorepo update
```

### CLI version and help

```sh
telesphorepo version
telesphorepo help publish
```

## Files and the Docker helper

- The key of each approved account is in `~/.telesphorepo/<server>/accounts/<user>/device.json`. Only you can read it.
- `docker-credential-telesphorepo` is the same program under the name that Docker, Podman, Helm and ORAS call.

## telesphorepo.toml

The project file that `telesphorepo setup` writes. It holds no secret: commit it. The CLI finds it in this folder or a folder above.

| Key         | Needed | What it sets                                                                                   |
| ----------- | ------ | ---------------------------------------------------------------------------------------------- |
| `server`    | yes    | The address of the server                                                                      |
| `repo`      | yes    | The repository                                                                                 |
| `kind`      | no     | `maven` or `gradle`, when the folder holds both                                                |
| `path`      | no     | The folder in a raw repository                                                                 |
| `dist`      | no     | The distribution of a Debian repository                                                        |
| `component` | no     | The component of a Debian repository                                                           |
| `[[when]]`  | no     | A rule that publishes some versions elsewhere, as in [Publish by version](#publish-by-version) |

```toml title="telesphorepo.toml"
server = "https://repo.example.com"
repo = "releases"
```

The file names one repository. To publish to two, such as a library and a Debian package from one git repository, put a `telesphorepo.toml` in each folder and run `telesphorepo publish` in each.

### Publish by version

Each `[[when]]` rule names a `version` pattern and the keys it changes: `repo`, `path`, `dist` or `component`. The first rule that matches decides, and a version that no rule matches goes where the keys above say. In a pattern, `*` stands for any text.

```toml title="telesphorepo.toml"
server = "https://repo.example.com"
repo = "maven-releases"

[[when]]
version = "*-SNAPSHOT"
repo = "maven-snapshots"
```

The CLI prints the version and the repository before it publishes. It reads the version from the project:

| Project | Version                                                                                                                                   |
| ------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| Gradle  | `version` of the root project                                                                                                             |
| Maven   | `project.version`                                                                                                                         |
| npm     | `version` in `package.json`                                                                                                               |
| Cargo   | `version` in `Cargo.toml`                                                                                                                 |
| Python  | `version` in `pyproject.toml`                                                                                                             |
| Helm    | `version` in `Chart.yaml`                                                                                                                 |
| .NET    | `<Version>` in the project file                                                                                                           |
| Files   | The version in each package: `.deb`, `.rpm`, `.pkg.tar.*`, `.nupkg`, `.whl`. Files of different versions can go to different repositories |

Raw files have no version: give one with `--version`. Each ecosystem marks a pre-release its own way, so write the pattern for yours: `*-SNAPSHOT` for Maven, `*-*` for npm pre-releases, `*~*` for a Debian version that sorts before its release.

## CI variables

| Variable              | What it is                                                                          |
| --------------------- | ----------------------------------------------------------------------------------- |
| `OIDC_TOKEN`          | The identity token of a Jenkins job. Its audience must be the address of the server |
| `TELESPHOREPO_SERVER` | The server of the Docker credential helper in a CI job                              |

A GitHub Actions job needs no variable. It needs `permissions: id-token: write`.
