Merge pull request #1501 from balena-io/1485-filter-discontinued-devices

Hide discontinued device types in `balena devices supported`, `balena app create`.
This commit is contained in:
srlowe 2019-11-15 13:39:41 +01:00 committed by GitHub
commit 0462574d8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 173 additions and 100 deletions

View File

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

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

@ -130,7 +130,9 @@ export function selectDeviceType() {
return getBalenaSdk()
.models.config.getDeviceTypes()
.then(deviceTypes => {
deviceTypes = _.sortBy(deviceTypes, 'name');
deviceTypes = _.sortBy(deviceTypes, 'name').filter(
dt => dt.state !== 'DISCONTINUED',
);
return getForm().ask({
message: 'Device Type',
type: 'list',

View File

@ -1,5 +1,5 @@
import * as Promise from 'bluebird';
import * as chai from 'chai';
import { expect } from 'chai';
import rewire = require('rewire');
import * as sinon from 'sinon';
import * as url from 'url';
@ -14,7 +14,7 @@ describe('Utils:', function() {
utils
.getDashboardLoginURL('https://127.0.0.1:3000/callback')
.then((loginUrl: string) =>
chai.expect(() => url.parse(loginUrl)).to.not.throw(Error),
expect(() => url.parse(loginUrl)).to.not.throw(Error),
));
it('should eventually contain an https protocol', () =>
@ -23,7 +23,7 @@ describe('Utils:', function() {
loginUrl: utils.getDashboardLoginURL('https://127.0.0.1:3000/callback'),
}).then(function({ dashboardUrl, loginUrl }) {
const { protocol } = url.parse(loginUrl);
return chai.expect(protocol).to.equal(url.parse(dashboardUrl).protocol);
return expect(protocol).to.equal(url.parse(dashboardUrl).protocol);
}));
it('should correctly escape a callback url without a path', () =>
@ -32,7 +32,7 @@ describe('Utils:', function() {
loginUrl: utils.getDashboardLoginURL('http://127.0.0.1:3000'),
}).then(function({ dashboardUrl, loginUrl }) {
const expectedUrl = `${dashboardUrl}/login/cli/http%253A%252F%252F127.0.0.1%253A3000`;
return chai.expect(loginUrl).to.equal(expectedUrl);
return expect(loginUrl).to.equal(expectedUrl);
}));
return it('should correctly escape a callback url with a path', () =>
@ -41,29 +41,29 @@ describe('Utils:', function() {
loginUrl: utils.getDashboardLoginURL('http://127.0.0.1:3000/callback'),
}).then(function({ dashboardUrl, loginUrl }) {
const expectedUrl = `${dashboardUrl}/login/cli/http%253A%252F%252F127.0.0.1%253A3000%252Fcallback`;
return chai.expect(loginUrl).to.equal(expectedUrl);
return expect(loginUrl).to.equal(expectedUrl);
}));
});
return describe('.loginIfTokenValid()', function() {
it('should eventually be false if token is undefined', function() {
const promise = utils.loginIfTokenValid(undefined);
return chai.expect(promise).to.eventually.be.false;
return expect(promise).to.eventually.be.false;
});
it('should eventually be false if token is null', function() {
const promise = utils.loginIfTokenValid(null);
return chai.expect(promise).to.eventually.be.false;
return expect(promise).to.eventually.be.false;
});
it('should eventually be false if token is an empty string', function() {
const promise = utils.loginIfTokenValid('');
return chai.expect(promise).to.eventually.be.false;
return expect(promise).to.eventually.be.false;
});
it('should eventually be false if token is a string containing only spaces', function() {
const promise = utils.loginIfTokenValid(' ');
return chai.expect(promise).to.eventually.be.false;
return expect(promise).to.eventually.be.false;
});
describe('given the token does not authenticate with the server', function() {
@ -78,7 +78,7 @@ describe('Utils:', function() {
it('should eventually be false', function() {
const promise = utils.loginIfTokenValid(tokens.johndoe.token);
return chai.expect(promise).to.eventually.be.false;
return expect(promise).to.eventually.be.false;
});
describe('given there was a token already', function() {
@ -88,12 +88,12 @@ describe('Utils:', function() {
balena.auth
.getToken()
.then(function(originalToken: string) {
chai.expect(originalToken).to.equal(tokens.janedoe.token);
expect(originalToken).to.equal(tokens.janedoe.token);
return utils.loginIfTokenValid(tokens.johndoe.token);
})
.then(balena.auth.getToken)
.then((currentToken: string) =>
chai.expect(currentToken).to.equal(tokens.janedoe.token),
expect(currentToken).to.equal(tokens.janedoe.token),
));
});
@ -104,9 +104,7 @@ describe('Utils:', function() {
utils
.loginIfTokenValid(tokens.johndoe.token)
.then(() => balena.auth.isLoggedIn())
.then((isLoggedIn: boolean) =>
chai.expect(isLoggedIn).to.equal(false),
));
.then((isLoggedIn: boolean) => expect(isLoggedIn).to.equal(false)));
});
});
@ -122,7 +120,7 @@ describe('Utils:', function() {
return it('should eventually be true', function() {
const promise = utils.loginIfTokenValid(tokens.johndoe.token);
return chai.expect(promise).to.eventually.be.true;
return expect(promise).to.eventually.be.true;
});
});
});

View File

@ -0,0 +1,35 @@
import { expect } from 'chai';
import * as _ from 'lodash';
import { cleanOutput, runCommand } from '../../helpers';
const HELP_MESSAGE = `
Usage: app create <name>
Use this command to create a new balena application.
You can specify the application device type with the \`--type\` option.
Otherwise, an interactive dropdown will be shown for you to select from.
You can see a list of supported device types with
\t$ balena devices supported
Examples:
\t$ balena app create MyApp
\t$ balena app create MyApp --type raspberry-pi
Options:
--type, -t <type> application device type (Check available types with \`balena devices supported\`)
`;
describe('balena app create', function() {
it('should print help text with the -h flag', async () => {
const { out, err } = await runCommand('app create -h');
expect(cleanOutput(out)).to.deep.equal(cleanOutput([HELP_MESSAGE]));
expect(err).to.have.lengthOf(0);
});
});

View File

@ -0,0 +1,35 @@
import { expect } from 'chai';
import * as _ from 'lodash';
import { cleanOutput, runCommand } from '../../helpers';
const HELP = `
Usage: devices supported
Use this command to get the list of all supported devices.
Examples:
\t$ balena devices supported
`;
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);
});
});

View File

@ -1,4 +1,4 @@
import * as chai from 'chai';
import { expect } from 'chai';
import { balenaAPIMock, runCommand } from '../../helpers';
describe('balena env add', function() {
@ -20,8 +20,8 @@ describe('balena env add', function() {
const { out, err } = await runCommand(`env add TEST 1 -d ${deviceId}`);
chai.expect(out.join('')).to.equal('');
chai.expect(err.join('')).to.equal('');
expect(out.join('')).to.equal('');
expect(err.join('')).to.equal('');
// @ts-ignore
mock.remove();

View File

@ -15,7 +15,7 @@
* limitations under the License.
*/
import * as chai from 'chai';
import { expect } from 'chai';
import { balenaAPIMock, runCommand } from '../../helpers';
describe('balena env rename', function() {
@ -25,8 +25,8 @@ describe('balena env rename', function() {
const { out, err } = await runCommand('env rename 376 emacs --device');
chai.expect(out.join('')).to.equal('');
chai.expect(err.join('')).to.equal('');
expect(out.join('')).to.equal('');
expect(err.join('')).to.equal('');
// @ts-ignore
mock.remove();

View File

@ -1,4 +1,4 @@
import * as chai from 'chai';
import { expect } from 'chai';
import { balenaAPIMock, runCommand } from '../../helpers';
describe('balena env rm', function() {
@ -8,8 +8,8 @@ describe('balena env rm', function() {
const { out, err } = await runCommand('env rm 144690 -d -y');
chai.expect(out.join('')).to.equal('');
chai.expect(err.join('')).to.equal('');
expect(out.join('')).to.equal('');
expect(err.join('')).to.equal('');
// @ts-ignore
mock.remove();

View File

@ -1,6 +1,6 @@
import * as chai from 'chai';
import { expect } from 'chai';
import * as _ from 'lodash';
import { runCommand } from '../helpers';
import { cleanOutput, runCommand } from '../helpers';
const SIMPLE_HELP = `
Usage: balena [COMMAND] [OPTIONS]
@ -92,62 +92,44 @@ const GLOBAL_OPTIONS = `
--version, -v
`;
const cleanOutput = (output: string[] | string) => {
return _(_.castArray(output))
.map(log => {
return log.split('\n').map(line => {
return line.trim();
});
})
.flatten()
.compact()
.value();
};
describe('balena help', function() {
it('should print simple help text', async () => {
const { out, err } = await runCommand('help');
chai
.expect(cleanOutput(out))
.to.deep.equal(
cleanOutput([
SIMPLE_HELP,
'Run `balena help --verbose` to list additional commands',
GLOBAL_OPTIONS,
]),
);
expect(cleanOutput(out)).to.deep.equal(
cleanOutput([
SIMPLE_HELP,
'Run `balena help --verbose` to list additional commands',
GLOBAL_OPTIONS,
]),
);
chai.expect(err.join('')).to.equal('');
expect(err.join('')).to.equal('');
});
it('should print additional commands with the -v flag', async () => {
const { out, err } = await runCommand('help -v');
chai
.expect(cleanOutput(out))
.to.deep.equal(
cleanOutput([SIMPLE_HELP, ADDITIONAL_HELP, GLOBAL_OPTIONS]),
);
expect(cleanOutput(out)).to.deep.equal(
cleanOutput([SIMPLE_HELP, ADDITIONAL_HELP, GLOBAL_OPTIONS]),
);
chai.expect(err.join('')).to.equal('');
expect(err.join('')).to.equal('');
chai.expect(err.join('')).to.equal('');
expect(err.join('')).to.equal('');
});
it('should print simple help text when no arguments present', async () => {
const { out, err } = await runCommand('');
chai
.expect(cleanOutput(out))
.to.deep.equal(
cleanOutput([
SIMPLE_HELP,
'Run `balena help --verbose` to list additional commands',
GLOBAL_OPTIONS,
]),
);
expect(cleanOutput(out)).to.deep.equal(
cleanOutput([
SIMPLE_HELP,
'Run `balena help --verbose` to list additional commands',
GLOBAL_OPTIONS,
]),
);
chai.expect(err.join('')).to.equal('');
expect(err.join('')).to.equal('');
});
});

View File

@ -1,4 +1,4 @@
import * as chai from 'chai';
import { expect } from 'chai';
import * as fs from 'fs';
import { runCommand } from '../helpers';
@ -11,13 +11,13 @@ describe('balena version', function() {
it('should print the installed version of the CLI', async () => {
const { out } = await runCommand('version');
chai.expect(out.join('')).to.equal(`${packageJSON.version}\n`);
expect(out.join('')).to.equal(`${packageJSON.version}\n`);
});
it('should print additional version information with the -a flag', async () => {
const { out } = await runCommand('version -a');
chai.expect(out.join('')).to.equal(
expect(out.join('')).to.equal(
`balena-cli version "${packageJSON.version}"
Node.js version "${nodeVersion}"
`,
@ -29,7 +29,7 @@ Node.js version "${nodeVersion}"
const json = JSON.parse(out.join(''));
chai.expect(json).to.deep.equal({
expect(json).to.deep.equal({
'balena-cli': packageJSON.version,
'Node.js': nodeVersion,
});

View File

@ -16,6 +16,7 @@
*/
import intercept = require('intercept-stdout');
import * as _ from 'lodash';
import * as nock from 'nock';
import * as path from 'path';
@ -78,3 +79,15 @@ export const balenaAPIMock = () => {
configVarSchema: [],
});
};
export function cleanOutput(output: string[] | string) {
return _(_.castArray(output))
.map(log => {
return log.split('\n').map(line => {
return line.trim();
});
})
.flatten()
.compact()
.value();
}