Skip to content

Commit

Permalink
implement proper --version command
Browse files Browse the repository at this point in the history
  • Loading branch information
seveibar committed Mar 18, 2024
1 parent d07e091 commit b0717f7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
6 changes: 6 additions & 0 deletions lib/cmd-fns/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { AppContext } from "lib/util/app-context"
import packageJson from "./../../package.json"

export const versionCmd = async (ctx: AppContext, args: any) => {
console.log(`tsci v${packageJson.version}`)
}
4 changes: 1 addition & 3 deletions lib/get-program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,7 @@ export const getProgram = (ctx: AppContext) => {
.option("--lock", "Lock the release after publishing to prevent changes")
.action((args) => CMDFN.publish(ctx, args))

cmd
.command("version")
.action(() => console.log(`tsci v${packageJson.version}`))
cmd.command("version").action(() => CMDFN.version(ctx, args))

cmd.command("login").action((args) => CMDFN.authLogin(ctx, args))
cmd.command("logout").action((args) => CMDFN.authLogout(ctx, args))
Expand Down
6 changes: 6 additions & 0 deletions lib/util/create-context-and-run-program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import kleur from "kleur"
import { PARAM_HANDLERS_BY_PARAM_NAME } from "lib/param-handlers"
import { createConfigHandler } from "lib/create-config-manager"
import dargs from "dargs"
import { versionCmd } from "lib/cmd-fns/version"

export type CliArgs = {
cmd: string[]
Expand Down Expand Up @@ -112,6 +113,11 @@ export const createContextAndRunProgram = async (process_args: any) => {
const { _: positional, ...flagsAndParams } = args
const args_without_globals = positional.concat(dargs(flagsAndParams))

if (args["version"] && args._.length === 2) {
await versionCmd(ctx, {})
process.exit(0)
}

await perfectCli(getProgram(ctx), args_without_globals, {
async customParamHandler({ commandPath, optionName }, { prompts }) {
const optionNameHandler =
Expand Down

0 comments on commit b0717f7

Please sign in to comment.