up
This commit is contained in:
@@ -904,6 +904,130 @@ internal static class CommandFactory
|
||||
});
|
||||
|
||||
policy.Add(activate);
|
||||
|
||||
// lint subcommand - validates policy DSL files locally
|
||||
var lint = new Command("lint", "Validate a policy DSL file locally without contacting the backend.");
|
||||
var lintFileArgument = new Argument<string>("file")
|
||||
{
|
||||
Description = "Path to the policy DSL file to validate."
|
||||
};
|
||||
var lintFormatOption = new Option<string?>("--format", new[] { "-f" })
|
||||
{
|
||||
Description = "Output format: table (default), json."
|
||||
};
|
||||
var lintOutputOption = new Option<string?>("--output", new[] { "-o" })
|
||||
{
|
||||
Description = "Write JSON output to the specified file."
|
||||
};
|
||||
|
||||
lint.Add(lintFileArgument);
|
||||
lint.Add(lintFormatOption);
|
||||
lint.Add(lintOutputOption);
|
||||
|
||||
lint.SetAction((parseResult, _) =>
|
||||
{
|
||||
var file = parseResult.GetValue(lintFileArgument) ?? string.Empty;
|
||||
var format = parseResult.GetValue(lintFormatOption);
|
||||
var output = parseResult.GetValue(lintOutputOption);
|
||||
var verbose = parseResult.GetValue(verboseOption);
|
||||
|
||||
return CommandHandlers.HandlePolicyLintAsync(file, format, output, verbose, cancellationToken);
|
||||
});
|
||||
|
||||
policy.Add(lint);
|
||||
|
||||
// edit subcommand - Git-backed DSL file editing with validation and commit
|
||||
var edit = new Command("edit", "Open a policy DSL file in $EDITOR, validate, and optionally commit with SemVer metadata.");
|
||||
var editFileArgument = new Argument<string>("file")
|
||||
{
|
||||
Description = "Path to the policy DSL file to edit."
|
||||
};
|
||||
var editCommitOption = new Option<bool>("--commit", new[] { "-c" })
|
||||
{
|
||||
Description = "Commit changes after successful validation."
|
||||
};
|
||||
var editVersionOption = new Option<string?>("--version", new[] { "-V" })
|
||||
{
|
||||
Description = "SemVer version for commit metadata (e.g. 1.2.0)."
|
||||
};
|
||||
var editMessageOption = new Option<string?>("--message", new[] { "-m" })
|
||||
{
|
||||
Description = "Commit message (auto-generated if not provided)."
|
||||
};
|
||||
var editNoValidateOption = new Option<bool>("--no-validate")
|
||||
{
|
||||
Description = "Skip validation after editing (not recommended)."
|
||||
};
|
||||
|
||||
edit.Add(editFileArgument);
|
||||
edit.Add(editCommitOption);
|
||||
edit.Add(editVersionOption);
|
||||
edit.Add(editMessageOption);
|
||||
edit.Add(editNoValidateOption);
|
||||
|
||||
edit.SetAction((parseResult, _) =>
|
||||
{
|
||||
var file = parseResult.GetValue(editFileArgument) ?? string.Empty;
|
||||
var commit = parseResult.GetValue(editCommitOption);
|
||||
var version = parseResult.GetValue(editVersionOption);
|
||||
var message = parseResult.GetValue(editMessageOption);
|
||||
var noValidate = parseResult.GetValue(editNoValidateOption);
|
||||
var verbose = parseResult.GetValue(verboseOption);
|
||||
|
||||
return CommandHandlers.HandlePolicyEditAsync(file, commit, version, message, noValidate, verbose, cancellationToken);
|
||||
});
|
||||
|
||||
policy.Add(edit);
|
||||
|
||||
// test subcommand - run coverage fixtures against a policy DSL file
|
||||
var test = new Command("test", "Run coverage test fixtures against a policy DSL file.");
|
||||
var testFileArgument = new Argument<string>("file")
|
||||
{
|
||||
Description = "Path to the policy DSL file to test."
|
||||
};
|
||||
var testFixturesOption = new Option<string?>("--fixtures", new[] { "-d" })
|
||||
{
|
||||
Description = "Path to fixtures directory (defaults to tests/policy/<policy-name>/cases)."
|
||||
};
|
||||
var testFilterOption = new Option<string?>("--filter")
|
||||
{
|
||||
Description = "Run only fixtures matching this pattern."
|
||||
};
|
||||
var testFormatOption = new Option<string?>("--format", new[] { "-f" })
|
||||
{
|
||||
Description = "Output format: table (default), json."
|
||||
};
|
||||
var testOutputOption = new Option<string?>("--output", new[] { "-o" })
|
||||
{
|
||||
Description = "Write test results to the specified file."
|
||||
};
|
||||
var testFailFastOption = new Option<bool>("--fail-fast")
|
||||
{
|
||||
Description = "Stop on first test failure."
|
||||
};
|
||||
|
||||
test.Add(testFileArgument);
|
||||
test.Add(testFixturesOption);
|
||||
test.Add(testFilterOption);
|
||||
test.Add(testFormatOption);
|
||||
test.Add(testOutputOption);
|
||||
test.Add(testFailFastOption);
|
||||
|
||||
test.SetAction((parseResult, _) =>
|
||||
{
|
||||
var file = parseResult.GetValue(testFileArgument) ?? string.Empty;
|
||||
var fixtures = parseResult.GetValue(testFixturesOption);
|
||||
var filter = parseResult.GetValue(testFilterOption);
|
||||
var format = parseResult.GetValue(testFormatOption);
|
||||
var output = parseResult.GetValue(testOutputOption);
|
||||
var failFast = parseResult.GetValue(testFailFastOption);
|
||||
var verbose = parseResult.GetValue(verboseOption);
|
||||
|
||||
return CommandHandlers.HandlePolicyTestAsync(file, fixtures, filter, format, output, failFast, verbose, cancellationToken);
|
||||
});
|
||||
|
||||
policy.Add(test);
|
||||
|
||||
return policy;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user