os versions: Add the --include-draft option

Change-type: minor
This commit is contained in:
Thodoris Greasidis 2024-01-22 18:41:49 +02:00
parent cdada0aec8
commit 1ba8db1459
3 changed files with 38 additions and 6 deletions

View File

@ -2728,6 +2728,10 @@ device type
select balenaOS ESR versions
#### --include-draft
include pre-release balenaOS versions
## os download <type>
Download an unconfigured OS image for the specified device type.

View File

@ -48,15 +48,33 @@ export default class OsVersionsCmd extends Command {
description: 'select balenaOS ESR versions',
default: false,
}),
'include-draft': Flags.boolean({
description: 'include pre-release balenaOS versions',
default: false,
}),
};
public async run() {
const { args: params, flags: options } = await this.parse(OsVersionsCmd);
if (options['include-draft']) {
const { warnify } = await import('../../utils/messages');
console.error(
warnify(stripIndent`
Using pre-release balenaOS versions is only supported for OS updates
and not for OS image downloads.
`),
);
}
const { formatOsVersion, getOsVersions } = await import(
'../../utils/cloud'
);
const vs = await getOsVersions(params.type, !!options.esr);
const vs = await getOsVersions(
params.type,
!!options.esr,
options['include-draft'],
);
console.log(vs.map((v) => formatOsVersion(v)).join('\n'));
}

View File

@ -200,7 +200,11 @@ async function resolveOSVersion(
version: string,
): Promise<string> {
if (['menu', 'menu-esr'].includes(version)) {
return await selectOSVersionFromMenu(deviceType, version === 'menu-esr');
return await selectOSVersionFromMenu(
deviceType,
version === 'menu-esr',
false,
);
}
const { normalizeOsVersion } = await import('./normalization');
version = normalizeOsVersion(version);
@ -210,8 +214,9 @@ async function resolveOSVersion(
async function selectOSVersionFromMenu(
deviceType: string,
esr: boolean,
includeDraft: boolean,
): Promise<string> {
const vs = await getOsVersions(deviceType, esr);
const vs = await getOsVersions(deviceType, esr, includeDraft);
const choices = vs.map((v) => ({
value: v.raw_version,
@ -233,17 +238,22 @@ async function selectOSVersionFromMenu(
export async function getOsVersions(
deviceType: string,
esr: boolean,
includeDraft: boolean,
): Promise<SDK.OsVersion[]> {
const sdk = getBalenaSdk();
let slug = deviceType;
let versions: SDK.OsVersion[] =
await sdk.models.os.getAvailableOsVersions(slug);
let versions: SDK.OsVersion[] = await sdk.models.os.getAvailableOsVersions(
slug,
{ includeDraft },
);
// if slug is an alias, fetch the real slug
if (!versions.length) {
// unalias device type slug
slug = (await sdk.models.deviceType.get(slug, { $select: 'slug' })).slug;
if (slug !== deviceType) {
versions = await sdk.models.os.getAvailableOsVersions(slug);
versions = await sdk.models.os.getAvailableOsVersions(slug, {
includeDraft,
});
}
}
versions = versions.filter(