mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-04-25 13:29:43 +00:00
Modify runCommand to accept args array instead of string
Change-type: patch Signed-off-by: Scott Lowe <scott@balena.io>
This commit is contained in:
parent
d4c513fd41
commit
e20265518d
@ -144,28 +144,34 @@ export default class DeviceInitCmd extends Command {
|
|||||||
|
|
||||||
async downloadOsImage(path: string, deviceType: string, options: FlagsDef) {
|
async downloadOsImage(path: string, deviceType: string, options: FlagsDef) {
|
||||||
const osVersion = options['os-version'] || 'default';
|
const osVersion = options['os-version'] || 'default';
|
||||||
await runCommand(
|
await runCommand([
|
||||||
`os download ${deviceType} --output '${path}' --version ${osVersion}`,
|
'os',
|
||||||
);
|
'download',
|
||||||
|
deviceType,
|
||||||
|
'--output',
|
||||||
|
path,
|
||||||
|
'--version',
|
||||||
|
osVersion,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
async configureOsImage(path: string, uuid: string, options: FlagsDef) {
|
async configureOsImage(path: string, uuid: string, options: FlagsDef) {
|
||||||
let configureCommand = `os configure ${path} --device ${uuid}`;
|
const configureCommand = ['os', 'configure', path, '--device', uuid];
|
||||||
if (options.config) {
|
if (options.config) {
|
||||||
configureCommand += ` --config ${options.config}`;
|
configureCommand.push('--config', options.config);
|
||||||
} else if (options.advanced) {
|
} else if (options.advanced) {
|
||||||
configureCommand += ' --advanced';
|
configureCommand.push('--advanced');
|
||||||
}
|
}
|
||||||
await runCommand(configureCommand);
|
await runCommand(configureCommand);
|
||||||
}
|
}
|
||||||
|
|
||||||
async writeOsImage(path: string, deviceType: string, options: FlagsDef) {
|
async writeOsImage(path: string, deviceType: string, options: FlagsDef) {
|
||||||
let osInitCommand = `os initialize '${path}' --type ${deviceType}`;
|
const osInitCommand = ['os', 'initialize', path, '--type', deviceType];
|
||||||
if (options.yes) {
|
if (options.yes) {
|
||||||
osInitCommand += ' --yes';
|
osInitCommand.push('--yes');
|
||||||
}
|
}
|
||||||
if (options.drive) {
|
if (options.drive) {
|
||||||
osInitCommand += ` --drive ${options.drive}`;
|
osInitCommand.push('--drive', options.drive);
|
||||||
}
|
}
|
||||||
await runCommand(osInitCommand);
|
await runCommand(osInitCommand);
|
||||||
}
|
}
|
||||||
|
@ -217,10 +217,11 @@ Examples:
|
|||||||
const { uuid } = await config.read(drive, options.type);
|
const { uuid } = await config.read(drive, options.type);
|
||||||
await umountAsync(drive);
|
await umountAsync(drive);
|
||||||
|
|
||||||
let configureCommand = `os configure ${drive} --device ${uuid}`;
|
let configureCommand = ['os', 'configure', drive, '--device', uuid];
|
||||||
if (options.advanced) {
|
if (options.advanced) {
|
||||||
configureCommand += ' --advanced';
|
configureCommand.push('--advanced');
|
||||||
}
|
}
|
||||||
|
|
||||||
const { runCommand } = await import('../utils/helpers');
|
const { runCommand } = await import('../utils/helpers');
|
||||||
await runCommand(configureCommand);
|
await runCommand(configureCommand);
|
||||||
|
|
||||||
|
@ -96,8 +96,7 @@ export async function sudo(
|
|||||||
await executeWithPrivileges(command, stderr, isCLIcmd);
|
await executeWithPrivileges(command, stderr, isCLIcmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function runCommand<T>(command: string): Promise<T> {
|
export function runCommand<T>(commandArgs: string[]): Promise<T> {
|
||||||
let commandArgs = command.split(' ');
|
|
||||||
const [isOclif, isOclifTopic] = isOclifCommand(commandArgs);
|
const [isOclif, isOclifTopic] = isOclifCommand(commandArgs);
|
||||||
if (isOclif) {
|
if (isOclif) {
|
||||||
if (isOclifTopic) {
|
if (isOclifTopic) {
|
||||||
@ -115,7 +114,7 @@ export function runCommand<T>(command: string): Promise<T> {
|
|||||||
require('../app-capitano');
|
require('../app-capitano');
|
||||||
|
|
||||||
const capitanoRunAsync = promisify(capitano.run);
|
const capitanoRunAsync = promisify(capitano.run);
|
||||||
return capitanoRunAsync(command);
|
return capitanoRunAsync(commandArgs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ function filterCliOutputForTests(testOutput: TestOutput): TestOutput {
|
|||||||
* Run the CLI in this same process, by calling the run() function in `app.ts`.
|
* Run the CLI in this same process, by calling the run() function in `app.ts`.
|
||||||
* @param cmd Command to execute, e.g. `push myApp` (without 'balena' prefix)
|
* @param cmd Command to execute, e.g. `push myApp` (without 'balena' prefix)
|
||||||
*/
|
*/
|
||||||
async function runCommanInProcess(cmd: string): Promise<TestOutput> {
|
async function runCommandInProcess(cmd: string): Promise<TestOutput> {
|
||||||
const preArgs = [process.argv[0], path.join(process.cwd(), 'bin', 'balena')];
|
const preArgs = [process.argv[0], path.join(process.cwd(), 'bin', 'balena')];
|
||||||
|
|
||||||
const err: string[] = [];
|
const err: string[] = [];
|
||||||
@ -199,7 +199,7 @@ export async function runCommand(cmd: string): Promise<TestOutput> {
|
|||||||
const [proxyPort] = await proxy.createProxyServerOnce();
|
const [proxyPort] = await proxy.createProxyServerOnce();
|
||||||
return runCommandInSubprocess(cmd, proxyPort);
|
return runCommandInSubprocess(cmd, proxyPort);
|
||||||
} else {
|
} else {
|
||||||
return runCommanInProcess(cmd);
|
return runCommandInProcess(cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
typings/capitano/index.d.ts
vendored
2
typings/capitano/index.d.ts
vendored
@ -82,7 +82,7 @@ declare module 'capitano' {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export function run(
|
export function run(
|
||||||
command: string,
|
command: string | string[],
|
||||||
callback: (err: Error | null, result: any) => void,
|
callback: (err: Error | null, result: any) => void,
|
||||||
): void;
|
): void;
|
||||||
export function execute(
|
export function execute(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user