mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-02-20 01:16:43 +00:00
v12 preparations: Add feature switch for 'devices supported' default columns
Connects-to: #1770 Change-type: patch
This commit is contained in:
parent
2fc0728a09
commit
a38b41f339
@ -23,6 +23,7 @@ import Command from '../../command';
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, getVisuals } from '../../utils/lazy';
|
||||
import { CommandHelp } from '../../utils/oclif-utils';
|
||||
import { isV12 } from '../../utils/version';
|
||||
|
||||
interface FlagsDef {
|
||||
discontinued: boolean;
|
||||
@ -77,28 +78,30 @@ export default class DevicesSupportedCmd extends Command {
|
||||
|
||||
public async run() {
|
||||
const { flags: options } = this.parse<FlagsDef, {}>(DevicesSupportedCmd);
|
||||
let deviceTypes: Array<Partial<
|
||||
SDK.DeviceType
|
||||
>> = await getBalenaSdk().models.config.getDeviceTypes();
|
||||
if (!options.discontinued) {
|
||||
deviceTypes = deviceTypes.filter(dt => dt.state !== 'DISCONTINUED');
|
||||
}
|
||||
const fields = ['slug', 'name'];
|
||||
if (options.verbose) {
|
||||
fields.splice(1, 0, 'aliases', 'arch', 'state');
|
||||
deviceTypes = deviceTypes.map(d => {
|
||||
let deviceTypes: Array<Partial<SDK.DeviceType>> = await getBalenaSdk()
|
||||
.models.config.getDeviceTypes()
|
||||
.map(d => {
|
||||
if (d.aliases && d.aliases.length) {
|
||||
// remove aliases that are equal to the slug
|
||||
d.aliases = d.aliases.filter((alias: string) => alias !== d.slug);
|
||||
if (!options.json) {
|
||||
// stringify the aliases array with commas and spaces
|
||||
d.aliases = [d.aliases.join(', ')];
|
||||
}
|
||||
} else {
|
||||
// ensure it is always an array (for the benefit of JSON output)
|
||||
d.aliases = [];
|
||||
}
|
||||
return d;
|
||||
});
|
||||
if (!options.discontinued) {
|
||||
deviceTypes = deviceTypes.filter(dt => dt.state !== 'DISCONTINUED');
|
||||
}
|
||||
const fields = options.verbose
|
||||
? ['slug', 'aliases', 'arch', 'state', 'name']
|
||||
: isV12()
|
||||
? ['slug', 'aliases', 'arch', 'name']
|
||||
: ['slug', 'name'];
|
||||
deviceTypes = _.sortBy(
|
||||
deviceTypes.map(d => _.pick(d, fields) as Partial<SDK.DeviceType>),
|
||||
fields,
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
import { expect } from 'chai';
|
||||
|
||||
import { isV12 } from '../../../build/utils/version';
|
||||
import { BalenaAPIMock } from '../../balena-api-mock';
|
||||
import { cleanOutput, runCommand } from '../../helpers';
|
||||
|
||||
@ -52,7 +53,9 @@ describe('balena devices supported', function() {
|
||||
|
||||
const lines = cleanOutput(out);
|
||||
|
||||
expect(lines[0].replace(/ +/g, ' ')).to.equal('SLUG NAME');
|
||||
expect(lines[0].replace(/ +/g, ' ')).to.equal(
|
||||
isV12() ? 'SLUG ALIASES ARCH NAME' : 'SLUG NAME',
|
||||
);
|
||||
expect(lines).to.have.lengthOf.at.least(2);
|
||||
|
||||
// Discontinued devices should be filtered out from results
|
||||
|
Loading…
x
Reference in New Issue
Block a user