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:
Scott Lowe 2019-11-07 11:02:44 +01:00
parent 45ce442cf2
commit afd97bd304
4 changed files with 84 additions and 29 deletions

View File

@ -100,7 +100,6 @@ If you come across any problems or would like to get in touch:
- [devices](#devices)
- [device &#60;uuid&#62;](#device-uuid)
- [devices supported](#devices-supported)
- [device register &#60;application&#62;](#device-register-application)
- [device rm &#60;uuid&#62;](#device-rm-uuid)
- [device identify &#60;uuid&#62;](#device-identify-uuid)
@ -114,6 +113,7 @@ If you come across any problems or would like to get in touch:
- [device move &#60;uuid&#62;](#device-move-uuid)
- [device init](#device-init)
- [device os-update &#60;uuid&#62;](#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 &#60;application&#62;
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

View File

@ -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

View File

@ -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 {

View 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);
});
});