mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-02-21 09:51:58 +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 * as cf from '../../utils/common-flags';
|
||||||
import { getBalenaSdk, getVisuals } from '../../utils/lazy';
|
import { getBalenaSdk, getVisuals } from '../../utils/lazy';
|
||||||
import { CommandHelp } from '../../utils/oclif-utils';
|
import { CommandHelp } from '../../utils/oclif-utils';
|
||||||
|
import { isV12 } from '../../utils/version';
|
||||||
|
|
||||||
interface FlagsDef {
|
interface FlagsDef {
|
||||||
discontinued: boolean;
|
discontinued: boolean;
|
||||||
@ -77,28 +78,30 @@ export default class DevicesSupportedCmd extends Command {
|
|||||||
|
|
||||||
public async run() {
|
public async run() {
|
||||||
const { flags: options } = this.parse<FlagsDef, {}>(DevicesSupportedCmd);
|
const { flags: options } = this.parse<FlagsDef, {}>(DevicesSupportedCmd);
|
||||||
let deviceTypes: Array<Partial<
|
let deviceTypes: Array<Partial<SDK.DeviceType>> = await getBalenaSdk()
|
||||||
SDK.DeviceType
|
.models.config.getDeviceTypes()
|
||||||
>> = await getBalenaSdk().models.config.getDeviceTypes();
|
.map(d => {
|
||||||
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 => {
|
|
||||||
if (d.aliases && d.aliases.length) {
|
if (d.aliases && d.aliases.length) {
|
||||||
|
// remove aliases that are equal to the slug
|
||||||
d.aliases = d.aliases.filter((alias: string) => alias !== d.slug);
|
d.aliases = d.aliases.filter((alias: string) => alias !== d.slug);
|
||||||
if (!options.json) {
|
if (!options.json) {
|
||||||
// stringify the aliases array with commas and spaces
|
// stringify the aliases array with commas and spaces
|
||||||
d.aliases = [d.aliases.join(', ')];
|
d.aliases = [d.aliases.join(', ')];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// ensure it is always an array (for the benefit of JSON output)
|
||||||
d.aliases = [];
|
d.aliases = [];
|
||||||
}
|
}
|
||||||
return d;
|
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 = _.sortBy(
|
||||||
deviceTypes.map(d => _.pick(d, fields) as Partial<SDK.DeviceType>),
|
deviceTypes.map(d => _.pick(d, fields) as Partial<SDK.DeviceType>),
|
||||||
fields,
|
fields,
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
|
|
||||||
|
import { isV12 } from '../../../build/utils/version';
|
||||||
import { BalenaAPIMock } from '../../balena-api-mock';
|
import { BalenaAPIMock } from '../../balena-api-mock';
|
||||||
import { cleanOutput, runCommand } from '../../helpers';
|
import { cleanOutput, runCommand } from '../../helpers';
|
||||||
|
|
||||||
@ -52,7 +53,9 @@ describe('balena devices supported', function() {
|
|||||||
|
|
||||||
const lines = cleanOutput(out);
|
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);
|
expect(lines).to.have.lengthOf.at.least(2);
|
||||||
|
|
||||||
// Discontinued devices should be filtered out from results
|
// Discontinued devices should be filtered out from results
|
||||||
|
Loading…
x
Reference in New Issue
Block a user