Skip to content

Commit

Permalink
[deps] Vault: Update commander to v11 (#7329)
Browse files Browse the repository at this point in the history
* [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 <[email protected]>
Co-authored-by: tangowithfoxtrot <[email protected]>
Co-authored-by: SmithThe4th <[email protected]>
  • Loading branch information
4 people authored Jan 31, 2024
1 parent 0178184 commit 83812d4
Show file tree
Hide file tree
Showing 15 changed files with 152 additions and 212 deletions.
2 changes: 1 addition & 1 deletion apps/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"big-integer": "1.6.51",
"browser-hrtime": "1.1.8",
"chalk": "4.1.2",
"commander": "7.2.0",
"commander": "11.1.0",
"form-data": "4.0.0",
"https-proxy-agent": "7.0.2",
"inquirer": "8.2.6",
Expand Down
6 changes: 3 additions & 3 deletions apps/cli/src/auth/commands/login.command.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as http from "http";

import * as program from "commander";
import { OptionValues } from "commander";
import * as inquirer from "inquirer";
import Separator from "inquirer/lib/objects/separator";
import { firstValueFrom } from "rxjs";
Expand Down Expand Up @@ -47,7 +47,7 @@ export class LoginCommand {
protected email: string;

private ssoRedirectUri: string = null;
private options: program.OptionValues;
private options: OptionValues;

constructor(
protected authService: AuthService,
Expand All @@ -68,7 +68,7 @@ export class LoginCommand {
protected logoutCallback: () => Promise<void>,
) {}

async run(email: string, password: string, options: program.OptionValues) {
async run(email: string, password: string, options: OptionValues) {
this.options = options;
this.email = email;

Expand Down
2 changes: 1 addition & 1 deletion apps/cli/src/bw.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as fs from "fs";
import * as path from "path";

import * as program from "commander";
import { program } from "commander";
import * as jsdom from "jsdom";

import { PinCryptoServiceAbstraction, PinCryptoService } from "@bitwarden/auth/common";
Expand Down
38 changes: 13 additions & 25 deletions apps/cli/src/commands/completion.command.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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 [
Expand All @@ -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;
Expand Down Expand Up @@ -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`,
);
}

Expand All @@ -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"),
);
}

Expand Down
6 changes: 3 additions & 3 deletions apps/cli/src/commands/config.command.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as program from "commander";
import { OptionValues } from "commander";

import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";

Expand All @@ -9,7 +9,7 @@ import { StringResponse } from "../models/response/string.response";
export class ConfigCommand {
constructor(private environmentService: EnvironmentService) {}

async run(setting: string, value: string, options: program.OptionValues): Promise<Response> {
async run(setting: string, value: string, options: OptionValues): Promise<Response> {
setting = setting.toLowerCase();
switch (setting) {
case "server":
Expand All @@ -19,7 +19,7 @@ export class ConfigCommand {
}
}

private async getOrSetServer(url: string, options: program.OptionValues): Promise<Response> {
private async getOrSetServer(url: string, options: OptionValues): Promise<Response> {
if (
(url == null || url.trim() === "") &&
!options.webVault &&
Expand Down
4 changes: 2 additions & 2 deletions apps/cli/src/commands/serve.command.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as koaMulter from "@koa/multer";
import * as koaRouter from "@koa/router";
import * as program from "commander";
import { OptionValues } from "commander";
import * as koa from "koa";
import * as koaBodyParser from "koa-bodyparser";
import * as koaJson from "koa-json";
Expand Down Expand Up @@ -164,7 +164,7 @@ export class ServeCommand {
);
}

async run(options: program.OptionValues) {
async run(options: OptionValues) {
const protectOrigin = !options.disableOriginProtection;
const port = options.port || 8087;
const hostname = options.hostname || "localhost";
Expand Down
6 changes: 3 additions & 3 deletions apps/cli/src/program.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as chalk from "chalk";
import * as program from "commander";
import { program, Command, OptionValues } from "commander";

import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";

Expand Down Expand Up @@ -135,7 +135,7 @@ export class Program {
writeLn(" bw login --sso");
writeLn("", true);
})
.action(async (email: string, password: string, options: program.OptionValues) => {
.action(async (email: string, password: string, options: OptionValues) => {
if (!options.check) {
await this.exitIfAuthed();
const command = new LoginCommand(
Expand Down Expand Up @@ -427,7 +427,7 @@ export class Program {
writeLn(" bw completion --shell zsh");
writeLn("", true);
})
.action(async (options: program.OptionValues, cmd: program.Command) => {
.action(async (options: OptionValues, cmd: Command) => {
const command = new CompletionCommand();
const response = await command.run(options);
this.processResponse(response);
Expand Down
6 changes: 3 additions & 3 deletions apps/cli/src/tools/export.command.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as program from "commander";
import { OptionValues } from "commander";
import * as inquirer from "inquirer";

import { EventCollectionService } from "@bitwarden/common/abstractions/event/event-collection.service";
Expand All @@ -22,7 +22,7 @@ export class ExportCommand {
private eventCollectionService: EventCollectionService,
) {}

async run(options: program.OptionValues): Promise<Response> {
async run(options: OptionValues): Promise<Response> {
if (
options.organizationid == null &&
(await this.policyService.policyAppliesToUser(PolicyType.DisablePersonalVaultExport))
Expand Down Expand Up @@ -79,7 +79,7 @@ export class ExportCommand {

private async saveFile(
exportContent: string,
options: program.OptionValues,
options: OptionValues,
format: ExportFormat,
): Promise<Response> {
try {
Expand Down
8 changes: 2 additions & 6 deletions apps/cli/src/tools/import.command.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as program from "commander";
import { OptionValues } from "commander";
import * as inquirer from "inquirer";

import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
Expand All @@ -16,11 +16,7 @@ export class ImportCommand {
private syncService: SyncService,
) {}

async run(
format: ImportType,
filepath: string,
options: program.OptionValues,
): Promise<Response> {
async run(format: ImportType, filepath: string, options: OptionValues): Promise<Response> {
const organizationId = options.organizationid;
if (organizationId != null) {
const organization = await this.organizationService.getFromState(organizationId);
Expand Down
4 changes: 2 additions & 2 deletions apps/cli/src/tools/send/commands/get.command.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as program from "commander";
import { OptionValues } from "commander";

import { SearchService } from "@bitwarden/common/abstractions/search.service";
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
Expand All @@ -21,7 +21,7 @@ export class SendGetCommand extends DownloadCommand {
super(cryptoService);
}

async run(id: string, options: program.OptionValues) {
async run(id: string, options: OptionValues) {
const serveCommand = process.env.BW_SERVE === "true";
if (serveCommand && !Utils.isGuid(id)) {
return Response.badRequest("`" + id + "` is not a GUID.");
Expand Down
4 changes: 2 additions & 2 deletions apps/cli/src/tools/send/commands/receive.command.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as program from "commander";
import { OptionValues } from "commander";
import * as inquirer from "inquirer";

import { ApiService } from "@bitwarden/common/abstractions/api.service";
Expand Down Expand Up @@ -36,7 +36,7 @@ export class SendReceiveCommand extends DownloadCommand {
super(cryptoService);
}

async run(url: string, options: program.OptionValues): Promise<Response> {
async run(url: string, options: OptionValues): Promise<Response> {
this.canInteract = process.env.BW_NOINTERACTION !== "true";

let urlObject: URL;
Expand Down
Loading

0 comments on commit 83812d4

Please sign in to comment.