mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-02-06 19:19:56 +00:00
Merge pull request #2683 from balena-io/bump-oclif-core-to-v3
Bump oclif-core to v3
This commit is contained in:
commit
90b65cd06b
@ -15,7 +15,7 @@ async function run() {
|
|||||||
require('@balena/es-version').set('es2018');
|
require('@balena/es-version').set('es2018');
|
||||||
|
|
||||||
// Run the CLI
|
// Run the CLI
|
||||||
await require('../build/app').run();
|
await require('../build/app').run(undefined, { dir: __dirname });
|
||||||
}
|
}
|
||||||
|
|
||||||
run();
|
run();
|
||||||
|
@ -57,7 +57,7 @@ require('ts-node').register({
|
|||||||
project: path.join(rootDir, 'tsconfig.json'),
|
project: path.join(rootDir, 'tsconfig.json'),
|
||||||
transpileOnly: true,
|
transpileOnly: true,
|
||||||
});
|
});
|
||||||
require('../lib/app').run();
|
require('../lib/app').run(undefined, { dir: __dirname, development: true });
|
||||||
|
|
||||||
// Modify package.json oclif paths from build/ -> lib/, or vice versa
|
// Modify package.json oclif paths from build/ -> lib/, or vice versa
|
||||||
function modifyOclifPaths(revert) {
|
function modifyOclifPaths(revert) {
|
||||||
|
13
lib/app.ts
13
lib/app.ts
@ -24,7 +24,7 @@ import {
|
|||||||
} from './preparser';
|
} from './preparser';
|
||||||
import { CliSettings } from './utils/bootstrap';
|
import { CliSettings } from './utils/bootstrap';
|
||||||
import { onceAsync } from './utils/lazy';
|
import { onceAsync } from './utils/lazy';
|
||||||
import { run as mainRun } from '@oclif/core';
|
import { run as mainRun, settings } from '@oclif/core';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sentry.io setup
|
* Sentry.io setup
|
||||||
@ -117,7 +117,14 @@ async function oclifRun(command: string[], options: AppOptions) {
|
|||||||
const runPromise = (async function (shouldFlush: boolean) {
|
const runPromise = (async function (shouldFlush: boolean) {
|
||||||
let isEEXIT = false;
|
let isEEXIT = false;
|
||||||
try {
|
try {
|
||||||
await mainRun(command, options.configPath);
|
if (options.development) {
|
||||||
|
// In dev mode -> use ts-node and dev plugins
|
||||||
|
process.env.NODE_ENV = 'development';
|
||||||
|
settings.debug = true;
|
||||||
|
}
|
||||||
|
// For posteriority: We can't use default oclif 'execute' as
|
||||||
|
// We customize error handling and flushing
|
||||||
|
await mainRun(command, options.loadOptions ?? options.dir);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// oclif sometimes exits with ExitError code EEXIT 0 (not an error),
|
// oclif sometimes exits with ExitError code EEXIT 0 (not an error),
|
||||||
// for example the `balena help` command.
|
// for example the `balena help` command.
|
||||||
@ -151,7 +158,7 @@ async function oclifRun(command: string[], options: AppOptions) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** CLI entrypoint. Called by the `bin/balena` and `bin/balena-dev` scripts. */
|
/** CLI entrypoint. Called by the `bin/balena` and `bin/balena-dev` scripts. */
|
||||||
export async function run(cliArgs = process.argv, options: AppOptions = {}) {
|
export async function run(cliArgs = process.argv, options: AppOptions) {
|
||||||
try {
|
try {
|
||||||
const { setOfflineModeEnvVars, normalizeEnvVars, pkgExec } = await import(
|
const { setOfflineModeEnvVars, normalizeEnvVars, pkgExec } = await import(
|
||||||
'./utils/bootstrap'
|
'./utils/bootstrap'
|
||||||
|
@ -50,7 +50,7 @@ export default class BalenaHelp extends Help {
|
|||||||
|
|
||||||
const command = this.config.findCommand(subject);
|
const command = this.config.findCommand(subject);
|
||||||
if (command) {
|
if (command) {
|
||||||
await this.showCommandHelp(await command.load());
|
await this.showCommandHelp(command);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,12 +15,16 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import type { Interfaces } from '@oclif/core';
|
||||||
|
|
||||||
export let unsupportedFlag = false;
|
export let unsupportedFlag = false;
|
||||||
|
|
||||||
export interface AppOptions {
|
export interface AppOptions {
|
||||||
// Prevent the default behavior of flushing stdout after running a command
|
// Prevent the default behavior of flushing stdout after running a command
|
||||||
noFlush?: boolean;
|
noFlush?: boolean;
|
||||||
configPath?: string;
|
development?: boolean;
|
||||||
|
dir: string;
|
||||||
|
loadOptions?: Interfaces.LoadOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function preparseArgs(argv: string[]): Promise<string[]> {
|
export async function preparseArgs(argv: string[]): Promise<string[]> {
|
||||||
|
1081
npm-shrinkwrap.json
generated
1081
npm-shrinkwrap.json
generated
File diff suppressed because it is too large
Load Diff
@ -196,7 +196,7 @@
|
|||||||
"@balena/compose": "^3.0.5",
|
"@balena/compose": "^3.0.5",
|
||||||
"@balena/dockerignore": "^1.0.2",
|
"@balena/dockerignore": "^1.0.2",
|
||||||
"@balena/es-version": "^1.0.1",
|
"@balena/es-version": "^1.0.1",
|
||||||
"@oclif/core": "^2.15.0",
|
"@oclif/core": "^3.11.0",
|
||||||
"@resin.io/valid-email": "^0.1.0",
|
"@resin.io/valid-email": "^0.1.0",
|
||||||
"@sentry/node": "^6.16.1",
|
"@sentry/node": "^6.16.1",
|
||||||
"@types/fast-levenshtein": "0.0.1",
|
"@types/fast-levenshtein": "0.0.1",
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
diff --git a/node_modules/@oclif/core/lib/cli-ux/list.js b/node_modules/@oclif/core/lib/cli-ux/list.js
|
diff --git a/node_modules/@oclif/core/lib/cli-ux/list.js b/node_modules/@oclif/core/lib/cli-ux/list.js
|
||||||
index dc6058c..64b2f85 100644
|
index 607d8dc..07ba1f2 100644
|
||||||
--- a/node_modules/@oclif/core/lib/cli-ux/list.js
|
--- a/node_modules/@oclif/core/lib/cli-ux/list.js
|
||||||
+++ b/node_modules/@oclif/core/lib/cli-ux/list.js
|
+++ b/node_modules/@oclif/core/lib/cli-ux/list.js
|
||||||
@@ -22,7 +22,7 @@ function renderList(items) {
|
@@ -22,7 +22,7 @@ function renderList(items) {
|
||||||
@ -12,20 +12,20 @@ index dc6058c..64b2f85 100644
|
|||||||
return lines.join('\n');
|
return lines.join('\n');
|
||||||
}
|
}
|
||||||
diff --git a/node_modules/@oclif/core/lib/help/command.js b/node_modules/@oclif/core/lib/help/command.js
|
diff --git a/node_modules/@oclif/core/lib/help/command.js b/node_modules/@oclif/core/lib/help/command.js
|
||||||
index 6de139b..3a13197 100644
|
index c528e93..2c20760 100644
|
||||||
--- a/node_modules/@oclif/core/lib/help/command.js
|
--- a/node_modules/@oclif/core/lib/help/command.js
|
||||||
+++ b/node_modules/@oclif/core/lib/help/command.js
|
+++ b/node_modules/@oclif/core/lib/help/command.js
|
||||||
@@ -206,7 +206,7 @@ class CommandHelp extends formatter_1.HelpFormatter {
|
@@ -45,7 +45,7 @@ class CommandHelp extends formatter_1.HelpFormatter {
|
||||||
if (args.filter(a => a.description).length === 0)
|
if (args.filter((a) => a.description).length === 0)
|
||||||
return;
|
return;
|
||||||
return args.map(a => {
|
return args.map((a) => {
|
||||||
- const name = a.name.toUpperCase();
|
- const name = a.name.toUpperCase();
|
||||||
+ const name = a.required ? `<${a.name}>` : `[${a.name}]`;
|
+ const name = a.required ? `<${a.name}>` : `[${a.name}]`;
|
||||||
let description = a.description || '';
|
let description = a.description || '';
|
||||||
if (a.default)
|
if (a.default)
|
||||||
description = `[default: ${a.default}] ${description}`;
|
description = `[default: ${a.default}] ${description}`;
|
||||||
@@ -238,14 +238,12 @@ class CommandHelp extends formatter_1.HelpFormatter {
|
@@ -137,14 +137,12 @@ class CommandHelp extends formatter_1.HelpFormatter {
|
||||||
label = labels.join(', ');
|
label = labels.join(flag.char ? ', ' : ' ');
|
||||||
}
|
}
|
||||||
if (flag.type === 'option') {
|
if (flag.type === 'option') {
|
||||||
- let value = flag.helpValue || (this.opts.showFlagNameInTitle ? flag.name : '<value>');
|
- let value = flag.helpValue || (this.opts.showFlagNameInTitle ? flag.name : '<value>');
|
||||||
@ -36,16 +36,16 @@ index 6de139b..3a13197 100644
|
|||||||
if (flag.multiple)
|
if (flag.multiple)
|
||||||
- value += '...';
|
- value += '...';
|
||||||
- if (!value.includes('|'))
|
- if (!value.includes('|'))
|
||||||
- value = underline(value);
|
- value = chalk_1.default.underline(value);
|
||||||
+ value += ' ...';
|
+ value += ' ...';
|
||||||
label += `=${value}`;
|
label += `=${value}`;
|
||||||
}
|
}
|
||||||
return label;
|
return label;
|
||||||
diff --git a/node_modules/@oclif/core/lib/help/index.js b/node_modules/@oclif/core/lib/help/index.js
|
diff --git a/node_modules/@oclif/core/lib/help/index.js b/node_modules/@oclif/core/lib/help/index.js
|
||||||
index f9ef7cc..a14c67c 100644
|
index 38494f5..213b8b0 100644
|
||||||
--- a/node_modules/@oclif/core/lib/help/index.js
|
--- a/node_modules/@oclif/core/lib/help/index.js
|
||||||
+++ b/node_modules/@oclif/core/lib/help/index.js
|
+++ b/node_modules/@oclif/core/lib/help/index.js
|
||||||
@@ -136,11 +136,12 @@ class Help extends HelpBase {
|
@@ -158,11 +158,12 @@ class Help extends HelpBase {
|
||||||
}
|
}
|
||||||
this.log(this.formatCommand(command));
|
this.log(this.formatCommand(command));
|
||||||
this.log('');
|
this.log('');
|
||||||
@ -58,15 +58,15 @@ index f9ef7cc..a14c67c 100644
|
|||||||
- if (subCommands.length > 0) {
|
- if (subCommands.length > 0) {
|
||||||
+ if (subCommands.length > 0 && !SUPPRESS_SUBTOPICS) {
|
+ if (subCommands.length > 0 && !SUPPRESS_SUBTOPICS) {
|
||||||
const aliases = [];
|
const aliases = [];
|
||||||
const uniqueSubCommands = subCommands.filter(p => {
|
const uniqueSubCommands = subCommands.filter((p) => {
|
||||||
aliases.push(...p.aliases);
|
aliases.push(...p.aliases);
|
||||||
diff --git a/node_modules/@oclif/core/lib/parser/errors.js b/node_modules/@oclif/core/lib/parser/errors.js
|
diff --git a/node_modules/@oclif/core/lib/parser/errors.js b/node_modules/@oclif/core/lib/parser/errors.js
|
||||||
index 07ec8e5..a4560ea 100644
|
index 51be624..768d589 100644
|
||||||
--- a/node_modules/@oclif/core/lib/parser/errors.js
|
--- a/node_modules/@oclif/core/lib/parser/errors.js
|
||||||
+++ b/node_modules/@oclif/core/lib/parser/errors.js
|
+++ b/node_modules/@oclif/core/lib/parser/errors.js
|
||||||
@@ -10,7 +10,8 @@ var errors_2 = require("../errors");
|
@@ -14,7 +14,8 @@ Object.defineProperty(exports, "CLIError", { enumerable: true, get: function ()
|
||||||
Object.defineProperty(exports, "CLIError", { enumerable: true, get: function () { return errors_2.CLIError; } });
|
|
||||||
class CLIParseError extends errors_1.CLIError {
|
class CLIParseError extends errors_1.CLIError {
|
||||||
|
parse;
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
- options.message += '\nSee more help with --help';
|
- options.message += '\nSee more help with --help';
|
||||||
+ const help = options.command ? `\`${options.command} --help\`` : '--help';
|
+ const help = options.command ? `\`${options.command} --help\`` : '--help';
|
||||||
@ -74,33 +74,34 @@ index 07ec8e5..a4560ea 100644
|
|||||||
super(options.message);
|
super(options.message);
|
||||||
this.parse = options.parse;
|
this.parse = options.parse;
|
||||||
}
|
}
|
||||||
@@ -31,7 +32,8 @@ class InvalidArgsSpecError extends CLIParseError {
|
@@ -37,7 +38,8 @@ exports.InvalidArgsSpecError = InvalidArgsSpecError;
|
||||||
exports.InvalidArgsSpecError = InvalidArgsSpecError;
|
|
||||||
class RequiredArgsError extends CLIParseError {
|
class RequiredArgsError extends CLIParseError {
|
||||||
constructor({ args, parse, flagsWithMultiple }) {
|
args;
|
||||||
|
constructor({ args, flagsWithMultiple, parse, }) {
|
||||||
- let message = `Missing ${args.length} required arg${args.length === 1 ? '' : 's'}`;
|
- let message = `Missing ${args.length} required arg${args.length === 1 ? '' : 's'}`;
|
||||||
+ const command = 'balena ' + parse.input.context.id.replace(/:/g, ' ');
|
+ const command = 'balena ' + parse.input.context.id.replace(/:/g, ' ');
|
||||||
+ let message = `Missing ${args.length} required argument${args.length === 1 ? '' : 's'}`;
|
+ let message = `Missing ${args.length} required argument${args.length === 1 ? '' : 's'}`;
|
||||||
const namedArgs = args.filter(a => a.name);
|
const namedArgs = args.filter((a) => a.name);
|
||||||
if (namedArgs.length > 0) {
|
if (namedArgs.length > 0) {
|
||||||
const list = (0, list_1.renderList)(namedArgs.map(a => [a.name, a.description]));
|
const list = (0, list_1.renderList)(namedArgs.map((a) => [a.name, a.description]));
|
||||||
@@ -42,16 +44,17 @@ class RequiredArgsError extends CLIParseError {
|
@@ -48,7 +50,7 @@ class RequiredArgsError extends CLIParseError {
|
||||||
message += `\n\nNote: ${flags} allow${flagsWithMultiple.length === 1 ? 's' : ''} multiple values. Because of this you need to provide all arguments before providing ${flagsWithMultiple.length === 1 ? 'that flag' : 'those flags'}.`;
|
message += `\n\nNote: ${flags} allow${flagsWithMultiple.length === 1 ? 's' : ''} multiple values. Because of this you need to provide all arguments before providing ${flagsWithMultiple.length === 1 ? 'that flag' : 'those flags'}.`;
|
||||||
message += '\nAlternatively, you can use "--" to signify the end of the flags and the beginning of arguments.';
|
message += '\nAlternatively, you can use "--" to signify the end of the flags and the beginning of arguments.';
|
||||||
}
|
}
|
||||||
- super({ parse, message });
|
- super({ message, parse });
|
||||||
+ super({ parse, message, command });
|
+ super({ message, parse, command });
|
||||||
this.args = args;
|
this.args = args;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.RequiredArgsError = RequiredArgsError;
|
@@ -56,9 +58,10 @@ exports.RequiredArgsError = RequiredArgsError;
|
||||||
class RequiredFlagError extends CLIParseError {
|
class RequiredFlagError extends CLIParseError {
|
||||||
|
flag;
|
||||||
constructor({ flag, parse }) {
|
constructor({ flag, parse }) {
|
||||||
+ const command = 'balena ' + parse.input.context.id.replace(/:/g, ' ');
|
+ const command = 'balena ' + parse.input.context.id.replace(/:/g, ' ');
|
||||||
const usage = (0, list_1.renderList)((0, help_1.flagUsages)([flag], { displayRequired: false }));
|
const usage = (0, list_1.renderList)((0, help_1.flagUsages)([flag], { displayRequired: false }));
|
||||||
const message = `Missing required flag:\n${usage}`;
|
const message = `Missing required flag:\n${usage}`;
|
||||||
- super({ parse, message });
|
- super({ message, parse });
|
||||||
+ super({ parse, message, command });
|
+ super({ message, parse, command });
|
||||||
this.flag = flag;
|
this.flag = flag;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -106,7 +106,7 @@ async function runCommandInProcess(cmd: string): Promise<TestOutput> {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await balenaCLI.run(preArgs.concat(cmd.split(' ').filter((c) => c)), {
|
await balenaCLI.run(preArgs.concat(cmd.split(' ').filter((c) => c)), {
|
||||||
configPath: path.resolve(__dirname, '..'),
|
dir: path.resolve(__dirname, '..'),
|
||||||
noFlush: true,
|
noFlush: true,
|
||||||
});
|
});
|
||||||
} finally {
|
} finally {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user