1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 16:53:34 +00:00

[deps] Vault: Update commander to v11 (#7329)

* [deps] Vault: Update commander to v11

* [deps] Vault: Update commander to v11

* [deps] Vault: Update commander to v11

* [deps] Vault: Update commander to v11

* removed unused interfaces

* fix shell completions (#7756)

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: gbubemismith <gsmithwalter@gmail.com>
Co-authored-by: tangowithfoxtrot <5676771+tangowithfoxtrot@users.noreply.github.com>
Co-authored-by: SmithThe4th <gsmith@bitwarden.com>
This commit is contained in:
renovate[bot]
2024-01-31 17:17:04 -05:00
committed by GitHub
parent 01781848f3
commit 83812d471c
15 changed files with 152 additions and 212 deletions

View File

@@ -1,25 +1,12 @@
import * as program from "commander";
import { program, OptionValues, Command } from "commander";
import { Response } from "../models/response";
import { MessageResponse } from "../models/response/message.response";
interface IOption {
long?: string;
short?: string;
description: string;
}
interface ICommand {
commands?: ICommand[];
options?: IOption[];
_name: string;
_description: string;
}
const validShells = ["zsh"];
export class CompletionCommand {
async run(options: program.OptionValues) {
async run(options: OptionValues) {
const shell: (typeof validShells)[number] = options.shell;
if (!shell) {
@@ -33,14 +20,14 @@ export class CompletionCommand {
let content = "";
if (shell === "zsh") {
content = this.zshCompletion("bw", program as any as ICommand).render();
content = this.zshCompletion("bw", program).render();
}
const res = new MessageResponse(content, null);
return Response.success(res);
}
private zshCompletion(rootName: string, rootCommand: ICommand) {
private zshCompletion(rootName: string, rootCommand: Command) {
return {
render: () => {
return [
@@ -52,7 +39,7 @@ export class CompletionCommand {
};
}
private renderCommandBlock(name: string, command: ICommand): string {
private renderCommandBlock(name: string, command: Command): string {
const { commands = [], options = [] } = command;
const hasOptions = options.length > 0;
const hasCommands = commands.length > 0;
@@ -89,18 +76,19 @@ export class CompletionCommand {
cmnds)
commands=(
${commands
.map(({ _name, _description }) => `"${_name}:${_description}"`)
.map((command) => `"${command.name().split(" ")[0]}:${command.description()}"`)
.join("\n ")}
)
_describe "command" commands
;;
esac
;;\n esac
case "$words[1]" in
${commands
.map(({ _name }) => [`${_name})`, `_${name}_${_name}`, ";;"].join("\n "))
.join("\n ")}
esac`,
.map((command) => {
const commandName = command.name().split(" ")[0];
return [`${commandName})`, `_${name}_${commandName}`, ";;"].join("\n ");
})
.join("\n ")}\n esac`,
);
}
@@ -110,7 +98,7 @@ export class CompletionCommand {
if (hasCommands) {
commandBlocParts.push(
commands.map((c) => this.renderCommandBlock(`${name}_${c._name}`, c)).join("\n\n"),
commands.map((c) => this.renderCommandBlock(`${name}_${c.name()}`, c)).join("\n\n"),
);
}