Context is the sole unit in the Cli subsystem. It owns the lifecycle of
command-line argument parsing, console and log-file output, and exit-code tracking.
Program creates exactly one Context per invocation and passes it to all other
units that need to write output or read configuration.
Context implements IDisposable. Callers must dispose of the context after use
so that any open log file is properly flushed and closed.
| Property | Type | Default | Source |
|---|---|---|---|
Version |
bool |
false |
-v / --version |
Help |
bool |
false |
-? / -h / --help |
Silent |
bool |
false |
--silent |
Validate |
bool |
false |
--validate |
IncludeKnownIssues |
bool |
false |
--include-known-issues |
| Property | Type | Default | Source |
|---|---|---|---|
BuildVersion |
string? |
null |
--build-version <version> |
ReportFile |
string? |
null |
--report <file> |
ReportDepth |
int |
1 |
--report-depth <depth> |
ResultsFile |
string? |
null |
--results <file> |
ConnectorFactory |
Func<IRepoConnector>? |
null |
Injected via overload |
| Property | Type | Description |
|---|---|---|
ExitCode |
int |
0 if no errors have been written; 1 otherwise |
Public factory method. Constructs a new Context by forwarding to
ArgumentParser, then opens a log file if --log was specified.
Throws ArgumentException for invalid arguments; throws
InvalidOperationException if the log file cannot be opened.
Overload that additionally accepts a connector factory for dependency injection
during testing. The factory is stored on ConnectorFactory and used by
Program.ProcessBuildNotes instead of the default factory.
Opens the specified file for writing in overwrite mode (truncating any existing
file) with AutoFlush enabled. If the directory does not exist, the method
throws InvalidOperationException.
Writes message to standard output (unless Silent is set) and to the log file
(if open).
Writes message to standard error in red (unless Silent is set) and to the
log file (if open). Sets the internal error flag so that ExitCode returns 1.
Flushes and closes the log file stream. Safe to call multiple times.
ArgumentParser is a private nested class used exclusively by Create. It
iterates over the argument array and classifies each token:
- Short flags (
-v,-h,-?) and long flags (--version,--help, etc.) are mapped to boolean properties. - Value arguments (
--build-version,--report,--report-depth,--results,--log) expect the next token as their value and throwArgumentExceptionif no next token is present. --report-depthadditionally validates that the value is a positive integer.- Any unrecognized token causes
ArgumentExceptionto be thrown.