2019-09-06 13:43:53 +00:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright 2016-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-09-06 13:43:53 +00:00
|
|
|
|
|
|
|
import * as cf from '../../utils/common-flags';
|
2019-12-11 17:47:54 +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-09-06 13:43:53 +00:00
|
|
|
|
|
|
|
type IArg<T> = import('@oclif/parser').args.IArg<T>;
|
|
|
|
|
|
|
|
interface FlagsDef {
|
2019-12-11 17:47:54 +00:00
|
|
|
config: boolean;
|
2019-09-06 13:43:53 +00:00
|
|
|
device: boolean;
|
2019-12-11 17:47:54 +00:00
|
|
|
service: boolean;
|
2019-09-06 13:43:53 +00:00
|
|
|
help: void;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface ArgsDef {
|
|
|
|
id: number;
|
|
|
|
value: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default class EnvRenameCmd extends Command {
|
|
|
|
public static description = stripIndent`
|
2019-12-11 17:47:54 +00:00
|
|
|
Change the value of a config or env var for an app, device or service.
|
2019-09-06 13:43:53 +00:00
|
|
|
|
2019-12-11 17:47:54 +00:00
|
|
|
Change the value of a configuration or environment variable for an application,
|
|
|
|
device or service, as selected by command-line options.
|
2019-09-06 13:43:53 +00:00
|
|
|
|
2019-12-11 17:47:54 +00:00
|
|
|
${ec.rmRenameHelp.split('\n').join('\n\t\t')}
|
2019-09-06 13:43:53 +00:00
|
|
|
`;
|
|
|
|
public static examples = [
|
2019-12-11 17:47:54 +00:00
|
|
|
'$ balena env rename 123123 emacs',
|
|
|
|
'$ balena env rename 234234 emacs --service',
|
|
|
|
'$ balena env rename 345345 emacs --device',
|
|
|
|
'$ balena env rename 456456 emacs --device --service',
|
|
|
|
'$ balena env rename 567567 1 --config',
|
|
|
|
'$ balena env rename 678678 1 --device --config',
|
2019-09-06 13:43:53 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
public static args: Array<IArg<any>> = [
|
|
|
|
{
|
|
|
|
name: 'id',
|
|
|
|
required: true,
|
2019-12-11 17:47:54 +00:00
|
|
|
description: "variable's numeric database ID",
|
2020-06-15 22:53:07 +00:00
|
|
|
parse: (input) => parseAsInteger(input, 'id'),
|
2019-09-06 13:43:53 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'value',
|
|
|
|
required: true,
|
|
|
|
description:
|
2019-12-11 17:47:54 +00:00
|
|
|
"variable value; if omitted, use value from this process' environment",
|
2019-09-06 13:43:53 +00:00
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2020-09-08 11:31:41 +00:00
|
|
|
public static usage = 'env rename <id> <value>';
|
2019-09-06 13:43:53 +00:00
|
|
|
|
|
|
|
public static flags: flags.Input<FlagsDef> = {
|
2019-12-11 17:47:54 +00:00
|
|
|
config: ec.booleanConfig,
|
|
|
|
device: ec.booleanDevice,
|
|
|
|
service: ec.booleanService,
|
2019-09-06 13:43:53 +00:00
|
|
|
help: cf.help,
|
|
|
|
};
|
|
|
|
|
|
|
|
public async run() {
|
2019-12-11 17:47:54 +00:00
|
|
|
const { args: params, flags: opt } = this.parse<FlagsDef, ArgsDef>(
|
2019-09-06 13:43:53 +00:00
|
|
|
EnvRenameCmd,
|
|
|
|
);
|
2019-12-05 15:34:35 +00:00
|
|
|
|
2020-03-24 08:51:19 +00:00
|
|
|
await Command.checkLoggedIn();
|
2019-09-06 13:43:53 +00:00
|
|
|
|
2020-02-27 14:55:30 +00:00
|
|
|
await getBalenaSdk().pine.patch({
|
2019-12-11 17:47:54 +00:00
|
|
|
resource: ec.getVarResourceName(opt.config, opt.device, opt.service),
|
2019-09-06 13:43:53 +00:00
|
|
|
id: params.id,
|
|
|
|
body: {
|
|
|
|
value: params.value,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|