diff --git a/lib/actions-oclif/device/init.ts b/lib/actions-oclif/device/init.ts index 2903ed7d..25134eeb 100644 --- a/lib/actions-oclif/device/init.ts +++ b/lib/actions-oclif/device/init.ts @@ -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); } diff --git a/lib/actions/config.js b/lib/actions/config.js index 67a0399c..da327804 100644 --- a/lib/actions/config.js +++ b/lib/actions/config.js @@ -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); diff --git a/lib/utils/helpers.ts b/lib/utils/helpers.ts index bf7c0b1f..6e6b1a9f 100644 --- a/lib/utils/helpers.ts +++ b/lib/utils/helpers.ts @@ -96,8 +96,7 @@ export async function sudo( await executeWithPrivileges(command, stderr, isCLIcmd); } -export function runCommand(command: string): Promise { - let commandArgs = command.split(' '); +export function runCommand(commandArgs: string[]): Promise { const [isOclif, isOclifTopic] = isOclifCommand(commandArgs); if (isOclif) { if (isOclifTopic) { @@ -115,7 +114,7 @@ export function runCommand(command: string): Promise { require('../app-capitano'); const capitanoRunAsync = promisify(capitano.run); - return capitanoRunAsync(command); + return capitanoRunAsync(commandArgs); } } diff --git a/tests/helpers.ts b/tests/helpers.ts index 88793be1..b289e977 100644 --- a/tests/helpers.ts +++ b/tests/helpers.ts @@ -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 { +async function runCommandInProcess(cmd: string): Promise { 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 { const [proxyPort] = await proxy.createProxyServerOnce(); return runCommandInSubprocess(cmd, proxyPort); } else { - return runCommanInProcess(cmd); + return runCommandInProcess(cmd); } } diff --git a/typings/capitano/index.d.ts b/typings/capitano/index.d.ts index 70212ea9..7682479c 100644 --- a/typings/capitano/index.d.ts +++ b/typings/capitano/index.d.ts @@ -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(