mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-22 06:57:48 +00:00
Merge pull request #1853 from balena-io/1770-devices-supported-et-al
v12 preparations: Add feature switches ('devices supported' and others)
This commit is contained in:
commit
5c8d822aee
@ -21,6 +21,7 @@ import { stripIndent } from 'common-tags';
|
||||
import Command from '../command';
|
||||
import * as cf from '../utils/common-flags';
|
||||
import { getBalenaSdk, getVisuals } from '../utils/lazy';
|
||||
import { isV12 } from '../utils/version';
|
||||
|
||||
interface ExtendedApplication extends Application {
|
||||
device_count?: number;
|
||||
@ -49,7 +50,9 @@ export default class AppsCmd extends Command {
|
||||
help: cf.help,
|
||||
verbose: flags.boolean({
|
||||
char: 'v',
|
||||
description: 'add extra columns in the tabular output (SLUG)',
|
||||
description: isV12()
|
||||
? 'No-op since release v12.0.0'
|
||||
: 'add extra columns in the tabular output (SLUG)',
|
||||
}),
|
||||
};
|
||||
|
||||
@ -83,7 +86,7 @@ export default class AppsCmd extends Command {
|
||||
getVisuals().table.horizontal(applications, [
|
||||
'id',
|
||||
'app_name',
|
||||
options.verbose ? 'slug' : '',
|
||||
options.verbose || isV12() ? 'slug' : '',
|
||||
'device_type',
|
||||
'online_devices',
|
||||
'device_count',
|
||||
|
@ -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,
|
||||
|
@ -562,10 +562,15 @@ export async function validateProjectDirectory(
|
||||
checkCompose(path.join(opts.projectPath, '..')),
|
||||
]);
|
||||
if (!hasCompose && hasParentCompose) {
|
||||
Logger.getLogger().logWarn(stripIndent`
|
||||
"docker-compose.y[a]ml" file found in parent directory: please check
|
||||
that the correct folder was specified. (Suppress with '--noparent-check'.)
|
||||
`);
|
||||
const { isV12 } = await import('./version');
|
||||
const msg = stripIndent`
|
||||
"docker-compose.y[a]ml" file found in parent directory: please check that
|
||||
the correct source folder was specified. (Suppress with '--noparent-check'.)`;
|
||||
if (isV12()) {
|
||||
throw new ExpectedError(`Error: ${msg}`);
|
||||
} else {
|
||||
Logger.getLogger().logWarn(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -22,6 +22,7 @@ import { expect } from 'chai';
|
||||
import { fs } from 'mz';
|
||||
import * as path from 'path';
|
||||
|
||||
import { isV12 } from '../../build/utils/version';
|
||||
import { BalenaAPIMock } from '../balena-api-mock';
|
||||
import { BuilderMock, builderResponsePath } from '../builder-mock';
|
||||
import { expectStreamNoCRLF, testPushBuildStream } from '../docker-build';
|
||||
@ -230,14 +231,23 @@ describe('balena push', function() {
|
||||
'.balena/balena.yml': { fileSize: 12, type: 'file' },
|
||||
'.dockerignore': { fileSize: 438, type: 'file' },
|
||||
'.gitignore': { fileSize: 20, type: 'file' },
|
||||
'.git/bar.txt': { fileSize: 4, type: 'file' },
|
||||
'.git/foo.txt': { fileSize: 4, type: 'file' },
|
||||
'c.txt': { fileSize: 1, type: 'file' },
|
||||
Dockerfile: { fileSize: 13, type: 'file' },
|
||||
'src/.balena/balena.yml': { fileSize: 16, type: 'file' },
|
||||
'src/.gitignore': { fileSize: 10, type: 'file' },
|
||||
'vendor/.git/vendor-git-contents': { fileSize: 20, type: 'file' },
|
||||
...(isV12()
|
||||
? {
|
||||
'a.txt': { fileSize: 1, type: 'file' },
|
||||
'src/src-a.txt': { fileSize: 5, type: 'file' },
|
||||
'src/src-c.txt': { fileSize: 5, type: 'file' },
|
||||
}
|
||||
: {
|
||||
'.git/bar.txt': { fileSize: 4, type: 'file' },
|
||||
}),
|
||||
};
|
||||
|
||||
const regSecretsPath = await addRegSecretsEntries(expectedFiles);
|
||||
const responseFilename = 'build-POST-v3.json';
|
||||
const responseBody = await fs.readFile(
|
||||
@ -245,14 +255,18 @@ describe('balena push', function() {
|
||||
'utf8',
|
||||
);
|
||||
const expectedResponseLines = [
|
||||
'[Warn] Using file ignore patterns from:',
|
||||
`[Warn] ${path.join(projectPath, '.dockerignore')}`,
|
||||
`[Warn] ${path.join(projectPath, '.gitignore')}`,
|
||||
`[Warn] ${path.join(projectPath, 'src', '.gitignore')}`,
|
||||
'[Warn] balena CLI currently uses gitgnore and dockerignore files, but an upcoming major',
|
||||
'[Warn] version release will disregard gitignore files and use a dockerignore file only.',
|
||||
'[Warn] Use the --nogitignore (-G) option to enable the new behavior already now and',
|
||||
"[Warn] suppress this warning. For more information, see 'balena help push'.",
|
||||
...(!isV12()
|
||||
? [
|
||||
'[Warn] Using file ignore patterns from:',
|
||||
`[Warn] ${path.join(projectPath, '.dockerignore')}`,
|
||||
`[Warn] ${path.join(projectPath, '.gitignore')}`,
|
||||
`[Warn] ${path.join(projectPath, 'src', '.gitignore')}`,
|
||||
'[Warn] balena CLI currently uses gitgnore and dockerignore files, but an upcoming major',
|
||||
'[Warn] version release will disregard gitignore files and use a dockerignore file only.',
|
||||
'[Warn] Use the --nogitignore (-G) option to enable the new behavior already now and',
|
||||
"[Warn] suppress this warning. For more information, see 'balena help push'.",
|
||||
]
|
||||
: []),
|
||||
...commonResponseLines[responseFilename],
|
||||
];
|
||||
|
||||
@ -486,13 +500,18 @@ describe('balena push: project validation', function() {
|
||||
'basic',
|
||||
'service1',
|
||||
);
|
||||
const expectedErrorLines = [
|
||||
'The --nolive flag is only valid when pushing to a local mode device',
|
||||
];
|
||||
const expectedOutputLines = [
|
||||
'[Warn] "docker-compose.y[a]ml" file found in parent directory: please check',
|
||||
"[Warn] that the correct folder was specified. (Suppress with '--noparent-check'.)",
|
||||
];
|
||||
const expectedErrorLines = isV12()
|
||||
? [
|
||||
'Error: "docker-compose.y[a]ml" file found in parent directory: please check that',
|
||||
"the correct source folder was specified. (Suppress with '--noparent-check'.)",
|
||||
]
|
||||
: ['The --nolive flag is only valid when pushing to a local mode device'];
|
||||
const expectedOutputLines = isV12()
|
||||
? []
|
||||
: [
|
||||
'[Warn] "docker-compose.y[a]ml" file found in parent directory: please check that',
|
||||
"[Warn] the correct source folder was specified. (Suppress with '--noparent-check'.)",
|
||||
];
|
||||
|
||||
const { out, err } = await runCommand(
|
||||
`push testApp --source ${projectPath} --nolive`,
|
||||
|
Loading…
Reference in New Issue
Block a user