2019-08-07 09:28:15 +00:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright 2019 Balena Ltd.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2020-03-19 08:45:57 +00:00
|
|
|
import { flags } from '@oclif/command';
|
|
|
|
import Command from '../../command';
|
2019-08-07 09:28:15 +00:00
|
|
|
|
2019-12-11 00:43:55 +00:00
|
|
|
import * as ec from '../../utils/env-common';
|
2020-05-04 14:57:23 +00:00
|
|
|
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
|
2020-04-17 13:19:33 +00:00
|
|
|
import { parseAsInteger } from '../../utils/validation';
|
2019-08-07 09:28:15 +00:00
|
|
|
|
2019-12-11 00:43:55 +00:00
|
|
|
type IArg<T> = import('@oclif/parser').args.IArg<T>;
|
|
|
|
|
2019-08-07 09:28:15 +00:00
|
|
|
interface FlagsDef {
|
2019-10-02 18:23:50 +00:00
|
|
|
config: boolean;
|
2019-08-07 09:28:15 +00:00
|
|
|
device: boolean;
|
2019-12-11 00:43:55 +00:00
|
|
|
service: boolean;
|
2019-08-07 09:28:15 +00:00
|
|
|
yes: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface ArgsDef {
|
|
|
|
id: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default class EnvRmCmd extends Command {
|
|
|
|
public static description = stripIndent`
|
2019-12-11 00:43:55 +00:00
|
|
|
Remove a config or env var from an application, device or service.
|
2019-08-07 09:28:15 +00:00
|
|
|
|
2019-12-11 00:43:55 +00:00
|
|
|
Remove a configuration or environment variable from an application, device
|
|
|
|
or service, as selected by command-line options.
|
2019-08-07 09:28:15 +00:00
|
|
|
|
2019-12-11 00:43:55 +00:00
|
|
|
${ec.rmRenameHelp.split('\n').join('\n\t\t')}
|
2019-08-07 09:28:15 +00:00
|
|
|
|
2019-12-11 00:43:55 +00:00
|
|
|
Interactive confirmation is normally asked before the variable is deleted.
|
2020-01-03 18:37:55 +00:00
|
|
|
The --yes option disables this behavior.
|
2019-08-07 09:28:15 +00:00
|
|
|
`;
|
|
|
|
public static examples = [
|
2019-12-11 00:43:55 +00:00
|
|
|
'$ balena env rm 123123',
|
|
|
|
'$ balena env rm 234234 --yes',
|
|
|
|
'$ balena env rm 345345 --config',
|
|
|
|
'$ balena env rm 456456 --service',
|
|
|
|
'$ balena env rm 567567 --device',
|
|
|
|
'$ balena env rm 678678 --device --config',
|
|
|
|
'$ balena env rm 789789 --device --service --yes',
|
2019-08-07 09:28:15 +00:00
|
|
|
];
|
|
|
|
|
2019-12-11 00:43:55 +00:00
|
|
|
public static args: Array<IArg<any>> = [
|
2019-08-07 09:28:15 +00:00
|
|
|
{
|
|
|
|
name: 'id',
|
|
|
|
required: true,
|
2019-12-11 00:43:55 +00:00
|
|
|
description: "variable's numeric database ID",
|
2020-06-15 22:53:07 +00:00
|
|
|
parse: (input) => parseAsInteger(input, 'id'),
|
2019-08-07 09:28:15 +00:00
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2020-09-04 14:34:34 +00:00
|
|
|
public static usage = 'env rm <id>';
|
2019-08-07 09:28:15 +00:00
|
|
|
|
|
|
|
public static flags: flags.Input<FlagsDef> = {
|
2019-12-11 00:43:55 +00:00
|
|
|
config: ec.booleanConfig,
|
|
|
|
device: ec.booleanDevice,
|
|
|
|
service: ec.booleanService,
|
2019-08-07 09:28:15 +00:00
|
|
|
yes: flags.boolean({
|
|
|
|
char: 'y',
|
2019-12-11 00:43:55 +00:00
|
|
|
description:
|
|
|
|
'do not prompt for confirmation before deleting the variable',
|
2019-08-07 09:28:15 +00:00
|
|
|
default: false,
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
|
|
|
|
public async run() {
|
2019-12-11 00:43:55 +00:00
|
|
|
const { args: params, flags: opt } = this.parse<FlagsDef, ArgsDef>(
|
2019-08-07 09:28:15 +00:00
|
|
|
EnvRmCmd,
|
|
|
|
);
|
2019-12-05 15:34:35 +00:00
|
|
|
|
2020-03-24 08:51:19 +00:00
|
|
|
await Command.checkLoggedIn();
|
2019-08-07 09:28:15 +00:00
|
|
|
|
2020-07-08 17:21:37 +00:00
|
|
|
const { confirm } = await import('../../utils/patterns');
|
2019-12-05 15:34:35 +00:00
|
|
|
await confirm(
|
2019-12-11 00:43:55 +00:00
|
|
|
opt.yes || false,
|
2019-09-30 19:56:57 +00:00
|
|
|
'Are you sure you want to delete the environment variable?',
|
|
|
|
undefined,
|
|
|
|
true,
|
|
|
|
);
|
2019-09-06 13:42:54 +00:00
|
|
|
|
2020-07-08 17:21:37 +00:00
|
|
|
const balena = getBalenaSdk();
|
2019-09-06 13:42:54 +00:00
|
|
|
await balena.pine.delete({
|
2019-12-11 00:43:55 +00:00
|
|
|
resource: ec.getVarResourceName(opt.config, opt.device, opt.service),
|
2019-09-06 13:42:54 +00:00
|
|
|
id: params.id,
|
|
|
|
});
|
2019-08-07 09:28:15 +00:00
|
|
|
}
|
|
|
|
}
|