mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-19 05:37:51 +00:00
Merge pull request #2429 from balena-io/os-versions-recommended
os versions, os download: Replace deprecated version fields
This commit is contained in:
commit
3d0f16168a
@ -65,9 +65,11 @@ export default class OsVersionsCmd extends Command {
|
||||
OsVersionsCmd,
|
||||
);
|
||||
|
||||
const { getFormattedOsVersions } = await import('../../utils/cloud');
|
||||
const vs = await getFormattedOsVersions(params.type, !!options.esr);
|
||||
const { formatOsVersion, getOsVersions } = await import(
|
||||
'../../utils/cloud'
|
||||
);
|
||||
const vs = await getOsVersions(params.type, !!options.esr);
|
||||
|
||||
console.log(vs.map((v) => v.formattedVersion).join('\n'));
|
||||
console.log(vs.map((v) => formatOsVersion(v)).join('\n'));
|
||||
}
|
||||
}
|
||||
|
@ -225,53 +225,45 @@ async function selectOSVersionFromMenu(
|
||||
deviceType: string,
|
||||
esr: boolean,
|
||||
): Promise<string> {
|
||||
const vs = await getFormattedOsVersions(deviceType, esr);
|
||||
const vs = await getOsVersions(deviceType, esr);
|
||||
|
||||
const choices = vs.map((v) => ({
|
||||
value: v.rawVersion,
|
||||
name: v.formattedVersion,
|
||||
value: v.raw_version,
|
||||
name: formatOsVersion(v),
|
||||
}));
|
||||
|
||||
return getCliForm().ask({
|
||||
message: 'Select the OS version:',
|
||||
type: 'list',
|
||||
choices,
|
||||
default: (vs.find((v) => v.isRecommended) ?? vs[0])?.rawVersion,
|
||||
default: vs[0]?.raw_version,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the output of sdk.models.hostapp.getAvailableOsVersions(), filtered
|
||||
* regarding ESR or non-ESR versions, and having the `formattedVersion` field
|
||||
* reformatted for compatibility with the pre-existing output format of the
|
||||
* `os versions` and `os download` commands.
|
||||
* Return the output of sdk.models.os.getAvailableOsVersions(), resolving
|
||||
* device type aliases and filtering with regard to ESR versions.
|
||||
*/
|
||||
export async function getFormattedOsVersions(
|
||||
export async function getOsVersions(
|
||||
deviceType: string,
|
||||
esr: boolean,
|
||||
): Promise<SDK.OsVersion[]> {
|
||||
const sdk = getBalenaSdk();
|
||||
let slug = deviceType;
|
||||
let versionsByDT: SDK.OsVersionsByDeviceType =
|
||||
await sdk.models.os.getAvailableOsVersions([slug]);
|
||||
let versions: SDK.OsVersion[] = await sdk.models.os.getAvailableOsVersions(
|
||||
slug,
|
||||
);
|
||||
// if slug is an alias, fetch the real slug
|
||||
if (!versionsByDT[slug]?.length) {
|
||||
if (!versions.length) {
|
||||
// unaliasDeviceType() produces a nice error msg if slug is invalid
|
||||
slug = await unaliasDeviceType(sdk, slug);
|
||||
if (slug !== deviceType) {
|
||||
versionsByDT = await sdk.models.os.getAvailableOsVersions([slug]);
|
||||
versions = await sdk.models.os.getAvailableOsVersions(slug);
|
||||
}
|
||||
}
|
||||
const versions: SDK.OsVersion[] = (versionsByDT[slug] || [])
|
||||
.filter((v: SDK.OsVersion) => v.osType === (esr ? 'esr' : 'default'))
|
||||
.map((v: SDK.OsVersion) => {
|
||||
const i = v.formattedVersion.indexOf(' ');
|
||||
v.formattedVersion =
|
||||
i < 0
|
||||
? `v${v.rawVersion}`
|
||||
: `v${v.rawVersion}${v.formattedVersion.substring(i)}`;
|
||||
return v;
|
||||
});
|
||||
versions = versions.filter(
|
||||
(v: SDK.OsVersion) => v.osType === (esr ? 'esr' : 'default'),
|
||||
);
|
||||
if (!versions.length) {
|
||||
const vType = esr ? 'ESR versions' : 'versions';
|
||||
throw new ExpectedError(
|
||||
@ -280,3 +272,9 @@ export async function getFormattedOsVersions(
|
||||
}
|
||||
return versions;
|
||||
}
|
||||
|
||||
export function formatOsVersion(osVersion: SDK.OsVersion): string {
|
||||
return osVersion.line
|
||||
? `v${osVersion.raw_version} (${osVersion.line})`
|
||||
: `v${osVersion.raw_version}`;
|
||||
}
|
||||
|
6
npm-shrinkwrap.json
generated
6
npm-shrinkwrap.json
generated
@ -3955,9 +3955,9 @@
|
||||
}
|
||||
},
|
||||
"balena-sdk": {
|
||||
"version": "16.8.0",
|
||||
"resolved": "https://registry.npmjs.org/balena-sdk/-/balena-sdk-16.8.0.tgz",
|
||||
"integrity": "sha512-kch7hhB9PksFsyVOAFyylsQMlv976V11DOwhb41w2JykVKjR9KSNFBfy1wYwYY1Wcp8PWXvj9WxtB0Sd/SW9bQ==",
|
||||
"version": "16.8.1",
|
||||
"resolved": "https://registry.npmjs.org/balena-sdk/-/balena-sdk-16.8.1.tgz",
|
||||
"integrity": "sha512-fSYo/aOGVRj0PhIRla8GRuLhyIecvri8kFFbDu0faUgDDUHfidyfIIUzuTggOc7XKr20WazvjfI4M2uVAqMKww==",
|
||||
"requires": {
|
||||
"@balena/es-version": "^1.0.0",
|
||||
"@types/json-schema": "^7.0.9",
|
||||
|
@ -208,7 +208,7 @@
|
||||
"balena-image-manager": "^7.1.1",
|
||||
"balena-preload": "^11.0.0",
|
||||
"balena-release": "^3.2.0",
|
||||
"balena-sdk": "^16.8.0",
|
||||
"balena-sdk": "^16.8.1",
|
||||
"balena-semver": "^2.3.0",
|
||||
"balena-settings-client": "^4.0.7",
|
||||
"balena-settings-storage": "^7.0.0",
|
||||
|
Loading…
Reference in New Issue
Block a user