Skip to content

Commit

Permalink
feat(command): show long version format with long --version option (#343
Browse files Browse the repository at this point in the history
)
  • Loading branch information
c4spar committed Apr 6, 2022
1 parent bc9cfbf commit 079b4ba
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
28 changes: 25 additions & 3 deletions command/command.ts
Expand Up @@ -11,7 +11,7 @@ import type {
IFlagsResult,
} from "../flags/types.ts";
import { parseArgumentsDefinition, splitArguments } from "./_utils.ts";
import { bold, red, yellow } from "./deps.ts";
import { blue, bold, red, yellow } from "./deps.ts";
import {
CommandExecutableNotFound,
CommandNotFound,
Expand Down Expand Up @@ -1198,13 +1198,20 @@ export class Command<
{
standalone: true,
prepend: true,
action: function () {
this.showVersion();
action: async function () {
const long = this.getRawArgs().includes(`--${versionOption.name}`);
if (long) {
await this.checkVersion();
this.showLongVersion();
} else {
this.showVersion();
}
this.exit();
},
...(this._versionOption?.opts ?? {}),
},
);
const versionOption = this.options[0];
}

if (this._helpOption !== false) {
Expand Down Expand Up @@ -1581,6 +1588,21 @@ export class Command<
console.log(this.getVersion());
}

/** Returns command name, version and meta data. */
public getLongVersion(): string {
return `${bold(this.getMainCommand().getName())} ${
blue(this.getVersion() ?? "")
}` +
Object.entries(this.getMeta()).map(
([k, v]) => `\n${bold(k)} ${blue(v)}`,
).join("");
}

/** Outputs command name, version and meta data. */
public showLongVersion(): void {
console.log(this.getLongVersion());
}

/** Output generated help without exiting. */
public showHelp(options?: HelpOptions): void {
console.log(this.getHelp(options));
Expand Down
5 changes: 4 additions & 1 deletion command/test/integration/fixtures/version_option_long.out
@@ -1 +1,4 @@
1.0.0
completions-test 1.0.0
meta1 value1
meta2 value2
meta3 value3

0 comments on commit 079b4ba

Please sign in to comment.