Skip to content

Commit

Permalink
add vertical command: handle page and template namess with spaces in …
Browse files Browse the repository at this point in the history
…them (#988)

When calling spawn sync, in order for an argument with a space in it to be
recognized as a single argument, it must be wrapped in quotes. Otherwise, the
later parts of the argument will be considered unknown arguments.
For example, if I run

`npx jambo [COMMAND] --name Blog Article --template vertical-standard`

the "Article" part of Blog Article will be considered a separate argument from
--name=Blog. Instead, it needs to be

`npx jambo [COMMAND] --name 'Blog Article' --template vertical-standard`

I also added an error message if a user tries to use a verticalKey or page name that contains
a quote. This was not working previously, I wouldn't want it to be ambiguous as to whether this was
ever supported.

J=TECHOPS-2502
TEST=manual

test adding a vertical, with and without a space
verify that the arguments passed to the add vertical command in CBD through the SGS UI is
the same as the way I tested locally
  • Loading branch information
oshi97 authored Oct 26, 2021
1 parent 6327a2d commit 2ff7073
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion commands/addvertical.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@ class VerticalAdder {
* @param {Object} args The command parameters.
*/
_validateArgs(args) {
function throwIfQuotesFound(argName) {
if (args[argName].includes(`'`) || args[argName].includes(`"`)) {
throw new UserError(`Quotes are not allowed for the "${argName}" argument.`);
}
}
throwIfQuotesFound('name');
throwIfQuotesFound('verticalKey');
if (args.template === 'universal-standard') {
throw new UserError('A vertical cannot be initialized with the universal template');
}
Expand Down Expand Up @@ -256,7 +263,7 @@ class VerticalAdder {
* @param {Array<string>} locales The additional locales to generate the page for.
*/
_createVerticalPage(name, template, locales) {
const args = ['--name', name, '--template', template];
const args = ['--name', `'${name}'`, '--template', `'${template}'`];

if (locales.length) {
args.push('--locales', locales.join(' '));
Expand Down

0 comments on commit 2ff7073

Please sign in to comment.