Skip to content

Commit

Permalink
verbose
Browse files Browse the repository at this point in the history
  • Loading branch information
ComradeVanti committed Sep 17, 2024
1 parent 8de27ea commit 7bc5023
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 42 deletions.
14 changes: 12 additions & 2 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createCommand } from "@commander-js/extra-typings";
import { createCommand, Option } from "@commander-js/extra-typings";
import type { Logger } from "npmlog";
import pkginfo from "pkginfo";
import type { DebugLog } from "../domain/logging";
Expand All @@ -18,6 +18,11 @@ import { makeRemoveCmd } from "./cmd-remove";
import { makeSearchCmd } from "./cmd-search";
import { makeViewCmd } from "./cmd-view";

const verboseOpt = new Option(
"-v, --verbose",
"output extra debugging"
).default(false);

/**
* Makes the openupm cli app with the given dependencies.
* @param fetchPackument IO function for fetching registry packuments.
Expand All @@ -43,11 +48,16 @@ export function makeOpenupmCli(
pkginfo(module);
const program = createCommand()
.version(module.exports.version)
.option("-v, --verbose", "output extra debugging")
.addOption(verboseOpt)
.option("--system-user", "auth for Windows system user")
.option("--no-upstream", "don't use upstream unity registry")
.option("--no-color", "disable color");

program.on("option:verbose", function () {
const verbose = program.opts().verbose;
log.level = verbose ? "verbose" : "notice";
});

program.addCommand(
makeAddCmd(
fetchCheckUrlExists,
Expand Down
4 changes: 0 additions & 4 deletions src/cli/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
* Options which are shared between commands.
*/
export type GlobalOptions = Readonly<{
/**
* Whether to print logs.
*/
verbose?: boolean;
/**
* Whether to use color in the console.
*/
Expand Down
11 changes: 0 additions & 11 deletions src/cli/parse-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@ export type Env = Readonly<{
upstream: boolean;
}>;

/**
* Determines which log level to use for output.
* @param options Cmd options.
*/
export function determineLogLevel(options: CmdOptions): "verbose" | "notice" {
return options.verbose ? "verbose" : "notice";
}

/**
* Determines whether to use color for output.
* @param envVars Environment variables.
Expand Down Expand Up @@ -73,9 +65,6 @@ export async function parseEnvUsing(
envVars: Record<string, string | undefined>,
options: CmdOptions
): Promise<Env> {
// log level
log.level = determineLogLevel(options);

// color
const useColor = determineUseColor(envVars, options);
if (!useColor) {
Expand Down
25 changes: 0 additions & 25 deletions test/unit/cli/parse-env.test.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,10 @@
import {
determineIsSystemUser,
determineLogLevel,
determineUseColor,
determineUseUpstream,
} from "../../../src/cli/parse-env";

describe("parse env", () => {
describe("log-level", () => {
it("should be verbose if verbose option is true", () => {
const actual = determineLogLevel({
verbose: true,
});

expect(actual).toEqual("verbose");
});

it("should be notice if verbose option is false", () => {
const actual = determineLogLevel({
verbose: false,
});

expect(actual).toEqual("notice");
});

it("should be notice if verbose option is missing", () => {
const actual = determineLogLevel({});

expect(actual).toEqual("notice");
});
});

describe("color", () => {
it("should use color if color option is true", () => {
const actual = determineUseColor(
Expand Down

0 comments on commit 7bc5023

Please sign in to comment.