namespace Agent.App.Cli; public enum AppCommand { Start, Apply, Show } public sealed record CommandLine( AppCommand Command, string? ConfigPath, bool Yes = false) { private static readonly HashSet RemovedCommands = new(StringComparer.Ordinal) { "serve", "check", "executable", "sandbox" }; public static CommandLine Parse(string[] args) { if (args.Length == 0) return new(AppCommand.Start, null); if (RemovedCommands.Contains(args[0])) throw new CommandLineException($"'{args[0]}' was removed in schema_version 2. Use 'agent-mcp', 'agent-mcp apply', or 'agent-mcp show'."); if (args.Any(static value => value is "--config" or "--lang" or "--transport" or "--path" or "--runtime-root" or "--no-runtime" or "--format")) throw new CommandLineException("Configuration override options were removed in schema_version 2. Put values in YAML and pass the config path as a positional argument."); AppCommand command = args[0] switch { "apply" => AppCommand.Apply, "show" => AppCommand.Show, _ when !args[0].StartsWith("--", StringComparison.Ordinal) => AppCommand.Start, _ => throw new CommandLineException($"Unknown option '{args[0]}'.") }; int index = command == AppCommand.Start ? 0 : 1; string? config = null; bool yes = false; while (index < args.Length) { string value = args[index++]; if (value == "--yes" && command == AppCommand.Apply && !yes) yes = true; else if (!value.StartsWith("--", StringComparison.Ordinal) && config is null) config = value; else throw new CommandLineException($"Unknown, duplicate, or invalid argument '{value}' for this command."); } return new(command, config, yes); } } public sealed class CommandLineException(string message) : Exception(message);