| 1 | namespace AIGuiders.DotnetTools.TomlCheck; |
| 2 | |
| 3 | internal static class CheckArgsParser |
| 4 | { |
| 5 | public static bool TryParse(string[] args, out string[] paths, out string? schema, out string? error) |
| 6 | { |
| 7 | paths = []; |
| 8 | schema = null; |
| 9 | error = null; |
| 10 | |
| 11 | if (args.Length == 0) |
| 12 | { |
| 13 | error = "check: at least one path is required."; |
| 14 | return false; |
| 15 | } |
| 16 | |
| 17 | var pathList = new List<string>(); |
| 18 | for (var i = 0; i < args.Length; i++) |
| 19 | { |
| 20 | var arg = args[i]; |
| 21 | if (arg is "--schema" or "-schema") |
| 22 | { |
| 23 | if (i + 1 >= args.Length) |
| 24 | { |
| 25 | error = "check: --schema requires a path."; |
| 26 | return false; |
| 27 | } |
| 28 | |
| 29 | schema = args[++i]; |
| 30 | continue; |
| 31 | } |
| 32 | |
| 33 | if (arg.StartsWith('-')) |
| 34 | { |
| 35 | error = $"check: unknown option: {arg}"; |
| 36 | return false; |
| 37 | } |
| 38 | |
| 39 | pathList.Add(arg); |
| 40 | } |
| 41 | |
| 42 | if (pathList.Count == 0) |
| 43 | { |
| 44 | error = "check: at least one path is required."; |
| 45 | return false; |
| 46 | } |
| 47 | |
| 48 | paths = pathList.ToArray(); |
| 49 | return true; |
| 50 | } |
| 51 | } |
| 52 | |
View only · write via MCP/CIDE