Skip to content
Merged
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
6 changes: 5 additions & 1 deletion docs/design/sarifmark/cli/context.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,14 @@ This satisfies requirements `SarifMark-Context-Create` through `SarifMark-Contex
| `ResultsFile` | `string?` | `null` | `--results <file>` | 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

Expand Down
11 changes: 11 additions & 0 deletions docs/reqstream/sarifmark/cli/cli.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions docs/reqstream/sarifmark/cli/context.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: >-
Expand Down
1 change: 1 addition & 0 deletions src/DemaConsulting.SarifMark/Cli/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Comment thread
Malcolmnixon marked this conversation as resolved.
Expand Down
14 changes: 14 additions & 0 deletions test/DemaConsulting.SarifMark.Tests/Cli/CliTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,4 +259,18 @@ public void Cli_ResultsParameter_SetsResultsFilePath()
Assert.AreEqual("results.trx", context.ResultsFile);
Assert.AreEqual(0, context.ExitCode);
}

/// <summary>
/// Test that the legacy --result alias sets the results file path in context.
/// </summary>
[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);
}
}
13 changes: 13 additions & 0 deletions test/DemaConsulting.SarifMark.Tests/Cli/ContextTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,19 @@ public void Context_Create_ResultsParameter_SetsResultsFile()
Assert.AreEqual("results.trx", context.ResultsFile);
}

/// <summary>
/// Test that creating a context with the legacy --result parameter sets ResultsFile property.
/// </summary>
[TestMethod]
public void Context_Create_ResultLegacyAlias_SetsResultsFile()
{
// Act
using var context = Context.Create(["--result", "results.trx"]);

// Assert
Assert.AreEqual("results.trx", context.ResultsFile);
}

/// <summary>
/// Test that WriteLine writes to the log file when it is open.
/// </summary>
Expand Down