Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand All @@ -60,7 +62,7 @@ public CliArguments(final DirectoryService directoryService)

/**
* Get the output file path
*
*
* @return output file path
*/
public Path getOutputPath()
Expand All @@ -74,7 +76,7 @@ public Path getOutputPath()

/**
* Set the output file path
*
*
* @param outputFile
* output file path
*/
Expand All @@ -85,7 +87,7 @@ public void setOutputFile(final String outputFile)

/**
* Set the output file path
*
*
* @param outputFile
* output file path
*/
Expand All @@ -101,6 +103,10 @@ public void setF(final String outputFile)
*/
public Optional<String> getCommand()
{
if (this.helpRequested)
{
return Optional.of(HelpCommand.COMMAND_NAME);
}
if (this.unnamedValues == null || this.unnamedValues.isEmpty())
{
return Optional.empty();
Expand Down Expand Up @@ -136,6 +142,26 @@ public void setUnnamedValues(final List<String> 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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@

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;
import org.itsallcode.openfasttrace.api.core.Newline;
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;
Expand Down Expand Up @@ -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()
{
Expand Down
2 changes: 2 additions & 0 deletions doc/spec/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
3 changes: 3 additions & 0 deletions doc/user_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> arguments)
{
jarLauncher()
.args(List.of("help"))
.args(arguments)
.expectedExitCode(ExitStatus.OK.getCode())
.expectStdOut(startsWith("""
OpenFastTrace
Expand Down