Skip to content

Commit

Permalink
fix(cli-server), parse string arguments correctly (#9087)
Browse files Browse the repository at this point in the history
Fixing a bug when an arg was entered as a string (e.g. `bit snap -m
'some message'`, the string was split into multiple args instead of
treating it as one argument.
  • Loading branch information
davidfirst authored Aug 5, 2024
1 parent 44e0b58 commit cdf3660
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
7 changes: 4 additions & 3 deletions scopes/harmony/api-server/cli-raw.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,22 @@ export class CLIRawRoute implements Route {
}

const randomNumber = Math.floor(Math.random() * 10000); // helps to distinguish between commands in the log
const cmdStrLog = `${randomNumber} ${command}`;
const commandStr = command.join(' ');
const cmdStrLog = `${randomNumber} ${commandStr}`;
await this.apiForIDE.logStartCmdHistory(cmdStrLog);
legacyLogger.isDaemon = true;
enableChalk();
const cliParser = new CLIParser(this.cli.commands, this.cli.groups, this.cli.onCommandStartSlot);
try {
const commandRunner = await cliParser.parse(command.split(' '));
const commandRunner = await cliParser.parse(command);
const result = await commandRunner.runCommand(true);
await this.apiForIDE.logFinishCmdHistory(cmdStrLog, 0);
res.json(result);
} catch (err: any) {
if (err instanceof YargsExitWorkaround) {
res.json({ data: err.helpMsg, exitCode: err.exitCode });
} else {
this.logger.error(`cli-raw server: got an error for ${command}`, err);
this.logger.error(`cli-raw server: got an error for ${commandStr}`, err);
await this.apiForIDE.logFinishCmdHistory(cmdStrLog, 1);
res.status(500);
res.jsonp({
Expand Down
5 changes: 2 additions & 3 deletions scopes/harmony/bit/server-commander.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,9 @@ export class ServerCommander {
if (!args.includes('--json') && !args.includes('-j')) {
loader.on();
}
const command = args.join(' ');
const endpoint = `cli-raw`;
const pwd = process.cwd();
const body = { command, pwd };
const body = { command: args, pwd };
let res;
try {
res = await fetch(`${url}/${endpoint}`, {
Expand All @@ -74,7 +73,7 @@ export class ServerCommander {
await this.deleteServerPortFile();
throw new ServerNotFound(port);
}
throw new Error(`failed to run command "${command}" on the server. ${err.message}`);
throw new Error(`failed to run command "${args.join(' ')}" on the server. ${err.message}`);
}

if (res.ok) {
Expand Down

0 comments on commit cdf3660

Please sign in to comment.