mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-01-18 18:56:25 +00:00
Fix cross-framework nested commands
Change-type: patch Signed-off-by: Scott Lowe <scott@balena.io>
This commit is contained in:
parent
6f6cb42725
commit
402e48c8f8
@ -150,6 +150,7 @@ export const convertedCommands = [
|
|||||||
'api-key:generate',
|
'api-key:generate',
|
||||||
'device',
|
'device',
|
||||||
'device:identify',
|
'device:identify',
|
||||||
|
'device:init',
|
||||||
'device:move',
|
'device:move',
|
||||||
'device:os-update',
|
'device:os-update',
|
||||||
'device:public-url',
|
'device:public-url',
|
||||||
@ -195,7 +196,7 @@ export const convertedCommands = [
|
|||||||
* oclif "topics" (colon-separated subcommands like `env:add`)
|
* oclif "topics" (colon-separated subcommands like `env:add`)
|
||||||
* @param argvSlice process.argv.slice(2)
|
* @param argvSlice process.argv.slice(2)
|
||||||
*/
|
*/
|
||||||
function isOclifCommand(argvSlice: string[]): [boolean, boolean] {
|
export function isOclifCommand(argvSlice: string[]): [boolean, boolean] {
|
||||||
// Look for commands that have been transitioned to oclif
|
// Look for commands that have been transitioned to oclif
|
||||||
// const { convertedCommands } = require('oclif/utils/command');
|
// const { convertedCommands } = require('oclif/utils/command');
|
||||||
const arg0 = argvSlice.length > 0 ? argvSlice[0] : '';
|
const arg0 = argvSlice.length > 0 ? argvSlice[0] : '';
|
||||||
|
@ -25,6 +25,7 @@ import type { Device, PineOptionsFor } from 'balena-sdk';
|
|||||||
import { ExpectedError } from '../errors';
|
import { ExpectedError } from '../errors';
|
||||||
import { getBalenaSdk, getChalk, getVisuals } from './lazy';
|
import { getBalenaSdk, getChalk, getVisuals } from './lazy';
|
||||||
import { promisify } from 'util';
|
import { promisify } from 'util';
|
||||||
|
import { isOclifCommand } from '../preparser';
|
||||||
|
|
||||||
export function getGroupDefaults(group: {
|
export function getGroupDefaults(group: {
|
||||||
options: Array<{ name: string; default?: string }>;
|
options: Array<{ name: string; default?: string }>;
|
||||||
@ -96,9 +97,26 @@ export async function sudo(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function runCommand<T>(command: string): Promise<T> {
|
export function runCommand<T>(command: string): Promise<T> {
|
||||||
const capitano = require('capitano') as typeof import('capitano');
|
let commandArgs = command.split(' ');
|
||||||
const capitanoRunAsync = promisify(capitano.run);
|
const [isOclif, isOclifTopic] = isOclifCommand(commandArgs);
|
||||||
return capitanoRunAsync(command);
|
if (isOclif) {
|
||||||
|
if (isOclifTopic) {
|
||||||
|
commandArgs = [
|
||||||
|
commandArgs[0] + ':' + commandArgs[1],
|
||||||
|
...commandArgs.slice(2),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
const { run } = require('@oclif/command');
|
||||||
|
return run(commandArgs);
|
||||||
|
} else {
|
||||||
|
const capitano = require('capitano') as typeof import('capitano');
|
||||||
|
// Need to require app-capitano to register capitano commands,
|
||||||
|
// in case calling command is oclif
|
||||||
|
require('../app-capitano');
|
||||||
|
|
||||||
|
const capitanoRunAsync = promisify(capitano.run);
|
||||||
|
return capitanoRunAsync(command);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getManifest(
|
export async function getManifest(
|
||||||
|
Loading…
Reference in New Issue
Block a user