Skip to content

Commit

Permalink
fix(command): zsh completion values not separated by new line (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
c4spar committed Oct 10, 2020
1 parent e0093b7 commit a89ccc6
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 12 deletions.
2 changes: 1 addition & 1 deletion command/completions/_bash_completions_generator.ts
Expand Up @@ -29,7 +29,7 @@ _${replaceSpecialChars(path)}() {
_${replaceSpecialChars(this.cmd.getName())}_complete() {
local action="$1"; shift
mapfile -t values < <( ${this.cmd.getName()} completions complete -l "\${action}" "\${@}" )
mapfile -t values < <( ${this.cmd.getName()} completions complete "\${action}" "\${@}" )
for i in "\${values[@]}"; do
opts+=("$i")
done
Expand Down
2 changes: 1 addition & 1 deletion command/completions/_fish_completions_generator.ts
Expand Up @@ -138,7 +138,7 @@ ${this.generateCompletions(this.cmd).trim()}
}

private getCompletionCommand(cmd: string): string {
return `'(${this.cmd.getName()} completions complete -l ${cmd.trim()})'`;
return `'(${this.cmd.getName()} completions complete ${cmd.trim()})'`;
}
}

Expand Down
12 changes: 2 additions & 10 deletions command/completions/complete.ts
Expand Up @@ -9,25 +9,20 @@ export class CompleteCommand extends Command {
super();
this.description("Get completions for given action from given command.")
.arguments("<action:string> [command...:string]")
.option("-l, --list", "Use line break as value separator.")
.action(
async (
{ list }: { list?: boolean },
// deno-lint-ignore no-undef
_,
action: string,
// deno-lint-ignore no-undef
commandNames: string[],
) => {
let parent: Command | undefined;
// deno-lint-ignore no-undef
const completeCommand: Command = commandNames
.reduce((cmd: Command, name: string): Command => {
parent = cmd;
const childCmd: Command | undefined = cmd.getCommand(name, false);
if (!childCmd) {
throw new Error(
`Auto-completion failed. Command not found: ${
// deno-lint-ignore no-undef
commandNames.join(" ")
}`,
);
Expand All @@ -36,15 +31,12 @@ export class CompleteCommand extends Command {
}, cmd || this.getMainCommand());

const completion: ICompletion | undefined = completeCommand
// deno-lint-ignore no-undef
.getCompletion(action);
const result: string[] =
await completion?.complete(completeCommand, parent) ?? [];

if (result?.length) {
Deno.stdout.writeSync(new TextEncoder().encode(result.join(
list ? "\n" : " ",
)));
Deno.stdout.writeSync(new TextEncoder().encode(result.join("\n")));
}
},
)
Expand Down

0 comments on commit a89ccc6

Please sign in to comment.