Skip to content

Add -V/--version and name the invoked command in the usage output - #593

Merged
bertysentry merged 3 commits into
mainfrom
cli-version-and-program-name
Aug 20, 2026
Merged

Add -V/--version and name the invoked command in the usage output#593
bertysentry merged 3 commits into
mainfrom
cli-version-and-program-name

Conversation

@bertysentry

Copy link
Copy Markdown
Contributor

Fixes#590, fixes#591.

-V / --version (#590)

A new standalone mode, recognized like -h only by itself and before the program text:

$ jawk --version
jawk 7.1.00
Java 25.0.3 (Eclipse Adoptium OpenJDK 64-Bit Server VM)
  • The version comes from the jar manifest's Implementation-Version, which maven-jar-plugin now generates via addDefaultImplementationEntries (the ManifestResourceTransformer carries it into the standalone jar). The Maven pom.properties resource is the fallback, and a plain class directory (IDE runs, unit tests) reports unknown. No build timestamp is involved, so the build stays reproducible.
  • Combined with any other argument it is rejected, like -h and --list-ext; after the program text it still flows to the script through ARGV, as gawk requires (covered by a test).
  • Documented in usage(), in the "Help and errors" group and the non-executing modes list of cli-reference.md, and in behavior-changes.md.

Usage names the invoked command (#591)

usage() now prefers the new JAWK_PROGRAM_NAME environment variable over its own jar file name, so the installed launcher's help matches what the user typed:

$ jawk -h
Usage:
jawk [-F fs_val] [-f script-filename] ...
jawk --list-ext
  • Both launchers pass their own invocation name (${0##*/} in the POSIX launcher, %~n0 in the jawk.cmd shim), on the -jar and the -cp (JAWK_CLASSPATH) invocations alike.
  • A direct java -jar jawk-x.y.z-standalone.jar -h keeps printing the java -jar ... form, which is correct for that invocation; a blank or unset variable falls back to it too.

Smoke tests

The installer workflow now asserts, on both the POSIX launcher and the Windows shim, that --version reports jawk <version> and that -h names jawk and never mentions java -jar. The steps probe with --version first, so they keep passing while the latest release predates the feature.

Verified end-to-end locally on both launchers (installer run into a scratch prefix, freshly built jar swapped in): --version, -h, plain one-liners, and the JAWK_CLASSPATH code path.

🤖 Generated with Claude Code

Two CLI reporting fixes:
- New -V/--version standalone mode: prints "jawk <version>" and the Java
runtime, then exits 0. The version comes from the jar manifest's
Implementation-Version (now generated via addDefaultImplementationEntries),
with the Maven pom.properties resource as fallback and "unknown" when
running from a plain class directory. Fixes#590.
- usage() now names the command Jawk was invoked as: the launchers written
by the one-command installers export their invocation name through the new
JAWK_PROGRAM_NAME environment variable, and the CLI falls back to the
"java -jar <jar>" form when the variable is not set, which stays correct
for direct jar invocations. Fixes#591.
The installer smoke tests assert both behaviors through the installed
launchers, probing with --version first so they keep passing against
releases that predate the feature.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@bertysentry

Copy link
Copy Markdown
ContributorAuthor

@codex please review

@chatgpt-codex-connectorchatgpt-codex-connectorBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit:123100a514

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +478 to +479
AwkTestSupport.TestResult result = AwkTestSupport
.cliTest("CLI --version prints the Jawk and Java versions")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Test non-script reporting modes without AwkTestSupport

These new --version tests—and the new help-output tests below—do not run an AWK script, but route through AwkTestSupport.cliTest. The repository explicitly limits that helper to executing AWK scripts and requires ordinary Java behavior to be exercised directly with plain JUnit assertions; instantiate Cli with captured streams and call parse/run directly instead.

AGENTS.md reference: AGENTS.md:L23-L29

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 152cae1: the -h/--version reporting-mode tests now drive Cli directly with captured streams and plain JUnit assertions (including the pre-existing -o help test, for consistency). The ARGV pass-through test keeps AwkTestSupport since it runs a script.

Comment threadsrc/site/markdown/cli-reference.md Outdated
## Execution Notes

- `--dump-syntax`, `--dump-intermediate`, `-K`, `-h`, `-?`, and `--list-ext` do not execute the script, and ignore `--persist` and `JAWK_PERSISTENT_MEMORY`. `--profile` does execute it, and keeps the normal AWK output on stdout.
- `--dump-syntax`, `--dump-intermediate`, `-K`, `-h`, `-?`, `-V`, `--version`, and `--list-ext` do not execute the script, and ignore `--persist` and `JAWK_PERSISTENT_MEMORY`. `--profile` does execute it, and keeps the normal AWK output on stdout.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Distinguish rejected --persist from ignored persistence

For jawk --persist state --version (in either order), parsing rejects the arguments because --version must be used alone, so the command-line --persist option is not ignored as this sentence claims. Only an ambient JAWK_PERSISTENT_MEMORY value is silently irrelevant to a standalone version run; document that distinction so the new CLI behavior is described consistently with line 77 and the implementation.

AGENTS.md reference: AGENTS.md:L35-L39

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 152cae1: the sentence now separates the modes that ignore --persist (--dump-syntax, --dump-intermediate, -K) from the standalone modes that reject it as an extra argument, with only an ambient JAWK_PERSISTENT_MEMORY being ignored by all of them.

Comment thread.github/workflows/installers.yml Outdated
# command in its help instead of "java -jar ...". Releases up to
# 7.1.00 predate --version and JAWK_PROGRAM_NAME, so probe with
# --version first and only assert on releases that support it.
if out="$("${HOME}/.local/bin/jawk" --version 2>/dev/null)"; then

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Stop treating every version failure as a legacy release

In the POSIX installer smoke job here, and equivalently in the Windows shim job, every nonzero --version result takes the legacy-release skip path. Once a release supports this option, a regression that makes --version fail will therefore still leave both smoke jobs green instead of enforcing the feature they were added to test; use the probed release version or another explicit capability boundary to skip only known legacy releases and fail for supported ones.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 152cae1: both jobs now skip only releases <= 7.1.00 (POSIX compares the probed release version with sort -V; Windows reads the installed jar's pom.properties like the pinned-version check) and otherwise require --version to succeed, so a regression fails the job.

- Non-script reporting-mode tests (-h, --version) no longer go through
AwkTestSupport, which is reserved for tests that run AWK scripts: they
drive Cli directly with captured streams and plain JUnit assertions.
- cli-reference.md now distinguishes the modes that ignore --persist
(--dump-syntax, --dump-intermediate, -K) from the standalone modes that
reject it as an extra argument.
- The installer smoke tests skip the version/help assertions only for
releases up to 7.1.00 (the last without --version), instead of treating
any --version failure as a legacy release, so a regression in a later
release fails the jobs. The Windows job reads the installed version from
the jar's pom.properties, like the POSIX pinned-version check.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@bertysentry

Copy link
Copy Markdown
ContributorAuthor

@codex please review again

@chatgpt-codex-connectorchatgpt-codex-connectorBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit:152cae1b64

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread.github/workflows/installers.yml Outdated
# 7.1.00 predate --version and JAWK_PROGRAM_NAME: skip only those,
# so a --version regression in a later release fails this job.
latest="${{ steps.release.outputs.version }}"
if [ "$(printf '%s\n' 7.1.00 "${latest}" | sort -V | tail -n 1)" = "7.1.00" ]; then

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Enforce checks for the first supporting release

Checked both new installer smoke-test sections: this cutoff skips v7.1.00, but pom.xml:6 identifies the current development line as 7.1.00-SNAPSHOT, so v7.1.00 is expected to be the first release containing --version and JAWK_PROGRAM_NAME. As a result, regressions in that first supported release take the legacy skip path here and in the Windows [version]...-le check instead of failing the jobs. Fresh evidence beyond the prior thread is the repository's current development version; use the last genuinely legacy release as the cutoff.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed: the cutoff is now 7.0.01, the last release that actually predates the feature (7.1.00-SNAPSHOT is the current development line, so 7.1.00 will be the first supporting release).

The development line is 7.1.00-SNAPSHOT, so 7.1.00 will be the first
release that ships --version and JAWK_PROGRAM_NAME; the last genuinely
legacy release is 7.0.01. With the previous cutoff a regression in the
first supporting release would have taken the skip path.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@bertysentry

Copy link
Copy Markdown
ContributorAuthor

@codex please review again

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit:843ade0ee9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@bertysentry
bertysentry merged commit 0c960b5 into mainAug 20, 2026
8 checks passed
@bertysentry
bertysentry deleted the cli-version-and-program-name branch August 20, 2026 11:42
Sign up for freeto 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.

jawk -h prints its usage as java -jar jawk-standalone.jar, not jawk No --version / -V option to report the Jawk version

1 participant

@bertysentry