2019-06-24 15:51:07 +00:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright 2019 Balena Ltd.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2023-09-06 14:39:31 +00:00
|
|
|
import { Flags } from '@oclif/core';
|
2020-03-19 08:45:57 +00:00
|
|
|
import Command from '../command';
|
2020-05-04 14:57:23 +00:00
|
|
|
import { stripIndent } from '../utils/lazy';
|
2019-06-24 15:51:07 +00:00
|
|
|
|
2019-09-10 22:51:53 +00:00
|
|
|
export interface JsonVersions {
|
|
|
|
'balena-cli': string;
|
|
|
|
'Node.js': string;
|
|
|
|
}
|
|
|
|
|
2019-06-24 15:51:07 +00:00
|
|
|
export default class VersionCmd extends Command {
|
|
|
|
public static description = stripIndent`
|
2020-10-20 21:11:17 +00:00
|
|
|
Display version information for the balena CLI and/or Node.js.
|
2019-06-24 15:51:07 +00:00
|
|
|
|
2020-10-20 21:11:17 +00:00
|
|
|
Display version information for the balena CLI and/or Node.js. Note that the
|
|
|
|
balena CLI executable installers for Windows and macOS, and the standalone
|
2020-10-20 21:02:53 +00:00
|
|
|
zip packages, ship with a built-in copy of Node.js. In this case, the
|
|
|
|
reported version of Node.js regards this built-in copy, rather than any
|
|
|
|
other \`node\` engine that may also be available on the command prompt.
|
2020-01-03 23:13:20 +00:00
|
|
|
|
|
|
|
The --json option is recommended when scripting the output of this command,
|
|
|
|
because the JSON format is less likely to change and it better represents
|
|
|
|
data types like lists and empty strings. The 'jq' utility may be helpful
|
|
|
|
in shell scripts (https://stedolan.github.io/jq/manual/).
|
2020-09-04 14:34:34 +00:00
|
|
|
|
|
|
|
This command can also be invoked with 'balena --version' or 'balena -v'.
|
2019-06-24 15:51:07 +00:00
|
|
|
`;
|
|
|
|
public static examples = [
|
|
|
|
'$ balena version',
|
|
|
|
'$ balena version -a',
|
|
|
|
'$ balena version -j',
|
2020-09-04 14:34:34 +00:00
|
|
|
`$ balena --version`,
|
|
|
|
`$ balena -v`,
|
2019-06-24 15:51:07 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
public static usage = 'version';
|
|
|
|
|
2021-11-12 16:03:29 +00:00
|
|
|
public static offlineCompatible = true;
|
|
|
|
|
2023-09-06 14:39:31 +00:00
|
|
|
public static flags = {
|
|
|
|
all: Flags.boolean({
|
2019-06-24 15:51:07 +00:00
|
|
|
default: false,
|
2020-12-07 13:35:57 +00:00
|
|
|
char: 'a',
|
2019-06-24 15:51:07 +00:00
|
|
|
description:
|
|
|
|
'include version information for additional components (Node.js)',
|
|
|
|
}),
|
2023-09-06 14:39:31 +00:00
|
|
|
json: Flags.boolean({
|
2019-06-24 15:51:07 +00:00
|
|
|
default: false,
|
2020-12-07 13:35:57 +00:00
|
|
|
char: 'j',
|
2019-06-24 15:51:07 +00:00
|
|
|
description:
|
|
|
|
'output version information in JSON format for programmatic use',
|
|
|
|
}),
|
2023-09-06 14:39:31 +00:00
|
|
|
help: Flags.help({ char: 'h' }),
|
2019-06-24 15:51:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
public async run() {
|
2023-09-06 14:39:31 +00:00
|
|
|
const { flags: options } = await this.parse(VersionCmd);
|
2019-09-10 22:51:53 +00:00
|
|
|
const versions: JsonVersions = {
|
2019-06-24 15:51:07 +00:00
|
|
|
'balena-cli': (await import('../../package.json')).version,
|
|
|
|
'Node.js':
|
|
|
|
process.version && process.version.startsWith('v')
|
|
|
|
? process.version.slice(1)
|
|
|
|
: process.version,
|
|
|
|
};
|
|
|
|
if (options.json) {
|
|
|
|
console.log(JSON.stringify(versions, null, 4));
|
|
|
|
} else {
|
|
|
|
if (options.all) {
|
|
|
|
console.log(`balena-cli version "${versions['balena-cli']}"`);
|
|
|
|
console.log(`Node.js version "${versions['Node.js']}"`);
|
|
|
|
} else {
|
|
|
|
// backwards compatibility
|
|
|
|
console.log(versions['balena-cli']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|