fix(cli): resolve CLI-008..013 — format validation, exit-code semantics, debug-stream cancellation/disposal, test coverage
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
using System.CommandLine;
|
||||
|
||||
namespace ScadaLink.CLI.Commands;
|
||||
|
||||
/// <summary>
|
||||
/// Factory methods for the global CLI options. Centralising option construction keeps
|
||||
/// validation rules (e.g. the accepted <c>--format</c> values) in one place and makes
|
||||
/// them testable without standing up the whole command tree.
|
||||
/// </summary>
|
||||
internal static class CliOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates the global <c>--format</c> option. The option deliberately has no
|
||||
/// <c>DefaultValueFactory</c> — format precedence (explicit flag → config/env →
|
||||
/// <c>"json"</c>) is resolved by <see cref="CommandHelpers.ResolveFormat"/>, which
|
||||
/// needs to distinguish an absent flag. The accepted values are constrained so a
|
||||
/// typo (e.g. <c>--format tabel</c>) is rejected with a clear parse error rather
|
||||
/// than silently falling through to JSON.
|
||||
/// </summary>
|
||||
internal static Option<string> CreateFormatOption()
|
||||
{
|
||||
var formatOption = new Option<string>("--format")
|
||||
{
|
||||
Description = "Output format (json or table)",
|
||||
Recursive = true,
|
||||
};
|
||||
formatOption.AcceptOnlyFromAmong("json", "table");
|
||||
return formatOption;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user