Add alias env set for command env add

Change-type: minor
This commit is contained in:
myarmolinsky 2024-09-26 12:32:10 -04:00
parent 44082e22e4
commit f1924bba6b
14 changed files with 127 additions and 118 deletions

View File

@ -16,7 +16,7 @@ _balena() {
config_cmds=( generate inject read reconfigure write )
device_cmds=( deactivate detect identify init list local-mode logs move os-update pin public-url purge reboot register rename restart rm shutdown ssh start-service stop-service track-fleet )
devices_cmds=( supported )
env_cmds=( add list rename rm )
env_cmds=( list rename rm set )
fleet_cmds=( create list pin purge rename restart rm track-latest )
internal_cmds=( osinit )
local_cmds=( configure flash )

View File

@ -15,7 +15,7 @@ _balena_complete()
config_cmds="generate inject read reconfigure write"
device_cmds="deactivate detect identify init list local-mode logs move os-update pin public-url purge reboot register rename restart rm shutdown ssh start-service stop-service track-fleet"
devices_cmds="supported"
env_cmds="add list rename rm"
env_cmds="list rename rm set"
fleet_cmds="create list pin purge rename restart rm track-latest"
internal_cmds="osinit"
local_cmds="configure flash"

View File

@ -222,10 +222,10 @@ are encouraged to regularly update the balena CLI to the latest version.
- Environment Variables
- [env add](#env-add)
- [env list](#env-list)
- [env rename](#env-rename)
- [env rm](#env-rm)
- [env set](#env-set)
- Fleets
@ -2072,83 +2072,6 @@ produce JSON output instead of tabular output
# Environment Variables
## env add
### Description
Add an environment or config variable to one or more fleets, devices or
services, as selected by the respective command-line options. Either the
--fleet or the --device option must be provided, and either may be be
used alongside the --service option to define a service-specific variable.
(A service corresponds to a Docker image/container in a microservices fleet.)
When the --service option is used in conjunction with the --device option,
the service variable applies to the selected device only. Otherwise, it
applies to all devices of the selected fleet. If the --service option is
omitted, the variable applies to all services.
If VALUE is omitted, the CLI will attempt to use the value of the environment
variable of same name in the CLI process' environment. In this case, a warning
message will be printed. Use `--quiet` to suppress it.
'BALENA_' or 'RESIN_' are reserved variable name prefixes used to identify
"configuration variables". Configuration variables control balena platform
features and are treated specially by balenaOS and the balena supervisor
running on devices. They are also stored differently in the balenaCloud API
database. Configuration variables cannot be set for specific services,
therefore the --service option cannot be used when the variable name starts
with a reserved prefix. When defining custom fleet variables, please avoid
these reserved prefixes.
Fleets may be specified by fleet name or slug. Fleet slugs are
the recommended option, as they are unique and unambiguous. Slugs can be
listed with the `balena fleet list` command. Note that slugs may change if the
fleet is renamed. Fleet names are not unique and may result in "Fleet is
ambiguous" errors at any time (even if it "used to work in the past"), for
example if the name clashes with a newly created public fleet, or with fleets
from other balena accounts that you may be invited to join under any role.
For this reason, fleet names are especially discouraged in scripts (e.g. CI
environments).
Examples:
$ balena env add TERM --fleet MyFleet
$ balena env add EDITOR vim -f myorg/myfleet
$ balena env add EDITOR vim --fleet MyFleet,MyFleet2
$ balena env add EDITOR vim --fleet MyFleet --service MyService
$ balena env add EDITOR vim --fleet MyFleet,MyFleet2 --service MyService,MyService2
$ balena env add EDITOR vim --device 7cf02a6
$ balena env add EDITOR vim --device 7cf02a6,d6f1433
$ balena env add EDITOR vim --device 7cf02a6 --service MyService
$ balena env add EDITOR vim --device 7cf02a6,d6f1433 --service MyService,MyService2
### Arguments
#### NAME
environment or config variable name
#### VALUE
variable value; if omitted, use value from this process' environment
### Options
#### -f, --fleet FLEET
fleet name or slug (preferred)
#### -d, --device DEVICE
device UUID
#### -q, --quiet
suppress warning messages
#### -s, --service SERVICE
service name
## env list
### Aliases
@ -2367,6 +2290,90 @@ select a service variable (may be used together with the --device option)
do not prompt for confirmation before deleting the variable
## env set
### Aliases
- `env add`
To use one of the aliases, replace `env set` with the alias.
### Description
Add or update an environment or config variable to one or more fleets, devices or
services, as selected by the respective command-line options. Either the
--fleet or the --device option must be provided, and either may be be
used alongside the --service option to define a service-specific variable.
(A service corresponds to a Docker image/container in a microservices fleet.)
When the --service option is used in conjunction with the --device option,
the service variable applies to the selected device only. Otherwise, it
applies to all devices of the selected fleet. If the --service option is
omitted, the variable applies to all services.
If VALUE is omitted, the CLI will attempt to use the value of the environment
variable of same name in the CLI process' environment. In this case, a warning
message will be printed. Use `--quiet` to suppress it.
'BALENA_' or 'RESIN_' are reserved variable name prefixes used to identify
"configuration variables". Configuration variables control balena platform
features and are treated specially by balenaOS and the balena supervisor
running on devices. They are also stored differently in the balenaCloud API
database. Configuration variables cannot be set for specific services,
therefore the --service option cannot be used when the variable name starts
with a reserved prefix. When defining custom fleet variables, please avoid
these reserved prefixes.
Fleets may be specified by fleet name or slug. Fleet slugs are
the recommended option, as they are unique and unambiguous. Slugs can be
listed with the `balena fleet list` command. Note that slugs may change if the
fleet is renamed. Fleet names are not unique and may result in "Fleet is
ambiguous" errors at any time (even if it "used to work in the past"), for
example if the name clashes with a newly created public fleet, or with fleets
from other balena accounts that you may be invited to join under any role.
For this reason, fleet names are especially discouraged in scripts (e.g. CI
environments).
Examples:
$ balena env set TERM --fleet MyFleet
$ balena env set EDITOR vim -f myorg/myfleet
$ balena env set EDITOR vim --fleet MyFleet,MyFleet2
$ balena env set EDITOR vim --fleet MyFleet --service MyService
$ balena env set EDITOR vim --fleet MyFleet,MyFleet2 --service MyService,MyService2
$ balena env set EDITOR vim --device 7cf02a6
$ balena env set EDITOR vim --device 7cf02a6,d6f1433
$ balena env set EDITOR vim --device 7cf02a6 --service MyService
$ balena env set EDITOR vim --device 7cf02a6,d6f1433 --service MyService,MyService2
### Arguments
#### NAME
environment or config variable name
#### VALUE
variable value; if omitted, use value from this process' environment
### Options
#### -f, --fleet FLEET
fleet name or slug (preferred)
#### -d, --device DEVICE
device UUID
#### -q, --quiet
suppress warning messages
#### -s, --service SERVICE
service name
# Fleets
## fleet create

View File

@ -35,11 +35,13 @@ interface ArgsDef {
value?: string;
}
export default class EnvAddCmd extends Command {
public static description = stripIndent`
Add env or config variable to fleets, devices or services.
export default class EnvSetCmd extends Command {
public static aliases = ['env add'];
Add an environment or config variable to one or more fleets, devices or
public static description = stripIndent`
Add or update env or config variable to fleets, devices or services.
Add or update an environment or config variable to one or more fleets, devices or
services, as selected by the respective command-line options. Either the
--fleet or the --device option must be provided, and either may be be
used alongside the --service option to define a service-specific variable.
@ -66,15 +68,15 @@ export default class EnvAddCmd extends Command {
`;
public static examples = [
'$ balena env add TERM --fleet MyFleet',
'$ balena env add EDITOR vim -f myorg/myfleet',
'$ balena env add EDITOR vim --fleet MyFleet,MyFleet2',
'$ balena env add EDITOR vim --fleet MyFleet --service MyService',
'$ balena env add EDITOR vim --fleet MyFleet,MyFleet2 --service MyService,MyService2',
'$ balena env add EDITOR vim --device 7cf02a6',
'$ balena env add EDITOR vim --device 7cf02a6,d6f1433',
'$ balena env add EDITOR vim --device 7cf02a6 --service MyService',
'$ balena env add EDITOR vim --device 7cf02a6,d6f1433 --service MyService,MyService2',
'$ balena env set TERM --fleet MyFleet',
'$ balena env set EDITOR vim -f myorg/myfleet',
'$ balena env set EDITOR vim --fleet MyFleet,MyFleet2',
'$ balena env set EDITOR vim --fleet MyFleet --service MyService',
'$ balena env set EDITOR vim --fleet MyFleet,MyFleet2 --service MyService,MyService2',
'$ balena env set EDITOR vim --device 7cf02a6',
'$ balena env set EDITOR vim --device 7cf02a6,d6f1433',
'$ balena env set EDITOR vim --device 7cf02a6 --service MyService',
'$ balena env set EDITOR vim --device 7cf02a6,d6f1433 --service MyService,MyService2',
];
public static args = {
@ -101,7 +103,7 @@ export default class EnvAddCmd extends Command {
};
public async run() {
const { args: params, flags: options } = await this.parse(EnvAddCmd);
const { args: params, flags: options } = await this.parse(EnvSetCmd);
const cmd = this;
if (!options.fleet && !options.device) {

View File

@ -76,7 +76,7 @@ const DEFAULT_OFFLINE_COMPATIBLE = false;
* See: https://oclif.io/docs/hooks
*
* This hook is used to track CLI command signatures (usage analytics).
* A command signature is something like "env add NAME [VALUE]". That's
* A command signature is something like "env set NAME [VALUE]". That's
* literally so: 'NAME' and 'VALUE' are NOT replaced with actual values.
*/

View File

@ -44,7 +44,7 @@ export async function preparseArgs(argv: string[]): Promise<string[]> {
else if (['--help', '-h'].includes(cmdSlice[0])) {
cmdSlice[0] = 'help';
}
// convert e.g. 'balena help env add' to 'balena env add --help'
// convert e.g. 'balena help env set' to 'balena env set --help'
if (
cmdSlice.length > 1 &&
cmdSlice[0] === 'help' &&

View File

@ -48,7 +48,7 @@ interface LoggerAdapter {
class Logger {
public static readonly Level = Level;
// `Logger.command` is currently set in `preparser.ts`
public static command: string; // CLI cmd, e.g. 'push', 'env add', ...
public static command: string; // CLI cmd, e.g. 'push', 'env set', ...
public streams: {
build: NodeJS.ReadWriteStream;

View File

@ -20,7 +20,7 @@ import { expect } from 'chai';
import { BalenaAPIMock } from '../../nock/balena-api-mock';
import { runCommand } from '../../helpers';
describe('balena env add', function () {
describe('balena env set', function () {
let api: BalenaAPIMock;
const fullUUID = 'f63fd7d7812c34c4c14ae023fdff05f5';
@ -42,7 +42,7 @@ describe('balena env add', function () {
.post(/^\/v\d+\/device_environment_variable($|\?)/)
.reply(200, 'OK');
const { out, err } = await runCommand(`env add TEST 1 -d ${fullUUID}`);
const { out, err } = await runCommand(`env set TEST 1 -d ${fullUUID}`);
expect(out.join('')).to.equal('');
expect(err.join('')).to.equal('');
@ -53,7 +53,7 @@ describe('balena env add', function () {
delete process.env.TEST_ENV_VAR_ADD_NO_VALUE_REJECTED;
const { out, err } = await runCommand(
`env add TEST_ENV_VAR_ADD_NO_VALUE_REJECTED -d ${fullUUID}`,
`env set TEST_ENV_VAR_ADD_NO_VALUE_REJECTED -d ${fullUUID}`,
);
expect(out.join('')).to.equal('');
@ -74,7 +74,7 @@ describe('balena env add', function () {
process.env.TEST_ENV_VAR_ADD_NO_VALUE = '4';
const { out, err } = await runCommand(
`env add TEST_ENV_VAR_ADD_NO_VALUE -d ${fullUUID}`,
`env set TEST_ENV_VAR_ADD_NO_VALUE -d ${fullUUID}`,
);
delete process.env.TEST_ENV_VAR_ADD_NO_VALUE;
@ -95,7 +95,7 @@ describe('balena env add', function () {
.reply(200, 'OK');
const { out, err } = await runCommand(
`env add TEST_EMPTY_STRING '' -d ${fullUUID}`,
`env set TEST_EMPTY_STRING '' -d ${fullUUID}`,
);
expect(out.join('')).to.equal('');

View File

@ -65,7 +65,7 @@ ADDITIONAL COMMANDS
device shutdown shutdown a device
device ssh SSH into the host or application container of a device
devices supported list the supported device types (like 'raspberrypi3' or 'intel-nuc')
env add add env or config variable to application(s), device(s) or service(s)
env set add or update env or config variable to application(s), device(s) or service(s)
env list list the environment or config variables of an application, device or service
env rename change the value of a config or env var for an app, device or service
env rm remove a config or env var from an application, device or service

View File

@ -136,9 +136,6 @@
> Warning Entry 'main' not found in %1
%1: node_modules/@oclif/core/package.json
%2: build/commands/devices/supported.js
> Warning Entry 'main' not found in %1
%1: node_modules/@oclif/core/package.json
%2: build/commands/env/add.js
> Warning Entry 'main' not found in %1
%1: node_modules/@oclif/core/package.json
%2: build/commands/env/list.js
@ -148,6 +145,9 @@
> Warning Entry 'main' not found in %1
%1: node_modules/@oclif/core/package.json
%2: build/commands/env/rm.js
> Warning Entry 'main' not found in %1
%1: node_modules/@oclif/core/package.json
%2: build/commands/env/set.js
> Warning Entry 'main' not found in %1
%1: node_modules/@oclif/core/package.json
%2: build/commands/fleet/create.js

View File

@ -136,9 +136,6 @@
> Warning Entry 'main' not found in %1
%1: node_modules/@oclif/core/package.json
%2: build/commands/devices/supported.js
> Warning Entry 'main' not found in %1
%1: node_modules/@oclif/core/package.json
%2: build/commands/env/add.js
> Warning Entry 'main' not found in %1
%1: node_modules/@oclif/core/package.json
%2: build/commands/env/list.js
@ -148,6 +145,9 @@
> Warning Entry 'main' not found in %1
%1: node_modules/@oclif/core/package.json
%2: build/commands/env/rm.js
> Warning Entry 'main' not found in %1
%1: node_modules/@oclif/core/package.json
%2: build/commands/env/set.js
> Warning Entry 'main' not found in %1
%1: node_modules/@oclif/core/package.json
%2: build/commands/fleet/create.js

View File

@ -136,9 +136,6 @@
> Warning Entry 'main' not found in %1
%1: node_modules/@oclif/core/package.json
%2: build/commands/devices/supported.js
> Warning Entry 'main' not found in %1
%1: node_modules/@oclif/core/package.json
%2: build/commands/env/add.js
> Warning Entry 'main' not found in %1
%1: node_modules/@oclif/core/package.json
%2: build/commands/env/list.js
@ -148,6 +145,9 @@
> Warning Entry 'main' not found in %1
%1: node_modules/@oclif/core/package.json
%2: build/commands/env/rm.js
> Warning Entry 'main' not found in %1
%1: node_modules/@oclif/core/package.json
%2: build/commands/env/set.js
> Warning Entry 'main' not found in %1
%1: node_modules/@oclif/core/package.json
%2: build/commands/fleet/create.js

View File

@ -136,9 +136,6 @@
> Warning Entry 'main' not found in %1
%1: node_modules/@oclif/core/package.json
%2: build/commands/devices/supported.js
> Warning Entry 'main' not found in %1
%1: node_modules/@oclif/core/package.json
%2: build/commands/env/add.js
> Warning Entry 'main' not found in %1
%1: node_modules/@oclif/core/package.json
%2: build/commands/env/list.js
@ -148,6 +145,9 @@
> Warning Entry 'main' not found in %1
%1: node_modules/@oclif/core/package.json
%2: build/commands/env/rm.js
> Warning Entry 'main' not found in %1
%1: node_modules/@oclif/core/package.json
%2: build/commands/env/set.js
> Warning Entry 'main' not found in %1
%1: node_modules/@oclif/core/package.json
%2: build/commands/fleet/create.js

View File

@ -136,9 +136,6 @@
> Warning Entry 'main' not found in %1
%1: node_modules\@oclif\core\package.json
%2: build\commands\devices\supported.js
> Warning Entry 'main' not found in %1
%1: node_modules\@oclif\core\package.json
%2: build\commands\env\add.js
> Warning Entry 'main' not found in %1
%1: node_modules\@oclif\core\package.json
%2: build\commands\env\list.js
@ -148,6 +145,9 @@
> Warning Entry 'main' not found in %1
%1: node_modules\@oclif\core\package.json
%2: build\commands\env\rm.js
> Warning Entry 'main' not found in %1
%1: node_modules\@oclif\core\package.json
%2: build\commands\env\set.js
> Warning Entry 'main' not found in %1
%1: node_modules\@oclif\core\package.json
%2: build\commands\fleet\create.js