diff --git a/docs/design/sonar-mark/cli/context.md b/docs/design/sonar-mark/cli/context.md index f7ca557..23a9d7d 100644 --- a/docs/design/sonar-mark/cli/context.md +++ b/docs/design/sonar-mark/cli/context.md @@ -50,3 +50,16 @@ Using `IDisposable` rather than a finalizer is appropriate because the resource - `SonarMark-Validation-JUnitFormat` — JUnit XML file extension is accepted by `ResultsFile` - `SonarMark-Enforce-Mode` — `Enforce` flag is parsed and stored - `SonarMark-Enforce-ExitCode` — `ExitCode` returns 1 when `_hasErrors` is true +- `SonarMark-Context-ResultAlias` — `--result` is accepted as a legacy alias for `--results` + +## Backward Compatibility + +### Legacy `--result` Alias + +The `ArgumentParser` accepts `--result` as a fall-through case immediately before `--results` +in the switch statement. Both spellings invoke the same `GetRequiredStringArgument` call and +set the same `ResultsFile` property, so downstream code is unaffected. + +This alias is intentionally omitted from help text and user-facing documentation because it +exists only to avoid breaking existing automation scripts that pre-date the canonical +`--results` spelling. New users and new scripts should always use `--results`. diff --git a/docs/reqstream/sonar-mark/cli/context.yaml b/docs/reqstream/sonar-mark/cli/context.yaml index 9f3b948..2f61c75 100644 --- a/docs/reqstream/sonar-mark/cli/context.yaml +++ b/docs/reqstream/sonar-mark/cli/context.yaml @@ -57,3 +57,14 @@ sections: tests: - Context_Create_ResultsFile_SetsResultsProperty - Context_Create_MissingResultsFilename_ThrowsException + + - id: SonarMark-Context-ResultAlias + title: The tool shall accept --result as a legacy alias for --results to preserve backward compatibility. + justification: | + Existing automation scripts and CI pipelines may use --result (without the trailing 's') from + before the canonical --results spelling was established. Accepting the alias prevents breakage + for those consumers without requiring a coordinated migration, while new users are directed to + the canonical --results flag via documentation and help text. + tests: + - Context_Create_ResultAlias_SetsResultsProperty + - Context_Create_MissingResultAliasFilename_ThrowsException diff --git a/src/DemaConsulting.SonarMark/Cli/Context.cs b/src/DemaConsulting.SonarMark/Cli/Context.cs index c2df169..2830e88 100644 --- a/src/DemaConsulting.SonarMark/Cli/Context.cs +++ b/src/DemaConsulting.SonarMark/Cli/Context.cs @@ -337,6 +337,8 @@ private int ParseArgument(string arg, string[] args, int index) Branch = GetRequiredStringArgument(arg, args, index, "a branch name argument"); return index + 1; + // Accept --result as a legacy alias so older scripts continue working + case "--result": case "--results": ResultsFile = GetRequiredStringArgument(arg, args, index, "a results filename argument"); return index + 1; diff --git a/test/DemaConsulting.SonarMark.Tests/Cli/ContextTests.cs b/test/DemaConsulting.SonarMark.Tests/Cli/ContextTests.cs index 1b2ea22..4f1e33d 100644 --- a/test/DemaConsulting.SonarMark.Tests/Cli/ContextTests.cs +++ b/test/DemaConsulting.SonarMark.Tests/Cli/ContextTests.cs @@ -461,4 +461,29 @@ public void Context_Create_MissingResultsFilename_ThrowsException() var ex = Assert.ThrowsExactly(() => Context.Create(["--results"])); Assert.Contains("--results requires a results filename argument", ex.Message); } + + /// + /// Test that --result (legacy alias) sets the ResultsFile property. + /// + [TestMethod] + public void Context_Create_ResultAlias_SetsResultsProperty() + { + // Act + using var context = Context.Create(["--result", "results.trx"]); + + // Assert + Assert.AreEqual("results.trx", context.ResultsFile); + Assert.AreEqual(0, context.ExitCode); + } + + /// + /// Test that --result (legacy alias) requires a filename argument. + /// + [TestMethod] + public void Context_Create_MissingResultAliasFilename_ThrowsException() + { + // Act/Assert + var ex = Assert.ThrowsExactly(() => Context.Create(["--result"])); + Assert.Contains("--result requires a results filename argument", ex.Message); + } }