From da554341c95d35b00947c1bb4355360a79b82ad5 Mon Sep 17 00:00:00 2001 From: Puneet Dixit <236133619+puneetdixit200@users.noreply.github.com> Date: Wed, 20 May 2026 17:10:33 +0530 Subject: [PATCH] fix: add help option aliases Map -h and --help to the existing help command and cover the aliases in unit, CLI integration, and docs updates. Assisted-by: OpenAI Codex (GPT-5) Signed-off-by: Puneet Dixit <236133619+puneetdixit200@users.noreply.github.com> --- .../openfasttrace/core/cli/CliArguments.java | 34 ++++++++++++++++--- .../core/cli/TestCliArguments.java | 24 +++++++++++++ doc/spec/design.md | 2 ++ doc/user_guide.md | 3 ++ .../openfasttrace/cli/CliExitIT.java | 19 ++++++++++- 5 files changed, 77 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/itsallcode/openfasttrace/core/cli/CliArguments.java b/core/src/main/java/org/itsallcode/openfasttrace/core/cli/CliArguments.java index 629ffdfb..48b50976 100644 --- a/core/src/main/java/org/itsallcode/openfasttrace/core/cli/CliArguments.java +++ b/core/src/main/java/org/itsallcode/openfasttrace/core/cli/CliArguments.java @@ -11,6 +11,7 @@ import org.itsallcode.openfasttrace.api.report.ReportConstants; import org.itsallcode.openfasttrace.api.report.ReportVerbosity; import org.itsallcode.openfasttrace.core.cli.commands.ConvertCommand; +import org.itsallcode.openfasttrace.core.cli.commands.HelpCommand; import org.itsallcode.openfasttrace.core.cli.commands.TraceCommand; import org.itsallcode.openfasttrace.core.cli.logging.LogLevel; import org.itsallcode.openfasttrace.core.exporter.ExporterConstants; @@ -45,10 +46,11 @@ public class CliArguments // [impl->dsn~cli.plugins.log~1] private LogLevel logLevel; + private boolean helpRequested; /** * Create new {@link CliArguments}. - * + * * @param directoryService * the directory service used for evaluating command line * arguments. @@ -60,7 +62,7 @@ public CliArguments(final DirectoryService directoryService) /** * Get the output file path - * + * * @return output file path */ public Path getOutputPath() @@ -74,7 +76,7 @@ public Path getOutputPath() /** * Set the output file path - * + * * @param outputFile * output file path */ @@ -85,7 +87,7 @@ public void setOutputFile(final String outputFile) /** * Set the output file path - * + * * @param outputFile * output file path */ @@ -101,6 +103,10 @@ public void setF(final String outputFile) */ public Optional getCommand() { + if (this.helpRequested) + { + return Optional.of(HelpCommand.COMMAND_NAME); + } if (this.unnamedValues == null || this.unnamedValues.isEmpty()) { return Optional.empty(); @@ -136,6 +142,26 @@ public void setUnnamedValues(final List unnamedValues) this.unnamedValues = unnamedValues; } + /** + * Request command line help. + * @param helpRequested + * whether help was requested + */ + public void setHelp(final boolean helpRequested) + { + this.helpRequested = helpRequested; + } + + /** + * Request command line help. + * @param helpRequested + * whether help was requested + */ + public void setH(final boolean helpRequested) + { + setHelp(helpRequested); + } + /** * Get the output format for an export or stream * diff --git a/core/src/test/java/org/itsallcode/openfasttrace/core/cli/TestCliArguments.java b/core/src/test/java/org/itsallcode/openfasttrace/core/cli/TestCliArguments.java index 143b1847..26f7e65d 100644 --- a/core/src/test/java/org/itsallcode/openfasttrace/core/cli/TestCliArguments.java +++ b/core/src/test/java/org/itsallcode/openfasttrace/core/cli/TestCliArguments.java @@ -6,6 +6,7 @@ import java.nio.file.Paths; import java.util.List; +import java.util.Optional; import org.itsallcode.openfasttrace.api.ColorScheme; import org.itsallcode.openfasttrace.api.DetailsSectionDisplay; @@ -13,6 +14,7 @@ import org.itsallcode.openfasttrace.api.report.ReportConstants; import org.itsallcode.openfasttrace.api.report.ReportVerbosity; import org.itsallcode.openfasttrace.core.cli.commands.ConvertCommand; +import org.itsallcode.openfasttrace.core.cli.commands.HelpCommand; import org.itsallcode.openfasttrace.core.cli.commands.TraceCommand; import org.itsallcode.openfasttrace.core.exporter.ExporterConstants; import org.junit.jupiter.api.BeforeEach; @@ -44,6 +46,28 @@ void testGetCommandWithUnnamedValuesEmpty() assertThat(this.arguments.getCommand().isPresent(), is(false)); } + @Test + void testSetHelpRequestsHelpCommand() + { + this.arguments.setHelp(true); + assertThat(this.arguments.getCommand(), equalTo(Optional.of(HelpCommand.COMMAND_NAME))); + } + + @Test + void testSetHRequestsHelpCommand() + { + this.arguments.setH(true); + assertThat(this.arguments.getCommand(), equalTo(Optional.of(HelpCommand.COMMAND_NAME))); + } + + @Test + void testHelpRequestOverridesUnnamedCommand() + { + this.arguments.setUnnamedValues(List.of(TraceCommand.COMMAND_NAME)); + this.arguments.setHelp(true); + assertThat(this.arguments.getCommand(), equalTo(Optional.of(HelpCommand.COMMAND_NAME))); + } + @Test void testSetOutputFormat() { diff --git a/doc/spec/design.md b/doc/spec/design.md index e2aa5250..e92f0d94 100644 --- a/doc/spec/design.md +++ b/doc/spec/design.md @@ -923,6 +923,8 @@ The CLI expects one of the following commands as first unnamed command line para command = "trace" / "convert" / "help" +The CLI also accepts `-h` and `--help` as aliases for the `help` command. + Covers: * `req~cli.tracing.command~1` diff --git a/doc/user_guide.md b/doc/user_guide.md index 053a66d4..df9794c1 100644 --- a/doc/user_guide.md +++ b/doc/user_guide.md @@ -579,6 +579,9 @@ Where `command` is one of * `trace` - create a requirement trace document * `convert` - convert to a different requirements format +* `help` - print the command line usage + +You can also print the command line usage with `-h` or `--help`. and `option` is one or more of the options listed below. diff --git a/product/src/test/java/org/itsallcode/openfasttrace/cli/CliExitIT.java b/product/src/test/java/org/itsallcode/openfasttrace/cli/CliExitIT.java index 953242a6..38c12d0f 100644 --- a/product/src/test/java/org/itsallcode/openfasttrace/cli/CliExitIT.java +++ b/product/src/test/java/org/itsallcode/openfasttrace/cli/CliExitIT.java @@ -43,9 +43,26 @@ void testRunWithUnsupportedCommand() @Test void testRunWithHelpCommand() + { + assertHelpOutputFor(List.of("help")); + } + + @Test + void testRunWithLongHelpOption() + { + assertHelpOutputFor(List.of("--help")); + } + + @Test + void testRunWithShortHelpOption() + { + assertHelpOutputFor(List.of("-h")); + } + + private void assertHelpOutputFor(final List arguments) { jarLauncher() - .args(List.of("help")) + .args(arguments) .expectedExitCode(ExitStatus.OK.getCode()) .expectStdOut(startsWith(""" OpenFastTrace