Skip to content

Commit

Permalink
fix(command): single quotes in option description breaks fish complet…
Browse files Browse the repository at this point in the history
…ions (#518)
  • Loading branch information
c4spar committed Dec 19, 2022
1 parent eb53cd2 commit c09c74a
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 98 deletions.
4 changes: 3 additions & 1 deletion command/_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,7 @@ export function getDescription(
description: string,
short?: boolean,
): string {
return short ? description.trim().split("\n", 1)[0] : dedent(description);
return short
? description.trim().split("\n", 1)[0].trim()
: dedent(description);
}
12 changes: 10 additions & 2 deletions command/completions/_fish_completions_generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,20 @@ ${this.generateCompletions(this.cmd).trim()}`;
options.standalone && cmd.push("-x");
cmd.push("-k");
cmd.push("-f");

if (options.arguments) {
options.required && cmd.push("-r");
cmd.push("-a", options.arguments);
}
options.description &&
cmd.push("-d", `'${getDescription(options.description, true)}'`);

if (options.description) {
const description: string = getDescription(options.description, true)
// escape single quotes
.replace(/'/g, "\\'");

cmd.push("-d", `'${description}'`);
}

return cmd.join(" ");
}

Expand Down

0 comments on commit c09c74a

Please sign in to comment.