tazel
A build system for C, C++, Objective-C, Objective-C++ and Zig, with C# project files.
Clonegit clone https://git.progmasoft.com/tazel
Reduce cyclomatic complexity of CommandLine.Make and Scan
- Commit
d25ff91dc4dd20233106624288957b57887a3595- Author
- Leitwolf11 ·
- Parents
8dcc8e19f601
Changes
src/Progmasoft.Tazel/Cli/CommandLine.cs | 37 ++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/src/Progmasoft.Tazel/Cli/CommandLine.cs b/src/Progmasoft.Tazel/Cli/CommandLine.cs index 25644d5..89373ca 100644 --- a/src/Progmasoft.Tazel/Cli/CommandLine.cs +++ b/src/Progmasoft.Tazel/Cli/CommandLine.cs @@ -90,19 +90,7 @@ internal static class CommandLine private static Command Make(ScannedCommand scanned) { var command = scanned.Command; - // -o means --output for tazel license/version and --output-dir for tazel tool/package. - if (command is "license" or "version") - { - var outputOption = Options.First(o => o.Long == "output"); - for (var i = 0; i < scanned.Seen.Count; i++) - { - if (scanned.Seen[i].Written.StartsWith("-o", StringComparison.Ordinal)) - { - scanned.Seen[i] = (outputOption, scanned.Seen[i].Values, scanned.Seen[i].Written); - } - } - } - + RemapShortOutput(scanned, command); var unscoped = scanned.Seen.FirstOrDefault(entry => entry.Option.Scope.Length > 0 && !entry.Option.Scope.Contains(command, StringComparer.Ordinal)); if (unscoped.Option is not null) @@ -131,6 +119,24 @@ internal static class CommandLine return CommandMakers.Build(scanned, output); } + // -o means --output for tazel license/version and --output-dir for tazel tool/package. + private static void RemapShortOutput(ScannedCommand scanned, string command) + { + if (command is not ("license" or "version")) + { + return; + } + + var outputOption = Options.First(o => o.Long == "output"); + for (var i = 0; i < scanned.Seen.Count; i++) + { + if (scanned.Seen[i].Written.StartsWith("-o", StringComparison.Ordinal)) + { + scanned.Seen[i] = (outputOption, scanned.Seen[i].Values, scanned.Seen[i].Written); + } + } + } + private static OutputOptions OutputOf(ScannedCommand scanned) => new( ParseWhen(scanned.Last("color")) ?? When.Auto, ParseWhen(scanned.Last("progress")) ?? When.Auto, @@ -150,6 +156,9 @@ internal static class CommandLine } } + private static bool IsPassthrough(string? command, List<string> positional) => + command == "custom" || (command == "tool" && positional is ["launch", _, ..]); + private static ScannedCommand Scan(IReadOnlyList<string> arguments) { string? command = null; @@ -160,7 +169,7 @@ internal static class CommandLine while (index < arguments.Count) { var argument = arguments[index++]; - if (command == "custom" || (command == "tool" && positional is ["launch", _, ..])) + if (IsPassthrough(command, positional)) { // Everything after `tazel custom`, and after the name of `tazel tool launch`, belongs to what runs, // its options and -- too.