Skip to content

Add Context class for argument parsing and program output#12

Merged
Malcolmnixon merged 4 commits intomainfrom
copilot/add-context-class-implementation
Feb 3, 2026
Merged

Add Context class for argument parsing and program output#12
Malcolmnixon merged 4 commits intomainfrom
copilot/add-context-class-implementation

Conversation

Copy link
Contributor

Copilot AI commented Feb 3, 2026

Pull Request

Description

Implements Context class based on SonarMark template to centralize command-line argument parsing and output management. Provides structured handling of program arguments, console/log file output, and exit code management.

Key Changes:

  • Context.cs (348 lines): Argument parser with WriteLine/WriteError methods, ExitCode property, and log file support
  • ContextTests.cs (33 tests): Coverage for argument parsing, output methods, error handling, and resource disposal
  • Program.cs: Integration with Context class, enhanced help message, structured exception handling

Supported Arguments:

-v, --version                Display version information
-?, -h, --help               Display this help message
--silent                     Suppress console output
--validate                   Run self-validation
--results <file>             Write validation results (TRX or JUnit)
--log <file>                 Write output to log file
--build-version <version>    Specify build version
--report <file>              Specify report file name
--report-depth <depth>       Specify report markdown depth (default: 1)

Usage Example:

using var context = Context.Create(args);
if (context.Version) {
    context.WriteLine($"BuildMark version {Version}");
    return context.ExitCode;
}
context.WriteError("Error message");  // Sets ExitCode to 1

Type of Change

  • New feature (non-breaking change which adds functionality)

Related Issues

Pre-Submission Checklist

Build and Test

  • Code builds successfully: dotnet build --configuration Release
  • All tests pass: dotnet test --configuration Release
  • Code produces zero warnings

Code Quality

  • Code formatting is correct: dotnet format --verify-no-changes
  • New code has appropriate XML documentation comments
  • Static analyzer warnings have been addressed

Quality Checks

  • Spell checker passes: cspell "**/*.{md,cs}"
  • Markdown linter passes: markdownlint "**/*.md"
  • YAML linter passes: yamllint '**/*.{yml,yaml}'

Testing

  • Added unit tests for new functionality
  • Updated existing tests if behavior changed
  • All tests follow the AAA (Arrange, Act, Assert) pattern
  • Test coverage is maintained or improved

Documentation

  • Updated README.md (if applicable)
  • Updated ARCHITECTURE.md (if applicable)
  • Added code examples for new features (if applicable)
  • Updated requirements.yaml (if applicable)

Additional Notes

  • All 103 tests pass (70 existing + 33 new)
  • CodeQL analysis: 0 security alerts
  • Manual verification completed with packaged tool
Original prompt

This section details on the original issue you should resolve

<issue_title>[Feature]: Program Context</issue_title>
<issue_description>### Problem Statement

A Context class is needed to handle program arguments and output.

Proposed Solution

Implement a Context class using https://github.com/demaconsulting/SonarMark/blob/main/src/DemaConsulting.SonarMark/Context.cs as a template. Specifically the Context class needs:

  • The same WriteLine/WriteError logic for writing to console and/or log file
  • The same ExitCode handling logix
  • Support for the following command-line arguments:
    • "-v" or "--version" to display the version information
    • "-?" or "-h" or "--help" to display help message
    • "--silent" to suppress console output
    • "--validate" to run self-validation
    • "--results " to write validation results (TRX or JUnit)
    • "--log " to write output to file
    • "--build-version" to specify the build version
    • "--report " to specify the name of the report file
    • "--report-depth " to specify the markdown header depth (default 1)

Alternatives Considered

No response

Usage Examples

Benefits

Similar program context processing to other DemaConsulting tools

Priority

High - Blocking my use case

Willingness to Contribute

Yes, I can submit a pull request

Additional Context

No response

Checklist

  • I have searched existing issues to ensure this is not a duplicate
  • I have provided a clear description of the feature
  • I have explained why this feature would be useful</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits February 3, 2026 14:28
Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
Copilot AI changed the title [WIP] Add Context class to handle program arguments and output Add Context class for argument parsing and program output Feb 3, 2026
Copilot AI requested a review from Malcolmnixon February 3, 2026 14:35
@Malcolmnixon Malcolmnixon marked this pull request as ready for review February 3, 2026 14:41
@Malcolmnixon Malcolmnixon merged commit 97e9abb into main Feb 3, 2026
10 checks passed
@Malcolmnixon Malcolmnixon deleted the copilot/add-context-class-implementation branch February 3, 2026 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Program Context

2 participants