mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-01-18 10:46:34 +00:00
Hide discontinued device types in balena devices supported
.
Add tests for action. Convert action to TypeScript. Connects-to: #1485 Change-type: patch Signed-off-by: Scott Lowe <scott@balena.io>
This commit is contained in:
parent
45ce442cf2
commit
afd97bd304
@ -100,7 +100,6 @@ If you come across any problems or would like to get in touch:
|
||||
|
||||
- [devices](#devices)
|
||||
- [device <uuid>](#device-uuid)
|
||||
- [devices supported](#devices-supported)
|
||||
- [device register <application>](#device-register-application)
|
||||
- [device rm <uuid>](#device-rm-uuid)
|
||||
- [device identify <uuid>](#device-identify-uuid)
|
||||
@ -114,6 +113,7 @@ If you come across any problems or would like to get in touch:
|
||||
- [device move <uuid>](#device-move-uuid)
|
||||
- [device init](#device-init)
|
||||
- [device os-update <uuid>](#device-os-update-uuid)
|
||||
- [devices supported](#devices-supported)
|
||||
|
||||
- Environment Variables
|
||||
|
||||
@ -374,14 +374,6 @@ Examples:
|
||||
|
||||
$ balena device 7cf02a6
|
||||
|
||||
## devices supported
|
||||
|
||||
Use this command to get the list of all supported devices
|
||||
|
||||
Examples:
|
||||
|
||||
$ balena devices supported
|
||||
|
||||
## device register <application>
|
||||
|
||||
Use this command to register a device to an application.
|
||||
@ -577,6 +569,14 @@ a balenaOS version
|
||||
|
||||
confirm non interactively
|
||||
|
||||
## devices supported
|
||||
|
||||
Use this command to get the list of all supported devices.
|
||||
|
||||
Examples:
|
||||
|
||||
$ balena devices supported
|
||||
|
||||
# Environment Variables
|
||||
|
||||
## envs
|
||||
|
@ -115,25 +115,6 @@ exports.info =
|
||||
]
|
||||
.nodeify(done)
|
||||
|
||||
exports.supported =
|
||||
signature: 'devices supported'
|
||||
description: 'list all supported devices'
|
||||
help: '''
|
||||
Use this command to get the list of all supported devices
|
||||
|
||||
Examples:
|
||||
|
||||
$ balena devices supported
|
||||
'''
|
||||
action: (params, options, done) ->
|
||||
balena = require('balena-sdk').fromSharedOptions()
|
||||
visuals = require('resin-cli-visuals')
|
||||
|
||||
balena.models.config.getDeviceTypes().then (deviceTypes) ->
|
||||
fields = ['slug', 'name']
|
||||
console.log visuals.table.horizontal(_.sortBy(deviceTypes, fields), fields)
|
||||
.nodeify(done)
|
||||
|
||||
exports.register =
|
||||
signature: 'device register <application>'
|
||||
description: 'register a device'
|
||||
@ -465,4 +446,6 @@ exports.init =
|
||||
|
||||
.nodeify(done)
|
||||
|
||||
exports.osUpdate = require('./device_ts').osUpdate
|
||||
tsActions = require('./device_ts')
|
||||
exports.osUpdate = tsActions.osUpdate
|
||||
exports.supported = tsActions.supported
|
||||
|
@ -19,6 +19,31 @@ import { stripIndent } from 'common-tags';
|
||||
import { normalizeUuidProp } from '../utils/normalization';
|
||||
import * as commandOptions from './command-options';
|
||||
|
||||
export const supported: CommandDefinition<{}, {}> = {
|
||||
signature: 'devices supported',
|
||||
description: 'list all supported devices',
|
||||
help: stripIndent`
|
||||
Use this command to get the list of all supported devices.
|
||||
|
||||
Examples:
|
||||
|
||||
$ balena devices supported
|
||||
`,
|
||||
async action(_params, _options) {
|
||||
const sdk = (await import('balena-sdk')).fromSharedOptions();
|
||||
const visuals = await import('resin-cli-visuals');
|
||||
const _ = await import('lodash');
|
||||
|
||||
let deviceTypes = await sdk.models.config.getDeviceTypes();
|
||||
const fields = ['slug', 'name'];
|
||||
deviceTypes = _.sortBy(deviceTypes, fields).filter(
|
||||
dt => dt.state !== 'DISCONTINUED',
|
||||
);
|
||||
const output = await visuals.table.horizontal(deviceTypes, fields);
|
||||
console.log(output);
|
||||
},
|
||||
};
|
||||
|
||||
// tslint:disable-next-line:no-namespace
|
||||
namespace OsUpdate {
|
||||
export interface Args {
|
||||
|
47
tests/commands/device/supported.spec.ts
Normal file
47
tests/commands/device/supported.spec.ts
Normal file
@ -0,0 +1,47 @@
|
||||
import { expect } from 'chai';
|
||||
import * as _ from 'lodash';
|
||||
import { runCommand } from '../../helpers';
|
||||
|
||||
const HELP = `
|
||||
Usage: devices supported
|
||||
|
||||
Use this command to get the list of all supported devices.
|
||||
|
||||
Examples:
|
||||
|
||||
\t$ balena devices supported
|
||||
`;
|
||||
|
||||
const cleanOutput = (output: string[] | string) => {
|
||||
return _(_.castArray(output))
|
||||
.map(log => {
|
||||
return log.split('\n').map(line => {
|
||||
return line.trim();
|
||||
});
|
||||
})
|
||||
.flatten()
|
||||
.compact()
|
||||
.value();
|
||||
};
|
||||
|
||||
describe('balena devices supported', function() {
|
||||
it('should list currently supported devices', async () => {
|
||||
const { out, err } = await runCommand('devices supported');
|
||||
|
||||
const lines = cleanOutput(out);
|
||||
|
||||
expect(lines[0].replace(/ +/g, ' ')).to.equal('SLUG NAME');
|
||||
expect(lines).to.have.lengthOf.at.least(2);
|
||||
expect(lines.some(l => l.includes('DISCONTINUED'))).to.be.false;
|
||||
|
||||
expect(err).to.have.lengthOf(0);
|
||||
});
|
||||
|
||||
it('should print help text with the -h flag', async () => {
|
||||
const { out, err } = await runCommand('devices supported -h');
|
||||
|
||||
expect(cleanOutput(out)).to.deep.equal(cleanOutput([HELP]));
|
||||
|
||||
expect(err).to.have.lengthOf(0);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user