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:
Scott Lowe 2020-07-03 10:05:40 +02:00
parent d4c513fd41
commit e20265518d
5 changed files with 23 additions and 17 deletions

View File

@ -144,28 +144,34 @@ export default class DeviceInitCmd extends Command {
async downloadOsImage(path: string, deviceType: string, options: FlagsDef) {
const osVersion = options['os-version'] || 'default';
await runCommand(
`os download ${deviceType} --output '${path}' --version ${osVersion}`,
);
await runCommand([
'os',
'download',
deviceType,
'--output',
path,
'--version',
osVersion,
]);
}
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) {
configureCommand += ` --config ${options.config}`;
configureCommand.push('--config', options.config);
} else if (options.advanced) {
configureCommand += ' --advanced';
configureCommand.push('--advanced');
}
await runCommand(configureCommand);
}
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) {
osInitCommand += ' --yes';
osInitCommand.push('--yes');
}
if (options.drive) {
osInitCommand += ` --drive ${options.drive}`;
osInitCommand.push('--drive', options.drive);
}
await runCommand(osInitCommand);
}

View File

@ -217,10 +217,11 @@ Examples:
const { uuid } = await config.read(drive, options.type);
await umountAsync(drive);
let configureCommand = `os configure ${drive} --device ${uuid}`;
let configureCommand = ['os', 'configure', drive, '--device', uuid];
if (options.advanced) {
configureCommand += ' --advanced';
configureCommand.push('--advanced');
}
const { runCommand } = await import('../utils/helpers');
await runCommand(configureCommand);

View File

@ -96,8 +96,7 @@ export async function sudo(
await executeWithPrivileges(command, stderr, isCLIcmd);
}
export function runCommand<T>(command: string): Promise<T> {
let commandArgs = command.split(' ');
export function runCommand<T>(commandArgs: string[]): Promise<T> {
const [isOclif, isOclifTopic] = isOclifCommand(commandArgs);
if (isOclif) {
if (isOclifTopic) {
@ -115,7 +114,7 @@ export function runCommand<T>(command: string): Promise<T> {
require('../app-capitano');
const capitanoRunAsync = promisify(capitano.run);
return capitanoRunAsync(command);
return capitanoRunAsync(commandArgs);
}
}

View File

@ -61,7 +61,7 @@ function filterCliOutputForTests(testOutput: TestOutput): TestOutput {
* 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)
*/
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 err: string[] = [];
@ -199,7 +199,7 @@ export async function runCommand(cmd: string): Promise<TestOutput> {
const [proxyPort] = await proxy.createProxyServerOnce();
return runCommandInSubprocess(cmd, proxyPort);
} else {
return runCommanInProcess(cmd);
return runCommandInProcess(cmd);
}
}

View File

@ -82,7 +82,7 @@ declare module 'capitano' {
};
export function run(
command: string,
command: string | string[],
callback: (err: Error | null, result: any) => void,
): void;
export function execute(