Progmasoft Git

tazel

A build system for C, C++, Objective-C, Objective-C++ and Zig, with C# project files.

Clonegit clone https://git.progmasoft.com/tazel

Clean up Fish option verbosity and reset completions on re-source

Commit
859480c29d5c61307e308668555400a524af9303
Author
Leitwolf11 ·
Parents
eae9bab5d31a

Files · Download .tar.gz

Changes

 src/Progmasoft.Tazel/Cli/ShellCompletion.cs        | 32 ++++++++--------------
 .../ShellCompletionAndExplainTests.cs              | 10 +++----
 2 files changed, 17 insertions(+), 25 deletions(-)

diff --git a/src/Progmasoft.Tazel/Cli/ShellCompletion.cs b/src/Progmasoft.Tazel/Cli/ShellCompletion.cs
index ca58356..cf9b941 100644
--- a/src/Progmasoft.Tazel/Cli/ShellCompletion.cs
+++ b/src/Progmasoft.Tazel/Cli/ShellCompletion.cs
@@ -409,25 +409,15 @@ internal static class ShellCompletion
         sb.AppendLine("# Tazel shell completion for Fish.");
         sb.AppendLine("# Load in the current shell: tazel shell-completion fish | source");
         sb.AppendLine();
-        sb.AppendLine("function __tazel_complete_val_opt");
+        sb.AppendLine("complete -c tazel -e");
+        sb.AppendLine();
+        sb.AppendLine("function __tazel_complete_colon_opt");
         sb.AppendLine("    set -l tok (commandline -ct)");
         sb.AppendLine("    set -l opt $argv[1]");
-        sb.AppendLine("    set -l vals $argv[2..-1]");
-        sb.AppendLine("    switch $tok");
-        sb.AppendLine("        case \"$opt:*\"");
-        sb.AppendLine("            for v in $vals");
-        sb.AppendLine("                echo \"$opt:$v\"");
-        sb.AppendLine("            end");
-        sb.AppendLine("        case \"$opt=*\"");
-        sb.AppendLine("            for v in $vals");
-        sb.AppendLine("                echo \"$opt=$v\"");
-        sb.AppendLine("            end");
-        sb.AppendLine("        case \"-*\"");
-        sb.AppendLine("            if string match -q -- \"$tok*\" \"$opt\"");
-        sb.AppendLine("                echo \"$opt\"");
-        sb.AppendLine("                echo \"$opt=\"");
-        sb.AppendLine("                echo \"$opt:\"");
-        sb.AppendLine("            end");
+        sb.AppendLine("    if string match -q -- \"$opt:*\" \"$tok\"");
+        sb.AppendLine("        for v in $argv[2..-1]");
+        sb.AppendLine("            echo \"$opt:$v\"");
+        sb.AppendLine("        end");
         sb.AppendLine("    end");
         sb.AppendLine("end");
         sb.AppendLine();
@@ -464,7 +454,7 @@ internal static class ShellCompletion
         sb.AppendLine();
         sb.AppendLine("complete -c tazel -f");
         sb.AppendLine();
-        sb.AppendLine("# Global options (space, = and : separators supported without forcing a trailing space)");
+        sb.AppendLine("# Global options");
         AppendFishValueOption(sb, null, "color", "always auto never", "Color output");
         AppendFishValueOption(sb, null, "progress", "always auto never", "Progress output");
         sb.AppendLine("complete -c tazel -l quiet -d 'Suppress status output'");
@@ -532,9 +522,11 @@ internal static class ShellCompletion
         var shortPart = shortOpt is null ? "" : $" -s {shortOpt}";
         var mode = requireFiles ? "-r" : "-x";
         var valuesArg = values is null ? "" : $" -a '{values}'";
-        var helperArgs = values is null ? $"--{longOpt}" : $"--{longOpt} {values}";
         sb.AppendLine($"complete -c tazel{cond}{shortPart} -l {longOpt} {mode}{valuesArg} -d '{description}'");
-        sb.AppendLine($"complete -c tazel{cond} -a '(__tazel_complete_val_opt {helperArgs})' -d '{description}'");
+        if (values is not null)
+        {
+            sb.AppendLine($"complete -c tazel{cond} -a '(__tazel_complete_colon_opt --{longOpt} {values})' -d '{description}'");
+        }
     }
 
     private static string PowerShell()
diff --git a/tests/Progmasoft.Tazel.Tests/ShellCompletionAndExplainTests.cs b/tests/Progmasoft.Tazel.Tests/ShellCompletionAndExplainTests.cs
index 9fdda6d..9ced299 100644
--- a/tests/Progmasoft.Tazel.Tests/ShellCompletionAndExplainTests.cs
+++ b/tests/Progmasoft.Tazel.Tests/ShellCompletionAndExplainTests.cs
@@ -113,13 +113,13 @@ public sealed class ShellCompletionAndExplainTests
     }
 
     [Fact]
-    public void FishScriptDoesNotForceTrailingSpaceOnValueOptions()
+    public void FishScriptErasesPriorCompletionsAndSupportsColonValuesWithoutDuplicatingOptions()
     {
         var script = ShellCompletion.Generate(ShellKind.Fish);
-        Assert.Contains("function __tazel_complete_val_opt", script, StringComparison.Ordinal);
-        Assert.Contains("__tazel_complete_val_opt --message-format rich-stdio script-friendly-stdio jsonl xml", script, StringComparison.Ordinal);
-        Assert.Contains("echo \"$opt=\"", script, StringComparison.Ordinal);
-        Assert.Contains("echo \"$opt:\"", script, StringComparison.Ordinal);
+        Assert.Contains("complete -c tazel -e", script, StringComparison.Ordinal);
+        Assert.Contains("function __tazel_complete_colon_opt", script, StringComparison.Ordinal);
+        Assert.Contains("__tazel_complete_colon_opt --message-format rich-stdio script-friendly-stdio jsonl xml", script, StringComparison.Ordinal);
+        Assert.DoesNotContain("echo \"$opt=\"", script, StringComparison.Ordinal);
     }
 
     [Fact]