balena-cli
Version:
The official balena Command Line Interface
90 lines (89 loc) • 3.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.commitOrIdArg = void 0;
const core_1 = require("@oclif/core");
const cf = require("../../utils/common-flags");
const lazy_1 = require("../../utils/lazy");
const yaml = require("js-yaml");
const validation_1 = require("../../utils/validation");
const messages_1 = require("../../utils/messages");
exports.commitOrIdArg = core_1.Args.custom({
parse: async (commitOrId) => (0, validation_1.tryAsInteger)(commitOrId),
});
class ReleaseCmd extends core_1.Command {
async run() {
const { args: params, flags: options } = await this.parse(ReleaseCmd);
const balena = (0, lazy_1.getBalenaSdk)();
if (options.composition) {
await this.showComposition(params.commitOrId, balena);
}
else {
await this.showReleaseInfo(params.commitOrId, balena, options);
}
}
async showComposition(commitOrId, balena) {
const release = await balena.models.release.get(commitOrId, {
$select: 'composition',
});
console.log(yaml.dump(release.composition));
}
async showReleaseInfo(commitOrId, balena, options) {
const fields = [
'id',
'commit',
'created_at',
'status',
'semver',
'is_final',
'build_log',
'start_timestamp',
'end_timestamp',
];
const release = await balena.models.release.get(commitOrId, {
...(!options.json && { $select: fields }),
$expand: {
release_tag: {
$select: ['tag_key', 'value'],
},
},
});
if (options.json) {
console.log(JSON.stringify(release, null, 4));
}
else {
const tagStr = release
.release_tag.map((t) => `${t.tag_key}=${t.value}`)
.join('\n');
const _ = await Promise.resolve().then(() => require('lodash'));
const values = _.mapValues(release, (val) => val !== null && val !== void 0 ? val : 'N/a');
values['tags'] = tagStr;
console.log((0, lazy_1.getVisuals)().table.vertical(values, [...fields, 'tags']));
}
}
}
ReleaseCmd.description = (0, lazy_1.stripIndent) `
Get info for a release.
${messages_1.jsonInfo.split('\n').join('\n\t\t')}
`;
ReleaseCmd.examples = [
'$ balena release a777f7345fe3d655c1c981aa642e5555',
'$ balena release 1234567',
'$ balena release d3f3151f5ad25ca6b070aa4d08296aca --json',
];
ReleaseCmd.flags = {
json: cf.json,
composition: core_1.Flags.boolean({
default: false,
char: 'c',
description: 'Return the release composition',
}),
};
ReleaseCmd.args = {
commitOrId: (0, exports.commitOrIdArg)({
description: 'the commit or ID of the release to get information',
required: true,
}),
};
ReleaseCmd.authenticated = true;
exports.default = ReleaseCmd;
//# sourceMappingURL=index.js.map