Skip to content

Commit

Permalink
fix: allow quoted values in terminal to work as expected
Browse files Browse the repository at this point in the history
  • Loading branch information
dillionmegida committed Apr 18, 2020
1 parent 201f6c3 commit d30d4f9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const {
requireValueMsg,
} = require("./utils");
const commands = require("./commands");
const { pkgName } = require("./config");

/**
* Print real git command to the terminal and execute it
Expand Down Expand Up @@ -85,8 +84,17 @@ module.exports = (command, options) => {
}
}

// this line is important because, if this package does not know that a value is required
// a command like branch yo will throw a warning, saying this package does not recognize yo
// yo is seen as a command. But with acceptValue, yo is seen as a value
if (commandObject.acceptValue) {
const [...values] = options;
let [...values] = options;
values = values.map((value) => {
if (value.split(" ").length > 1) {
// then a connected string like "hello hi" is used
return `\"${value}\"`;
} else return value;
});
fullCommand += ` ${values.join(" ")}`;
return showGitAndExecute(fullCommand);
}
Expand Down
21 changes: 19 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,25 @@ const showGitCommand = (command) =>

const execCommand = async (command) => {
const package = command.split(" ")[0];
commandOptions = command.replace(`${package} `, "").split(" ");
spawnSync(package, commandOptions, {
let commandOptions = command.replace(`${package} `, "").split(" ");
let commandOptionsFormatted = [];
let i = 0;

// command options needs to be formmatted for cases where a two words are joined together with quotes
while (i < commandOptions.length) {
if (commandOptions[i].startsWith('"')) {
let l = "";
while (!l.endsWith('"')) {
l += ` ${commandOptions[i]}`;
i++;
}
commandOptionsFormatted.push(l);
} else {
commandOptionsFormatted.push(commandOptions[i]);
}
i++;
}
spawnSync(package, commandOptionsFormatted, {
stdio: "inherit",
});
process.exit(0);
Expand Down

0 comments on commit d30d4f9

Please sign in to comment.