Skip to content

Commit

Permalink
Log OSDK CLI version on start of CLI (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
zeyadkhaled authored Feb 15, 2024
1 parent f89a9c6 commit 6702612
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
5 changes: 5 additions & 0 deletions packages/cli/changelog/@unreleased/pr-70.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Log OSDK CLI version on start of CLI
links:
- https://github.com/palantir/osdk-ts/pull/70
8 changes: 6 additions & 2 deletions packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ import site from "./commands/site/index.js";
import typescript from "./commands/typescript/index.js";
import { ExitProcessError } from "./ExitProcessError.js";
import { logConfigFileMiddleware } from "./yargs/logConfigFileMiddleware.js";
import { logVersionMiddleware } from "./yargs/logVersionMiddleware.js";
import { logLevelMiddleware } from "./yargs/logLevelMiddleware.js";
import { YargsCheckError } from "./YargsCheckError.js";

export async function cli(args: string[] = process.argv) {
consola.info(
`Palantir OSDK CLI ${process.env.PACKAGE_VERSION}\n`,
);

const base: Argv<CliCommonArgs> = yargs(hideBin(args))
.wrap(Math.min(150, yargs().terminalWidth()))
.env("OSDK")
Expand All @@ -43,7 +47,7 @@ export async function cli(args: string[] = process.argv) {
},
)
.demandCommand()
.middleware(logVersionMiddleware, true)
.middleware(logLevelMiddleware, true)
.middleware(logConfigFileMiddleware)
.strict()
.command({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,17 @@ import { consola } from "consola";
import type { CliCommonArgs } from "../CliCommonArgs.js";

let firstTime = true;
export async function logVersionMiddleware(args: CliCommonArgs) {
export async function logLevelMiddleware(args: CliCommonArgs) {
if (firstTime) {
firstTime = false;
// This will be called before any command is executed
consola.info(
`Palantir OSDK CLI ${process.env.PACKAGE_VERSION}`,
);

consola.level = 3 + args.verbose; // so 1 -v is debug logs and -vv is trace
if (consola.level > 3) {
consola.debug(
`Verbose logging enabled (${consola.level === 4 ? "debug" : "trace"})`,
`Verbose logging enabled (${
consola.level === 4 ? "debug" : "trace"
})\n`,
);
}

consola.log(""); // intentional blank line
}
}

0 comments on commit 6702612

Please sign in to comment.