Skip to content

Commit 2697bb0

Browse files
authored
DOCS-3106: Document CLI usability improvements (#3960)
1 parent 62b068b commit 2697bb0

File tree

1 file changed

+98
-42
lines changed

1 file changed

+98
-42
lines changed

docs/dev/tools/cli.md

Lines changed: 98 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ The CLI lets you:
2626
For example, this CLI command moves a servo to the 75 degree position:
2727

2828
```sh {class="command-line" data-prompt="$"}
29-
viam machines part run --machine 82c608a-1be9-46a5 --organization "Artoo's Org" \
29+
viam machines part run --machine 82c608a-1be9-46a5 --org "Artoo's Org" \
3030
--location myLoc --part "mymachine-main" --data '{"name": "myServo", "angle_deg":75}' \
3131
viam.component.servo.v1.ServoService.MoveRequest
3232
```
@@ -563,7 +563,7 @@ viam locations api-key create --location-id=<location-id>
563563
| Command option | Description | Positional arguments |
564564
| -------------- | ----------- | -------------------- |
565565
| `list` | List all locations (name and id) that the authenticated session has access to, grouped by organization | **organization id** : (_optional_) return results for specified organization only |
566-
| `api-key` | Work with an api-key for your location | `create` |
566+
| `api-key` | Work with an API key for your location | `create` |
567567
| `--help` | Return help | - |
568568

569569
##### Positional arguments: `api-key`
@@ -603,7 +603,7 @@ See [Authenticate](#authenticate).
603603
| -------------- | ----------- | -------------------- |
604604
| `api-key` | Authenticate to Viam using an organization, location, or machine part API key. | - |
605605
| `print-access-token` | Prints the access token used to authenticate the current CLI session. | - |
606-
| `--disable-browser-open` | Authenticate in a headless environment by preventing the opening of the default browser during login (default: `false`). | - |
606+
| `--no-browser` | Authenticate in a headless environment by preventing the opening of the default browser during login (default: `false`). | - |
607607
| `--help` | Return help. | - |
608608

609609
##### Named arguments
@@ -1096,7 +1096,7 @@ See [create an organization API key](#create-an-organization-api-key) for more i
10961096
<!-- prettier-ignore -->
10971097
| Command option | Description | Positional arguments |
10981098
| -------------- | ----------- | -------------------- |
1099-
| `list` | List all organizations (name, id, and [namespace](/operate/reference/naming-modules/#create-a-namespace-for-your-organization)) that the authenticated session has access to. | - |
1099+
| `list` | List all organizations (name, ID, and [namespace](/operate/reference/naming-modules/#create-a-namespace-for-your-organization)) that the authenticated session has access to. | - |
11001100
| `api-key create` | Create a new organization API key. | - |
11011101
| `support-email get` | Get the support email for an organization. | - |
11021102
| `support-email set` | Set the support email for an organization. | - |
@@ -1165,6 +1165,62 @@ viam packages export --org-id=123 --name=MyMLModel --version=latest --type=ml_mo
11651165
| `--path` | The path to the package for upload. The package should be zipped with tar and have the `.tar.gz` extension. | `upload` | **Required** |
11661166
| `--destination` | The output directory for downloaded package. | `export` | **Required** |
11671167

1168+
### `profiles`
1169+
1170+
The `profiles` command allows you to manage different CLI authentication profiles, so you can easily switch between API key authentications (for example authentication to one organization versus another).
1171+
1172+
```sh {class="command-line" data-prompt="$"}
1173+
viam profiles add --profile-name=<name-of-profile-to-add> --key-id=<API-key-ID> --key=<API-key>
1174+
viam profiles update --profile-name=<name-of-profile-to-update> --key-id=<API-key-ID> --key=<API-key>
1175+
viam profiles list
1176+
viam profiles remove --profile-name=<name-of-profile-to-remove>
1177+
```
1178+
1179+
Examples:
1180+
1181+
```sh {id="terminal-prompt" class="command-line" data-prompt="$"}
1182+
# Add a new profile for authentication (throws error if profile already exists)
1183+
viam profiles add --profile-name=mycompany --key-id=54321zyx --key=123abcd1234
1184+
1185+
# Update an existing profile for authentication, or add it if it doesn't exist
1186+
viam profiles update --key=123abcd1234 --key-id=54321zyx --profile-name=mycompany
1187+
1188+
# List all existing profiles by name
1189+
viam profiles list
1190+
1191+
# Remove a profile
1192+
viam profiles remove --profile-name=mycompany
1193+
1194+
# Example of using a profile to see a list of machines available to that profile
1195+
viam --profile=mycompany machines list
1196+
```
1197+
1198+
See [create an organization API key](#create-an-organization-api-key) for more information.
1199+
1200+
{{% alert title="Tip" color="tip" %}}
1201+
You can set a default profile by using the `VIAM_CLI_PROFILE_NAME` environment variable.
1202+
{{% /alert %}}
1203+
1204+
#### Command options
1205+
1206+
<!-- prettier-ignore -->
1207+
| Command option | Description | Positional arguments |
1208+
| -------------- | ----------- | -------------------- |
1209+
| `add` | List all existing profiles by name. | - |
1210+
| `update` | Update an existing profile for authentication, or add it if it doesn't exist. | - |
1211+
| `list` | List all existing profiles by name. | - |
1212+
| `remove` | Remove a profile. | - |
1213+
| `--help` | Return help | - |
1214+
1215+
##### Named arguments
1216+
1217+
<!-- prettier-ignore -->
1218+
| Argument | Description | Applicable commands | Required? |
1219+
| -------- | ----------- | ------------------- | --------- |
1220+
| `--profile-name` | Name of the profile to add, update, or remove. | `add`, `update`, `remove` | **Required** |
1221+
| `--key-id` | The `key id` (UUID) of the API key. | `add`, `update` | **Required** |
1222+
| `--key` | The `key value` of the API key. | `api-key`, `update` | **Required** |
1223+
11681224
### `machines` (alias `robots`)
11691225

11701226
The `machines` command allows you to manage your machine fleet.
@@ -1179,15 +1235,15 @@ This includes:
11791235

11801236
```sh {class="command-line" data-prompt="$"}
11811237
viam machines list
1182-
viam machines status --organization=<org name> --location=<location name> --machine=<machine id>
1183-
viam machines logs --organization=<org name> --location=<location name> --machine=<machine id> [...named args]
1184-
viam machines api-key create --machine-id=<machine-id> [...named args]
1185-
viam machines part logs --machine=<machine> --part=<part> [...named args]
1186-
viam machines part status --organization=<org name> --location=<location name> --machine=<machine id>
1187-
viam machines part run --organization=<org name> --location=<location name> --machine=<machine id> [--stream] --data <meth>
1188-
viam machines part shell --organization=<org name> --location=<location name> --machine=<machine id>
1238+
viam machines status --org=<org id> --location=<location id> --machine=<machine id>
1239+
viam machines logs --org=<org id> --location=<location id> --machine=<machine id> [...named args]
1240+
viam machines api-key create --machine=<machine id> [...named args]
1241+
viam machines part logs --machine=<machine id> --part=<part id> [...named args]
1242+
viam machines part status --org=<org id> --location=<location id> --machine=<machine id>
1243+
viam machines part run --org=<org id> --location=<location id> --machine=<machine id> [--stream] --data <meth>
1244+
viam machines part shell --org=<org id> --location=<location id> --machine=<machine id> --part=<part id>
11891245
viam machines part restart --machine=<machine id> --part=<part id>
1190-
viam machines part cp --organization=<org name> --location=<location name> --machine=<machine id> --part=<part name> <file name> machine:/path/to/file
1246+
viam machines part cp --org=<org id> --location=<location id> --machine=<machine id> --part=<part id> <file name> machine:/path/to/file
11911247
```
11921248

11931249
Examples:
@@ -1197,48 +1253,45 @@ Examples:
11971253
viam machines list
11981254

11991255
# get machine status
1200-
viam machines status --machine=123 --organization="Robot's Org" --location=myLoc
1256+
viam machines status --machine=123
12011257

12021258
# create an api key for a machine
1203-
viam machines api-key create --machine-id=123 --name=MyKey
1259+
viam machines api-key create --machine=123 --name=MyKey
12041260

12051261
# stream logs from a machine
1206-
viam machines logs --machine=123 \
1207-
--organization="Robot's Org" --location=myLoc
1262+
viam machines logs --machine=123
12081263

12091264
# stream logs from a machine part
1210-
viam machines part logs --machine=123 \
1211-
--organization="Robot's Org" --location=myLoc --part=myrover-main --tail=true
1265+
viam machines part logs --part=myrover-main --tail=true
12121266

12131267
# stream classifications from a machine part every 500 milliseconds from the Viam Vision Service with classifier "stuff_detector"
1214-
viam machines part run --machine=123 \
1215-
--organization="Robot's Org" --location=myLoc --part=myrover-main --stream=500ms \
1268+
viam machines part run --part=myrover-main --stream=500ms \
12161269
--data='{"name": "vision", "camera_name": "cam", "classifier_name": "stuff_classifier", "n":1}' \
12171270
viam.service.vision.v1.VisionService.GetClassificationsFromCamera
12181271

12191272
# restart a part of a specified machine
1220-
viam machines part restart --machine=123 --part=456
1273+
viam machines part restart --part=123
12211274

12221275
# tunnel connections to the specified port on a machine part
12231276
viam machine part tunnel --part=123 --destination-port=1111 --local-port 2222
12241277

12251278
# Copy and a single file to a machine and change the file's name:
1226-
viam machine part cp --organization=my_org --location=my_location --machine=my_machine --part=m1-main my_file machine:/home/user/
1279+
viam machine part cp --part=123 my_file machine:/home/user/
12271280

12281281
# Recursively copy a directory to a machine:
1229-
viam machine part cp --machine=123 --part=123 -r my_dir machine:/home/user/
1282+
viam machine part cp --part=123 -r my_dir machine:/home/user/
12301283

12311284
# Copy multiple files to a machine with recursion and keep original permissions and metadata for the files:
1232-
viam machine part cp --machine=123 --part=123 -r -p my_dir my_file machine:/home/user/some/existing/dir/
1285+
viam machine part cp --part=123 -r -p my_dir my_file machine:/home/user/some/existing/dir/
12331286

12341287
# Copy a single file from a machine to a local destination:
1235-
viam machine part cp --machine=123 --part=123 machine:my_file ~/Downloads/
1288+
viam machine part cp --part=123 machine:my_file ~/Downloads/
12361289

12371290
# Recursively copy a directory from a machine to a local destination:
1238-
viam machine part cp --machine=123 --part=123 -r machine:my_dir ~/Downloads/
1291+
viam machine part cp --part=123 -r machine:my_dir ~/Downloads/
12391292

12401293
# Copy multiple files from the machine to a local destination with recursion and keep original permissions and metadata for the files:
1241-
viam machine part cp --machine=123 --part=123 -r -p machine:my_dir machine:my_file ~/some/existing/dir/
1294+
viam machine part cp --part=123 -r -p machine:my_dir machine:my_file ~/some/existing/dir/
12421295
```
12431296

12441297
#### Command options
@@ -1247,7 +1300,7 @@ viam machine part cp --machine=123 --part=123 -r -p machine:my_dir machine:my_fi
12471300
| Command option | Description | Positional arguments |
12481301
| -------------- | ----------- | -------------------- |
12491302
| `list` | List all machines that the authenticated session has access to, filtered by organization and location. | - |
1250-
| `api-key` | Work with an api-key for your machine | `create` (see [positional arguments: api-key](#positional-arguments-api-key)) |
1303+
| `api-key` | Work with an API key for your machine | `create` (see [positional arguments: api-key](#positional-arguments-api-key)) |
12511304
| `status` | Retrieve machine status for a specified machine | - |
12521305
| `logs` | Retrieve logs for a specified machine | - |
12531306
| `part` | Manage a specified machine part | `status`, `run`, `logs`, `shell`, `restart`, `tunnel`, `cp` (see [positional arguments: part](#positional-arguments-part)). To use the `part shell` and `part cp` commands, you must add the [ViamShellDanger fragment](https://app.viam.com/fragment/b511adfa-80ab-4a70-9bd5-fbb14696b17e/json) to your machine. |
@@ -1268,7 +1321,7 @@ viam machine part cp --machine=123 --part=123 -r -p machine:my_dir machine:my_fi
12681321
| -------- | ----------- |
12691322
| `status` | Retrieve machine status for a specified machine part |
12701323
| `run` | Run a component or service command, optionally at a specified interval. For commands that return data in their response, you can use this to stream data. |
1271-
| `logs` | Get logs for the specified machine part |
1324+
| `logs` | Get logs for the specified machine or machine part |
12721325
| `shell` | Access a machine part securely using a secure shell. To use this feature you must add the [`ViamShellDanger` fragment](https://app.viam.com/fragment/b511adfa-80ab-4a70-9bd5-fbb14696b17e/json) to your machine. |
12731326
| `restart` | Restart a machine part. |
12741327
| `cp` | Copy files to and from a machine part. |
@@ -1280,27 +1333,26 @@ viam machine part cp --machine=123 --part=123 -r -p machine:my_dir machine:my_fi
12801333
<!-- prettier-ignore -->
12811334
| Argument | Description | Applicable commands | Required? |
12821335
| -------- | ----------- | ------------------- | --------- |
1283-
| `--organization` | Organization name or ID that the machine belongs to | `list`, `status`, `logs`, `part` | **Required** |
1284-
| `--location` | Location name or ID that the machine belongs to or to list machines in | `list`, `status`, `logs`, `part` | **Required** |
1285-
| `--machine` | Machine name or ID for which the command is being issued. If machine name is used instead of ID, `--organization` and `--location` are required. | `status`, `logs`, `part` | **Required** |
1286-
| `--errors` | Boolean, return only errors (default: false) | `logs` | Optional |
1336+
| `--part` | Part ID for which the command is being issued. | `part` | **Required** |
1337+
| `--machine` | Machine ID for which the command is being issued. If machine name is used instead of ID, `--org` and `--location` are required. | `status`, `logs` | **Required** |
1338+
| `--location` | ID of the location that the machine belongs to or to list machines in. | `list`, `status`, `logs`, `part` | Optional |
1339+
| `--org` | ID of the organization that the machine belongs to or to list machines in. | `list`, `status`, `logs`, `part` | Optional |
1340+
| `--errors` | Boolean, return only errors (default: false). | `logs` | Optional |
12871341
| `--levels` | Filter logs by levels (debug, info, warn, error). Accepts multiple inputs in comma-separated list. | `logs` | Optional |
1288-
| `--part` | Part name or ID for which the command is being issued | `logs`, `part` | Optional |
1289-
| `--tail` | Tail (stream) logs, boolean(default false) | `part logs` | Optional |
1342+
| `--tail` | Tail (stream) logs, boolean(default false). | `part logs` | Optional |
12901343
| `--keyword` | Filter logs by keyword. | `logs` | Optional |
12911344
| `--start` | Filter logs to include only those after the start time. Time format example: `2025-01-13T21:30:00Z` (ISO-8601 timestamp in RFC3339). | `logs` | Optional |
12921345
| `--end` | Filter logs to include only those before the end time. Time format example: `2025-01-13T21:35:00Z` (ISO-8601 timestamp in RFC3339). | `logs` | Optional |
12931346
| `--count` | The number of logs to fetch. | `logs` | Optional |
12941347
| `--format` | THe file format for the output file. Options: `text` or `json`. | `logs` | Optional |
12951348
| `--output` | The path to the output file to store logs in. | `logs` | Optional |
1296-
| `--stream` | If specified, the interval in which to stream the specified data, for example, 100ms or 1s | `part run` | Optional |
1297-
| `--data` | Command data for the command being request to run (see [data argument](#using-the---stream-and---data-arguments)) | `part run` | **Required** |
1298-
| `--machine-id` | The machine to create an API key for | `api-key` | **Required** |
1299-
| `--name` | The optional name of the API key | `api-key` | Optional |
1300-
| `--org-id` | The optional organization ID to attach the key to | `api-key` | Optional |
1349+
| `--stream` | If specified, the interval in which to stream the specified data, for example, 100ms or 1s. | `part run` | Optional |
1350+
| `--data` | Command data for the command being request to run (see [data argument](#using-the---stream-and---data-arguments)). | `part run` | **Required** |
1351+
| `--machine-id` | The machine to create an API key for. | `api-key` | **Required** |
1352+
| `--name` | The optional name of the API key. | `api-key` | Optional |
13011353
| `--recursive`, `-r` | Recursively copy files. Default: `false`. | `part cp` | Optional |
13021354
| `--preserve`, `-p` | Preserve modification times and file mode bits from the source files. Default: `false`. | `part cp` | Optional |
1303-
| `--desination-port` | The port on a machine part to tunnel to. | `part tunnel` | **Required** |
1355+
| `--destination-port` | The port on a machine part to tunnel to. | `part tunnel` | **Required** |
13041356
| `--local-port` | The local port from which to tunnel. | `part tunnel` | **Required** |
13051357

13061358
##### Using the `--stream` and `--data` arguments
@@ -1482,4 +1534,8 @@ You can pass global options after the `viam` CLI keyword with any command.
14821534
<!-- prettier-ignore -->
14831535
| Global option | Description |
14841536
| ------------- | ----------- |
1485-
| `--debug` | Enable debug logging (default: false) |
1537+
| `--debug` | Enable debug logging (default: false). |
1538+
| `--disable-profiles`, `disable-profile` | Disable usage of [profiles](#profiles), falling back to default (false) behavior. |
1539+
| `--help`, `-h` | Show help (default: false). |
1540+
| `--profile` | Specify a particular [profile](#profiles) for the current command. |
1541+
| `--quiet`, `-q` | Suppress warnings (default: false). |

0 commit comments

Comments
 (0)