balena-cli
Version:
The official balena Command Line Interface
99 lines • 3.41 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.commitOrIdArg = void 0;
const core_1 = require("@oclif/core");
const lazy_1 = require("../../utils/lazy");
const yaml = require("js-yaml");
const validation_1 = require("../../utils/validation");
exports.commitOrIdArg = core_1.Args.custom({
parse: validation_1.tryAsInteger,
});
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 {
return 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',
'raw_version',
'is_final',
'build_log',
'start_timestamp',
'end_timestamp',
];
const explicitReadFields = ['raw_version', 'build_log'];
const fieldNameMap = {
raw_version: 'version',
};
const release = await balena.models.release.get(commitOrId, {
...(!options.json && { $select: fields }),
$expand: {
release_tag: {
$select: ['tag_key', 'value'],
},
},
});
if (options.json) {
const releaseWithExplicitReadFields = await balena.models.release.get(release.id, {
$select: ['id', ...explicitReadFields],
});
Object.assign(release, releaseWithExplicitReadFields);
return JSON.stringify(release, null, 4);
}
const tagStr = release
.release_tag.map((t) => `${t.tag_key}=${t.value}`)
.join('\n');
const values = Object.fromEntries(Object.entries(release).map(([f, val]) => {
var _a;
return [
(_a = fieldNameMap[f]) !== null && _a !== void 0 ? _a : f,
val !== null && val !== void 0 ? val : 'N/a',
];
}));
values['tags'] = tagStr;
console.log((0, lazy_1.getVisuals)().table.vertical(values, [
...fields.map((f) => { var _a; return (_a = fieldNameMap[f]) !== null && _a !== void 0 ? _a : f; }),
'tags',
]));
}
}
ReleaseCmd.enableJsonFlag = true;
ReleaseCmd.description = (0, lazy_1.stripIndent) `
Get info for a release.
`;
ReleaseCmd.examples = [
'$ balena release a777f7345fe3d655c1c981aa642e5555',
'$ balena release 1234567',
];
ReleaseCmd.flags = {
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