diff --git a/docs/design/sarifmark/cli/context.md b/docs/design/sarifmark/cli/context.md index 8f41704..87248a4 100644 --- a/docs/design/sarifmark/cli/context.md +++ b/docs/design/sarifmark/cli/context.md @@ -40,10 +40,14 @@ This satisfies requirements `SarifMark-Context-Create` through `SarifMark-Contex | `ResultsFile` | `string?` | `null` | `--results ` | Path for the self-validation results file | | `ExitCode` | `int` | `0`/`1` | *(derived)* | 0 until `WriteError` is called, then 1 | +The `--result` flag is accepted as a legacy alias for `--results`, preserving backwards compatibility +(see requirement `SarifMark-Context-ResultLegacyAlias`). + These properties satisfy requirements `SarifMark-Context-VersionFlag`, `SarifMark-Context-HelpFlag`, `SarifMark-Context-SilentFlag`, `SarifMark-Context-ValidateFlag`, `SarifMark-Context-EnforceFlag`, `SarifMark-Context-SarifParam`, `SarifMark-Context-ReportParam`, `SarifMark-Context-ReportDepthParam`, -`SarifMark-Context-HeadingParam`, `SarifMark-Context-ResultsParam`, and `SarifMark-Context-ExitCode`. +`SarifMark-Context-HeadingParam`, `SarifMark-Context-ResultsParam`, `SarifMark-Context-ResultLegacyAlias`, +and `SarifMark-Context-ExitCode`. ## ArgumentParser Inner Class diff --git a/docs/reqstream/sarifmark/cli/cli.yaml b/docs/reqstream/sarifmark/cli/cli.yaml index 467795c..87e2e92 100644 --- a/docs/reqstream/sarifmark/cli/cli.yaml +++ b/docs/reqstream/sarifmark/cli/cli.yaml @@ -159,3 +159,14 @@ sections: - SarifMark-Context-ResultsParam tests: - Cli_ResultsParameter_SetsResultsFilePath + + - id: SarifMark-Cli-ResultLegacyAlias + title: The CLI shall accept --result as a legacy alias for --results. + justification: >- + Supporting the legacy --result alias preserves backwards compatibility for users and scripts + that relied on the earlier parameter name, avoiding breaking changes in automated workflows. + tags: [public] + children: + - SarifMark-Context-ResultLegacyAlias + tests: + - Cli_ResultLegacyAlias_SetsResultsFilePath diff --git a/docs/reqstream/sarifmark/cli/context.yaml b/docs/reqstream/sarifmark/cli/context.yaml index b65e75b..2c8a10c 100644 --- a/docs/reqstream/sarifmark/cli/context.yaml +++ b/docs/reqstream/sarifmark/cli/context.yaml @@ -120,6 +120,15 @@ sections: tests: - Context_Create_ResultsParameter_SetsResultsFile + - id: SarifMark-Context-ResultLegacyAlias + title: The Create method shall accept --result as a legacy alias for --results. + justification: >- + Accepting the legacy --result alias preserves backwards compatibility for existing scripts and + workflows that used the earlier parameter name, preventing breaking changes when users upgrade. + tags: [internal] + tests: + - Context_Create_ResultLegacyAlias_SetsResultsFile + - id: SarifMark-Context-LogParam title: The Create method shall parse the --log parameter and open the specified log file for writing. justification: >- diff --git a/src/DemaConsulting.SarifMark/Cli/Context.cs b/src/DemaConsulting.SarifMark/Cli/Context.cs index 22eb848..cda99d0 100644 --- a/src/DemaConsulting.SarifMark/Cli/Context.cs +++ b/src/DemaConsulting.SarifMark/Cli/Context.cs @@ -286,6 +286,7 @@ private int ParseArgument(string arg, string[] args, int index) Heading = GetRequiredStringArgument(arg, args, index, "a heading text argument"); return index + 1; + case "--result": // Legacy alias for --results to preserve backwards compatibility case "--results": ResultsFile = GetRequiredStringArgument(arg, args, index, "a results filename argument"); return index + 1; diff --git a/test/DemaConsulting.SarifMark.Tests/Cli/CliTests.cs b/test/DemaConsulting.SarifMark.Tests/Cli/CliTests.cs index c234c54..b462e9c 100644 --- a/test/DemaConsulting.SarifMark.Tests/Cli/CliTests.cs +++ b/test/DemaConsulting.SarifMark.Tests/Cli/CliTests.cs @@ -259,4 +259,18 @@ public void Cli_ResultsParameter_SetsResultsFilePath() Assert.AreEqual("results.trx", context.ResultsFile); Assert.AreEqual(0, context.ExitCode); } + + /// + /// Test that the legacy --result alias sets the results file path in context. + /// + [TestMethod] + public void Cli_ResultLegacyAlias_SetsResultsFilePath() + { + // Act + using var context = Context.Create(["--result", "results.trx"]); + + // Assert + Assert.AreEqual("results.trx", context.ResultsFile); + Assert.AreEqual(0, context.ExitCode); + } } diff --git a/test/DemaConsulting.SarifMark.Tests/Cli/ContextTests.cs b/test/DemaConsulting.SarifMark.Tests/Cli/ContextTests.cs index 3a56423..c1748f0 100644 --- a/test/DemaConsulting.SarifMark.Tests/Cli/ContextTests.cs +++ b/test/DemaConsulting.SarifMark.Tests/Cli/ContextTests.cs @@ -521,6 +521,19 @@ public void Context_Create_ResultsParameter_SetsResultsFile() Assert.AreEqual("results.trx", context.ResultsFile); } + /// + /// Test that creating a context with the legacy --result parameter sets ResultsFile property. + /// + [TestMethod] + public void Context_Create_ResultLegacyAlias_SetsResultsFile() + { + // Act + using var context = Context.Create(["--result", "results.trx"]); + + // Assert + Assert.AreEqual("results.trx", context.ResultsFile); + } + /// /// Test that WriteLine writes to the log file when it is open. ///