balena-cli
Version:
The official balena Command Line Interface
90 lines (84 loc) • 3.5 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@oclif/core");
const cf = require("../../utils/common-flags");
const lazy_1 = require("../../utils/lazy");
const messages_1 = require("../../utils/messages");
class TagSetCmd extends core_1.Command {
async run() {
var _a;
const { args: params, flags: options } = await this.parse(TagSetCmd);
const balena = (0, lazy_1.getBalenaSdk)();
if (!options.fleet && !options.device && !options.release) {
const { ExpectedError } = await Promise.resolve().then(() => require('../../errors'));
throw new ExpectedError(TagSetCmd.missingResourceMessage);
}
(_a = params.value) !== null && _a !== void 0 ? _a : (params.value = '');
if (options.fleet) {
const { getFleetSlug } = await Promise.resolve().then(() => require('../../utils/sdk'));
return balena.models.application.tags.set(await getFleetSlug(balena, options.fleet), params.tagKey, params.value);
}
if (options.device) {
return balena.models.device.tags.set(options.device, params.tagKey, params.value);
}
if (options.release) {
const { disambiguateReleaseParam } = await Promise.resolve().then(() => require('../../utils/normalization'));
const releaseParam = await disambiguateReleaseParam(balena, options.release);
return balena.models.release.tags.set(releaseParam, params.tagKey, params.value);
}
}
}
TagSetCmd.description = (0, lazy_1.stripIndent) `
Set a tag on a fleet, device or release.
Set a tag on a fleet, device or release.
You can optionally provide a value to be associated with the created
tag, as an extra argument after the tag key. If a value isn't
provided, a tag with an empty value is created.
${messages_1.applicationIdInfo.split('\n').join('\n\t\t')}
`;
TagSetCmd.examples = [
'$ balena tag set mySimpleTag --fleet MyFleet',
'$ balena tag set mySimpleTag -f myorg/myfleet',
'$ balena tag set myCompositeTag myTagValue --fleet MyFleet',
'$ balena tag set myCompositeTag myTagValue --device 7cf02a6',
'$ balena tag set myCompositeTag "my tag value with whitespaces" --device 7cf02a6',
'$ balena tag set myCompositeTag myTagValue --release 1234',
'$ balena tag set myCompositeTag --release 1234',
'$ balena tag set myCompositeTag --release b376b0e544e9429483b656490e5b9443b4349bd6',
];
TagSetCmd.args = {
tagKey: core_1.Args.string({
description: 'the key string of the tag',
required: true,
}),
value: core_1.Args.string({
description: 'the optional value associated with the tag',
required: false,
}),
};
TagSetCmd.strict = false;
TagSetCmd.flags = {
fleet: {
...cf.fleet,
exclusive: ['device', 'release'],
},
device: {
...cf.device,
exclusive: ['fleet', 'release'],
},
release: {
...cf.release,
exclusive: ['fleet', 'device'],
},
};
TagSetCmd.authenticated = true;
TagSetCmd.missingResourceMessage = (0, lazy_1.stripIndent) `
To set a resource tag, you must provide exactly one of:
* A fleet, with --fleet <fleetNameOrSlug>
* A device, with --device <UUID>
* A release, with --release <ID or commit>
See the help page for examples:
$ balena help tag set
`;
exports.default = TagSetCmd;
//# sourceMappingURL=set.js.map
;