Skip to content

fix(cli): print the version for --version and -v - #354

Merged
theCodeDrift merged 2 commits into
mainfrom
fix/version-flag
Sep 21, 2026
Merged

theCodeDrift merged 2 commits into
mainfrom
fix/version-flag

Conversation

@theCodeDrift

Copy link
Copy Markdown
Member

What

taskless --version and taskless -v print the version followed by a newline on stdout and exit 0. Both flags are listed under OPTIONS in the root --help. The flag answers from any position, so taskless check --version prints the version as well, mirroring how --help is resolved.

Why

packages/cli/src/index.ts runs the root command through citty's runCommand rather than runMain, on purpose, so the finally that emits the cli_run telemetry denominator still runs; --help was re-implemented in front of dispatch for that reason, but --version (the other flag runMain implements from meta.version) was not, so it reached the root command as an unknown flag and rendered the usage banner. -v was never a citty alias at all.

hasVersionFlag uses the same splitRawArguments scan as hasHelpFlag, so taskless -d -v check still names a directory and taskless check -- -v still names a path. Position is deliberately not consulted: the question is about the tool, not the subcommand, no subcommand defines -v or --version, and before this change check --version silently dropped the flag and ran a full check. The version path returns normally into the same finally, so cli_run is still counted; a test pins that alongside the existing help guard.

How verified

Measured on a fresh pnpm build of main (0.11.2) before the change:

$ node packages/cli/dist/index.js --version | wc -c
    2065
$ node packages/cli/dist/index.js -v | head -1
 Taskless CLI (taskless v0.11.2)
$ node packages/cli/dist/index.js check --version
No issues found.

After:

$ node packages/cli/dist/index.js --version; echo "exit=$?"
0.11.2
exit=0
$ node packages/cli/dist/index.js --version | wc -c
       7
$ node packages/cli/dist/index.js -v
0.11.2
$ node packages/cli/dist/index.js check --version
0.11.2
$ node packages/cli/dist/index.js --help | grep version
  `--allow-version-mismatches`    Proceed when .taskless/ is newer than this CLI understands (skips migrations)
               `-v, --version`    Print the version and exit

pnpm build, pnpm typecheck, pnpm lint, and pnpm --filter @taskless/cli test (95 files, 1541 tests) all pass. New tests live in packages/cli/test/version-flag.test.ts: exact <version>\n stdout for both flags with empty stderr, the subcommand-position case, the -- escape, the --help listing, the hasVersionFlag table, and the cli_run emission guard.

Fixes #352

@theCodeDrift

Copy link
Copy Markdown
Member Author

@claude /review

@claude

claude Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

Claude finished @theCodeDrift's task in 8m 10s —— View job


Review complete

Review mode: incremental — read 0 prior review thread(s) before reviewing. .prior-review.json contained one top-level comment (the @claude /review trigger itself) and no review threads or reviews, so this is the first review of this PR.

  • Read .prior-review.json (no prior findings to classify)
  • Fetch PR diff and metadata (gh pr diff 354, gh pr view 354)
  • Read changed files in full context (index.ts, util/argv.ts, util/help.ts, telemetry-run.ts, commands/check.ts, commands/info.ts, version.ts, wizard/intro.ts)
  • Run correctness / cleanup / conventions angles (line-by-line, removed-behavior, cross-file tracing, reuse/simplification, CLAUDE.md conventions)
  • Verify candidate findings (independent second pass + manual trace of splitRawArguments/hasVersionFlag)
  • Post inline comments and final summary

Assessment

Solid, well-scoped fix. The core mechanism — intercepting --version/-v before runCommand dispatch, mirroring the existing --help interception so the finally-block telemetry (cli_run) still fires — is correct and I traced it end-to-end: help wins over version when both are given, --version never reaches main.run()'s onlyInitFlags check, no subcommand defines a conflicting -v/--version alias, and the --/-d <value> scanning edge cases the new tests target (check -- -v, -d -v check) resolve the way the tests expect. Manual verification steps in the PR body match code behavior. The changeset is correctly patch for a pre-1.0 package per this repo's semver convention.

Posted 2 inline comments, both low-severity / plausible edge cases, not blocking:

  1. packages/cli/src/util/argv.ts — hasVersionFlag/hasHelpFlag don't know about subcommand-specific value-taking flags (e.g. check --timeout), so taskless check --timeout -v would version-intercept instead of passing -v through as --timeout's (malformed) value; also, --version=true isn't recognized since the match is an exact-string comparison. Both are edge cases largely inherited from the pre-existing hasHelpFlag pattern rather than newly introduced, but hasVersionFlag duplicates that pattern verbatim rather than sharing a helper — flagged as a simplification opportunity too.
  2. packages/cli/src/index.ts:167 — writes __VERSION__ directly instead of reusing the existing CLI_VERSION export from src/version.ts, which has a typeof-guarded fallback. Not a functional bug today (the same direct pattern already exists a few lines up in meta.version, and both build and test configs define __VERSION__), just a missed reuse.

No correctness bugs found in the interception logic, the hasVersionFlag/splitRawArguments scanning rules, the control-flow ordering (help → version → dispatch), or the telemetry/exit-code paths. Test coverage for the fixed defect (#352) is solid — the --version/-v exact-stdout assertions would catch a regression to the old fall-through behavior.

Comment thread packages/cli/src/index.ts
Comment thread packages/cli/src/util/argv.ts
@theCodeDrift

Copy link
Copy Markdown
Member Author

Re: @claude[bot] — "Claude finished @theCodeDrift's task in 8m 10s — Review complete…"
#354 (comment)

Read in full. The hasHelpFlag/hasVersionFlag duplication is folded into a shared hasFlag in 6b5239a; the --version=true point matches citty's own exact-token behaviour and is left as-is; the check --timeout -v case and the CLI_VERSION reuse nit are held open for the maintainer.

— AI Coding Agent

The entry runs the root command through citty's runCommand rather than
runMain so the finally that emits cli_run still runs, and --help was
re-implemented in front of dispatch for that reason. --version was not,
so it reached the root command as an unknown flag and rendered the usage
banner; -v was never an alias at all.

hasVersionFlag scans argv the way hasHelpFlag does, so a directory or a
path after -- that reads like -v is still a value, and the flag answers
from any position: taskless check --version prints the version instead
of silently dropping the flag and running check. The root args list
-v, --version so --help documents it.
…Flag

Both did the same splitRawArguments walk over different literals; a
private hasFlag carries the scan once and each keeps its own name.
@theCodeDrift
theCodeDrift merged commit 912767b into main Sep 21, 2026
4 checks passed
@theCodeDrift
theCodeDrift deleted the fix/version-flag branch September 21, 2026 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

taskless --version and -v print the usage banner instead of the version

1 participant