From e711ceac63b2f7384151ba2753fe085f738e8b39 Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Sun, 8 Sep 2019 14:00:56 +0200 Subject: Init: basic command line abstraction for fish’s complete MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkgs/profpatsch/dhallsh/Argument/toArgList.dhall | 18 ++++ pkgs/profpatsch/dhallsh/Argument/type.dhall | 3 + pkgs/profpatsch/dhallsh/BaseCommand/type.dhall | 1 + pkgs/profpatsch/dhallsh/Command/type.dhall | 1 + pkgs/profpatsch/dhallsh/List/filterOptional.dhall | 23 +++++ pkgs/profpatsch/dhallsh/Option/type.dhall | 1 + .../dhallsh/OptionPrinter/newStyle.dhall | 8 ++ pkgs/profpatsch/dhallsh/OptionPrinter/type.dhall | 1 + pkgs/profpatsch/dhallsh/main.dhall | 101 +++++++++++++++++++++ pkgs/profpatsch/dhallsh/shell.nix | 15 +++ 10 files changed, 172 insertions(+) create mode 100644 pkgs/profpatsch/dhallsh/Argument/toArgList.dhall create mode 100644 pkgs/profpatsch/dhallsh/Argument/type.dhall create mode 100644 pkgs/profpatsch/dhallsh/BaseCommand/type.dhall create mode 100644 pkgs/profpatsch/dhallsh/Command/type.dhall create mode 100644 pkgs/profpatsch/dhallsh/List/filterOptional.dhall create mode 100644 pkgs/profpatsch/dhallsh/Option/type.dhall create mode 100644 pkgs/profpatsch/dhallsh/OptionPrinter/newStyle.dhall create mode 100644 pkgs/profpatsch/dhallsh/OptionPrinter/type.dhall create mode 100644 pkgs/profpatsch/dhallsh/main.dhall create mode 100644 pkgs/profpatsch/dhallsh/shell.nix diff --git a/pkgs/profpatsch/dhallsh/Argument/toArgList.dhall b/pkgs/profpatsch/dhallsh/Argument/toArgList.dhall new file mode 100644 index 00000000..93785c72 --- /dev/null +++ b/pkgs/profpatsch/dhallsh/Argument/toArgList.dhall @@ -0,0 +1,18 @@ +let OptionPrinter = ../OptionPrinter/type.dhall + +let Option = ../Option/type.dhall + +let Argument = ../Argument/type.dhall + +in λ(optionPrinter : OptionPrinter) + → λ(a : Argument) + → merge + { Plain = + λ(t : Text) → [ t ] + , Flag = + λ(o : Option) → [ optionPrinter o ] + , Option = + λ(o : { opt : Option, arg : Text }) → [ optionPrinter o.opt, o.arg ] + } + a + : List Text diff --git a/pkgs/profpatsch/dhallsh/Argument/type.dhall b/pkgs/profpatsch/dhallsh/Argument/type.dhall new file mode 100644 index 00000000..2e5b6439 --- /dev/null +++ b/pkgs/profpatsch/dhallsh/Argument/type.dhall @@ -0,0 +1,3 @@ +let Option = ../Option/type.dhall + +in < Plain : Text | Flag : Option | Option : { opt : Option, arg : Text } > diff --git a/pkgs/profpatsch/dhallsh/BaseCommand/type.dhall b/pkgs/profpatsch/dhallsh/BaseCommand/type.dhall new file mode 100644 index 00000000..a9994f56 --- /dev/null +++ b/pkgs/profpatsch/dhallsh/BaseCommand/type.dhall @@ -0,0 +1 @@ +List Text diff --git a/pkgs/profpatsch/dhallsh/Command/type.dhall b/pkgs/profpatsch/dhallsh/Command/type.dhall new file mode 100644 index 00000000..0b8d62da --- /dev/null +++ b/pkgs/profpatsch/dhallsh/Command/type.dhall @@ -0,0 +1 @@ +λ(arg : Type) → { cmd : Text, args : List arg } diff --git a/pkgs/profpatsch/dhallsh/List/filterOptional.dhall b/pkgs/profpatsch/dhallsh/List/filterOptional.dhall new file mode 100644 index 00000000..810599b0 --- /dev/null +++ b/pkgs/profpatsch/dhallsh/List/filterOptional.dhall @@ -0,0 +1,23 @@ +let filterOptional + : ∀(a : Type) → ∀(b : Type) → (a → Optional b) → List a → List b + = λ(a : Type) + → λ(b : Type) + → λ(f : a → Optional b) + → λ(l : List a) + → List/build + b + ( λ(list : Type) + → λ(cons : b → list → list) + → λ(nil : list) + → List/fold + a + l + list + ( λ(x : a) + → λ(xs : list) + → Optional/fold b (f x) list (λ(opt : b) → cons opt xs) xs + ) + nil + ) + +in filterOptional diff --git a/pkgs/profpatsch/dhallsh/Option/type.dhall b/pkgs/profpatsch/dhallsh/Option/type.dhall new file mode 100644 index 00000000..3a282d3a --- /dev/null +++ b/pkgs/profpatsch/dhallsh/Option/type.dhall @@ -0,0 +1 @@ +< Long : Text | Short : Text > diff --git a/pkgs/profpatsch/dhallsh/OptionPrinter/newStyle.dhall b/pkgs/profpatsch/dhallsh/OptionPrinter/newStyle.dhall new file mode 100644 index 00000000..2a9435d9 --- /dev/null +++ b/pkgs/profpatsch/dhallsh/OptionPrinter/newStyle.dhall @@ -0,0 +1,8 @@ +let Option = ../Option/type.dhall + +let newStyle + : Option → Text + = λ(o : Option) + → merge { Long = λ(t : Text) → "--${t}", Short = λ(t : Text) → "-${t}" } o + +in newStyle diff --git a/pkgs/profpatsch/dhallsh/OptionPrinter/type.dhall b/pkgs/profpatsch/dhallsh/OptionPrinter/type.dhall new file mode 100644 index 00000000..77d4b8e2 --- /dev/null +++ b/pkgs/profpatsch/dhallsh/OptionPrinter/type.dhall @@ -0,0 +1 @@ +let Option = ../Option/type.dhall in ∀(o : Option) → Text diff --git a/pkgs/profpatsch/dhallsh/main.dhall b/pkgs/profpatsch/dhallsh/main.dhall new file mode 100644 index 00000000..aea25bb1 --- /dev/null +++ b/pkgs/profpatsch/dhallsh/main.dhall @@ -0,0 +1,101 @@ +let Prelude = + https://prelude.dhall-lang.org/package.dhall sha256:2acd9f8eae045eae46d8288d76b01678c4ac4883a58eadb6be0da00b3ba590cf + +let List/filterOptional = ./List/filterOptional.dhall + +let Command = ./Command/type.dhall + +let Option = ./Option/type.dhall + +let Argument = ./Argument/type.dhall + +let Complete = + { cmd : + Text + , description : + Text + , condition : + Optional Text + , short-option : + Optional Text + , long-option : + Optional Text + , long-option-old-style : + Optional Text + , arguments : + Optional Text + , keep-order : + Bool + , no-files : + Bool + , require-parameter : + Bool + , wraps : + Optional Text + } + +let complete = + λ(a : { cmd : Text, description : Text }) + → { cmd = + a.cmd + , description = + a.description + , condition = + None Text + , short-option = + None Text + , long-option = + None Text + , long-option-old-style = + None Text + , arguments = + None Text + , keep-order = + False + , no-files = + False + , require-parameter = + False + , wraps = + None Text + } + +let completeToCommand + : Complete → Command Argument + = let l = λ(o : Text) → Option.Long o + + in λ(c : Complete) + → let long = + λ(name : Text) + → λ(content : Text) + → Argument.Option { opt = Option.Long name, arg = content } + + let args = + [ Some (long "description" c.description) + , Prelude.Optional.map + Text + Argument + (long "condition") + c.condition + ] + : List (Optional Argument) + + let id = λ(a : Optional Argument) → a + + in { cmd = + c.cmd + , args = + List/filterOptional (Optional Argument) Argument id args + : List Argument + } + +in let foo = + completeToCommand (complete { cmd = "complete", description = "foo" }) + + in [ [ foo.cmd ] + # Prelude.List.concatMap + Argument + Text + (./Argument/toArgList.dhall ./OptionPrinter/newStyle.dhall) + foo.args + ] diff --git a/pkgs/profpatsch/dhallsh/shell.nix b/pkgs/profpatsch/dhallsh/shell.nix new file mode 100644 index 00000000..3b5af77b --- /dev/null +++ b/pkgs/profpatsch/dhallsh/shell.nix @@ -0,0 +1,15 @@ +let pkgs = import {}; + simple = import (pkgs.fetchFromGitHub { + owner = "justinwoo"; + repo = "easy-dhall-nix"; + rev = "14f7e929210e928f7b5beade5ef163a62a5d1f4b"; + sha256 = "02f5723rx4q4b53dbckmc7mgzfc1m27xbh1m8rkdhlkklwb5jydp"; + }) {}; + +in + pkgs.mkShell { + name = "dhallsh"; + buildInputs = [ + simple.dhall-simple + ]; + } -- cgit 1.4.1 From 07df02fb273e6263a0ac0cec96bb7e5c3b379032 Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Sun, 8 Sep 2019 14:12:53 +0200 Subject: Add dhall-to-shell script (to convert (List (List Text)) to sh) --- pkgs/profpatsch/dhallsh/shell.nix | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkgs/profpatsch/dhallsh/shell.nix b/pkgs/profpatsch/dhallsh/shell.nix index 3b5af77b..c744c158 100644 --- a/pkgs/profpatsch/dhallsh/shell.nix +++ b/pkgs/profpatsch/dhallsh/shell.nix @@ -6,10 +6,16 @@ let pkgs = import {}; sha256 = "02f5723rx4q4b53dbckmc7mgzfc1m27xbh1m8rkdhlkklwb5jydp"; }) {}; + dhall-to-shell = pkgs.writers.writeBashBin "dhall-to-shell" '' + ${simple.dhall-json-simple}/bin/dhall-to-json \ + | ${pkgs.jq}/bin/jq -r 'map(@sh) | join("\n")' + ''; + in pkgs.mkShell { name = "dhallsh"; buildInputs = [ + dhall-to-shell simple.dhall-simple ]; } -- cgit 1.4.1 From 654e7f931201a7fe435624aa4412bb1fcc4fedb7 Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Mon, 9 Sep 2019 01:42:29 +0200 Subject: First working fish subcommand completion. --- pkgs/profpatsch/dhallsh/Command/toList.dhall | 12 +++ pkgs/profpatsch/dhallsh/imports/Prelude.dhall | 1 + pkgs/profpatsch/dhallsh/main.dhall | 123 +++++++++++++++++--------- 3 files changed, 94 insertions(+), 42 deletions(-) create mode 100644 pkgs/profpatsch/dhallsh/Command/toList.dhall create mode 100644 pkgs/profpatsch/dhallsh/imports/Prelude.dhall diff --git a/pkgs/profpatsch/dhallsh/Command/toList.dhall b/pkgs/profpatsch/dhallsh/Command/toList.dhall new file mode 100644 index 00000000..23605a3f --- /dev/null +++ b/pkgs/profpatsch/dhallsh/Command/toList.dhall @@ -0,0 +1,12 @@ +let Prelude = ../imports/Prelude.dhall + +let Command = ./type.dhall + +let toList + : ∀(a : Type) → (a → List Text) → Command a → List Text + = λ(a : Type) + → λ(f : a → List Text) + → λ(c : Command a) + → [ c.cmd ] # Prelude.List.concatMap a Text f c.args + +in toList diff --git a/pkgs/profpatsch/dhallsh/imports/Prelude.dhall b/pkgs/profpatsch/dhallsh/imports/Prelude.dhall new file mode 100644 index 00000000..8b2a62a0 --- /dev/null +++ b/pkgs/profpatsch/dhallsh/imports/Prelude.dhall @@ -0,0 +1 @@ +https://prelude.dhall-lang.org/package.dhall sha256:2acd9f8eae045eae46d8288d76b01678c4ac4883a58eadb6be0da00b3ba590cf diff --git a/pkgs/profpatsch/dhallsh/main.dhall b/pkgs/profpatsch/dhallsh/main.dhall index aea25bb1..36be6142 100644 --- a/pkgs/profpatsch/dhallsh/main.dhall +++ b/pkgs/profpatsch/dhallsh/main.dhall @@ -1,5 +1,4 @@ -let Prelude = - https://prelude.dhall-lang.org/package.dhall sha256:2acd9f8eae045eae46d8288d76b01678c4ac4883a58eadb6be0da00b3ba590cf +let Prelude = ./imports/Prelude.dhall let List/filterOptional = ./List/filterOptional.dhall @@ -15,14 +14,14 @@ let Complete = , description : Text , condition : - Optional Text + Optional (Command Argument) , short-option : Optional Text , long-option : Optional Text , long-option-old-style : Optional Text - , arguments : + , argument : Optional Text , keep-order : Bool @@ -34,6 +33,12 @@ let Complete = Optional Text } +let argCommandToList + : Command Argument → List Text + = ./Command/toList.dhall + Argument + (./Argument/toArgList.dhall ./OptionPrinter/newStyle.dhall) + let complete = λ(a : { cmd : Text, description : Text }) → { cmd = @@ -41,19 +46,19 @@ let complete = , description = a.description , condition = - None Text + None (Command Argument) , short-option = None Text , long-option = None Text , long-option-old-style = None Text - , arguments = + , argument = None Text , keep-order = False , no-files = - False + True , require-parameter = False , wraps = @@ -62,40 +67,74 @@ let complete = let completeToCommand : Complete → Command Argument - = let l = λ(o : Text) → Option.Long o - - in λ(c : Complete) - → let long = - λ(name : Text) - → λ(content : Text) + = λ(c : Complete) + → let long = + λ(name : Text) + → Prelude.Optional.map + Text + Argument + ( λ(content : Text) → Argument.Option { opt = Option.Long name, arg = content } + ) + + let flag = + λ(name : Text) + → λ(flag : Bool) + → if flag + + then Some (Argument.Flag (Option.Long name)) + + else None Argument + + let conditionToText = + λ(c : Command Argument) + → Prelude.Text.concatSep " " (argCommandToList c) + + let args = + [ long "command" (Some c.cmd) + , long "description" (Some c.description) + , Prelude.Optional.map + (Command Argument) + Argument + ( λ(c : Command Argument) + → Argument.Option + { opt = Option.Long "condition", arg = conditionToText c } + ) + c.condition + , long "short-option" c.short-option + , long "long-option" c.long-option + , long "old-option" c.long-option-old-style + , long "arguments" c.argument + , long "wraps" c.wraps + , flag "keep-order" c.keep-order + , flag "no-files" c.no-files + , flag "require-parameter" c.require-parameter + ] + : List (Optional Argument) + + let id = λ(a : Optional Argument) → a + + in { cmd = + "complete" + , args = + List/filterOptional (Optional Argument) Argument id args + : List Argument + } + +in let fishSeenSubcommandFn = "__fish_seen_subcommand_from" + + let fishUseSubcommandFn = "__fish_use_subcommand" + + let foo + : Command Argument + = completeToCommand + ( complete { cmd = "abc", description = "this is foo option" } + ⫽ { condition = + Some { cmd = fishUseSubcommandFn, args = [] : List Argument } + , argument = + Some "foo" + } + ) - let args = - [ Some (long "description" c.description) - , Prelude.Optional.map - Text - Argument - (long "condition") - c.condition - ] - : List (Optional Argument) - - let id = λ(a : Optional Argument) → a - - in { cmd = - c.cmd - , args = - List/filterOptional (Optional Argument) Argument id args - : List Argument - } - -in let foo = - completeToCommand (complete { cmd = "complete", description = "foo" }) - - in [ [ foo.cmd ] - # Prelude.List.concatMap - Argument - Text - (./Argument/toArgList.dhall ./OptionPrinter/newStyle.dhall) - foo.args - ] + in [ argCommandToList foo, [ "complete", "--do-complete=abc " ] ] + : List (List Text) -- cgit 1.4.1 From dcf2f789cca133b27d408f984bb398b14ea925d3 Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Mon, 9 Sep 2019 01:54:51 +0200 Subject: `abc foo --bar` can be completed --- pkgs/profpatsch/dhallsh/main.dhall | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/pkgs/profpatsch/dhallsh/main.dhall b/pkgs/profpatsch/dhallsh/main.dhall index 36be6142..86300b79 100644 --- a/pkgs/profpatsch/dhallsh/main.dhall +++ b/pkgs/profpatsch/dhallsh/main.dhall @@ -125,7 +125,7 @@ in let fishSeenSubcommandFn = "__fish_seen_subcommand_from" let fishUseSubcommandFn = "__fish_use_subcommand" - let foo + let fooSubcommand : Command Argument = completeToCommand ( complete { cmd = "abc", description = "this is foo option" } @@ -136,5 +136,26 @@ in let fishSeenSubcommandFn = "__fish_seen_subcommand_from" } ) - in [ argCommandToList foo, [ "complete", "--do-complete=abc " ] ] + let fooSubcommandBarOption + : Command Argument + = completeToCommand + ( complete { cmd = "abc", description = "will bar the baz" } + ⫽ { condition = + Some + { cmd = + fishSeenSubcommandFn + , args = + [ Argument.Plain "foo" ] + } + , long-option = + Some "bar" + , short-option = + Some "b" + } + ) + + in [ argCommandToList fooSubcommand + , argCommandToList fooSubcommandBarOption + , [ "complete", "--do-complete=abc foo -" ] + ] : List (List Text) -- cgit 1.4.1 From d43a8e155a9b5c79ffb0f881a0b273c188de9704 Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Sat, 14 Sep 2019 22:59:15 +0200 Subject: main: factor out basic fish completion commands --- .../profpatsch/dhallsh/Fish/Complete/default.dhall | 28 +++ .../dhallsh/Fish/Complete/toCommand.dhall | 77 ++++++++ pkgs/profpatsch/dhallsh/Fish/Complete/type.dhall | 27 +++ pkgs/profpatsch/dhallsh/main.dhall | 193 +++++---------------- 4 files changed, 176 insertions(+), 149 deletions(-) create mode 100644 pkgs/profpatsch/dhallsh/Fish/Complete/default.dhall create mode 100644 pkgs/profpatsch/dhallsh/Fish/Complete/toCommand.dhall create mode 100644 pkgs/profpatsch/dhallsh/Fish/Complete/type.dhall diff --git a/pkgs/profpatsch/dhallsh/Fish/Complete/default.dhall b/pkgs/profpatsch/dhallsh/Fish/Complete/default.dhall new file mode 100644 index 00000000..0405f921 --- /dev/null +++ b/pkgs/profpatsch/dhallsh/Fish/Complete/default.dhall @@ -0,0 +1,28 @@ +let Command = ../../Command/type.dhall + +let Argument = ../../Argument/type.dhall + +in λ(a : { cmd : Text, description : Text }) + → { cmd = + a.cmd + , description = + a.description + , condition = + None (Command Argument) + , short-option = + None Text + , long-option = + None Text + , long-option-old-style = + None Text + , argument = + None Text + , keep-order = + False + , no-files = + True + , require-parameter = + False + , wraps = + None Text + } diff --git a/pkgs/profpatsch/dhallsh/Fish/Complete/toCommand.dhall b/pkgs/profpatsch/dhallsh/Fish/Complete/toCommand.dhall new file mode 100644 index 00000000..f7453b65 --- /dev/null +++ b/pkgs/profpatsch/dhallsh/Fish/Complete/toCommand.dhall @@ -0,0 +1,77 @@ +let Prelude = ../../imports/Prelude.dhall + +let Command = ../../Command/type.dhall + +let Argument = ../../Argument/type.dhall + +let Option = ../../Option/type.dhall + +let OptionPrinter = ../../OptionPrinter/type.dhall + +let Complete = ./type.dhall + +in λ(conditionOptionPrinter : OptionPrinter) + → λ(c : Complete) + → let long = + λ(name : Text) + → Prelude.Optional.map + Text + Argument + ( λ(content : Text) + → Argument.Option { opt = Option.Long name, arg = content } + ) + + let flag = + λ(name : Text) + → λ(flag : Bool) + → if flag + + then Some (Argument.Flag (Option.Long name)) + + else None Argument + + let conditionToText = + λ(c : Command Argument) + → Prelude.Text.concatSep + " " + ( ../../Command/toList.dhall + Argument + (../../Argument/toArgList.dhall conditionOptionPrinter) + c + ) + : Text + + let args = + [ long "command" (Some c.cmd) + , long "description" (Some c.description) + , Prelude.Optional.map + (Command Argument) + Argument + ( λ(c : Command Argument) + → Argument.Option + { opt = Option.Long "condition", arg = conditionToText c } + ) + c.condition + , long "short-option" c.short-option + , long "long-option" c.long-option + , long "old-option" c.long-option-old-style + , long "arguments" c.argument + , long "wraps" c.wraps + , flag "keep-order" c.keep-order + , flag "no-files" c.no-files + , flag "require-parameter" c.require-parameter + ] + : List (Optional Argument) + + let id = λ(a : Optional Argument) → a + + in { cmd = + "complete" + , args = + ../../List/filterOptional.dhall + (Optional Argument) + Argument + id + args + : List Argument + } diff --git a/pkgs/profpatsch/dhallsh/Fish/Complete/type.dhall b/pkgs/profpatsch/dhallsh/Fish/Complete/type.dhall new file mode 100644 index 00000000..c208f67a --- /dev/null +++ b/pkgs/profpatsch/dhallsh/Fish/Complete/type.dhall @@ -0,0 +1,27 @@ +let Command = ../../Command/type.dhall + +let Argument = ../../Argument/type.dhall + +in { cmd : + Text + , description : + Text + , condition : + Optional (Command Argument) + , short-option : + Optional Text + , long-option : + Optional Text + , long-option-old-style : + Optional Text + , argument : + Optional Text + , keep-order : + Bool + , no-files : + Bool + , require-parameter : + Bool + , wraps : + Optional Text + } diff --git a/pkgs/profpatsch/dhallsh/main.dhall b/pkgs/profpatsch/dhallsh/main.dhall index 86300b79..abf53032 100644 --- a/pkgs/profpatsch/dhallsh/main.dhall +++ b/pkgs/profpatsch/dhallsh/main.dhall @@ -1,161 +1,56 @@ -let Prelude = ./imports/Prelude.dhall - -let List/filterOptional = ./List/filterOptional.dhall - let Command = ./Command/type.dhall -let Option = ./Option/type.dhall - let Argument = ./Argument/type.dhall -let Complete = - { cmd : - Text - , description : - Text - , condition : - Optional (Command Argument) - , short-option : - Optional Text - , long-option : - Optional Text - , long-option-old-style : - Optional Text - , argument : - Optional Text - , keep-order : - Bool - , no-files : - Bool - , require-parameter : - Bool - , wraps : - Optional Text - } +let Complete = ./Fish/Complete/type.dhall let argCommandToList - : Command Argument → List Text - = ./Command/toList.dhall - Argument - (./Argument/toArgList.dhall ./OptionPrinter/newStyle.dhall) + : Command Argument → List Text + = ./Command/toList.dhall + Argument + (./Argument/toArgList.dhall ./OptionPrinter/newStyle.dhall) -let complete = - λ(a : { cmd : Text, description : Text }) - → { cmd = - a.cmd - , description = - a.description - , condition = - None (Command Argument) - , short-option = - None Text - , long-option = - None Text - , long-option-old-style = - None Text - , argument = - None Text - , keep-order = - False - , no-files = - True - , require-parameter = - False - , wraps = - None Text - } +let complete = ./Fish/Complete/default.dhall let completeToCommand - : Complete → Command Argument - = λ(c : Complete) - → let long = - λ(name : Text) - → Prelude.Optional.map - Text - Argument - ( λ(content : Text) - → Argument.Option { opt = Option.Long name, arg = content } - ) - - let flag = - λ(name : Text) - → λ(flag : Bool) - → if flag - - then Some (Argument.Flag (Option.Long name)) - - else None Argument - - let conditionToText = - λ(c : Command Argument) - → Prelude.Text.concatSep " " (argCommandToList c) - - let args = - [ long "command" (Some c.cmd) - , long "description" (Some c.description) - , Prelude.Optional.map - (Command Argument) - Argument - ( λ(c : Command Argument) - → Argument.Option - { opt = Option.Long "condition", arg = conditionToText c } - ) - c.condition - , long "short-option" c.short-option - , long "long-option" c.long-option - , long "old-option" c.long-option-old-style - , long "arguments" c.argument - , long "wraps" c.wraps - , flag "keep-order" c.keep-order - , flag "no-files" c.no-files - , flag "require-parameter" c.require-parameter - ] - : List (Optional Argument) - - let id = λ(a : Optional Argument) → a - - in { cmd = - "complete" - , args = - List/filterOptional (Optional Argument) Argument id args - : List Argument - } + : Complete → Command Argument + = ./Fish/Complete/toCommand.dhall ./OptionPrinter/newStyle.dhall in let fishSeenSubcommandFn = "__fish_seen_subcommand_from" - let fishUseSubcommandFn = "__fish_use_subcommand" - - let fooSubcommand - : Command Argument - = completeToCommand - ( complete { cmd = "abc", description = "this is foo option" } - ⫽ { condition = - Some { cmd = fishUseSubcommandFn, args = [] : List Argument } - , argument = - Some "foo" - } - ) - - let fooSubcommandBarOption - : Command Argument - = completeToCommand - ( complete { cmd = "abc", description = "will bar the baz" } - ⫽ { condition = - Some - { cmd = - fishSeenSubcommandFn - , args = - [ Argument.Plain "foo" ] - } - , long-option = - Some "bar" - , short-option = - Some "b" - } - ) - - in [ argCommandToList fooSubcommand - , argCommandToList fooSubcommandBarOption - , [ "complete", "--do-complete=abc foo -" ] - ] - : List (List Text) + let fishUseSubcommandFn = "__fish_use_subcommand" + + let fooSubcommand + : Command Argument + = completeToCommand + ( complete { cmd = "abc", description = "this is foo option" } + ⫽ { condition = + Some { cmd = fishUseSubcommandFn, args = [] : List Argument } + , argument = + Some "foo" + } + ) + + let fooSubcommandBarOption + : Command Argument + = completeToCommand + ( complete { cmd = "abc", description = "will bar the baz" } + ⫽ { condition = + Some + { cmd = + fishSeenSubcommandFn + , args = + [ Argument.Plain "foo" ] + } + , long-option = + Some "bar" + , short-option = + Some "b" + } + ) + + in [ argCommandToList fooSubcommand + , argCommandToList fooSubcommandBarOption + , [ "complete", "--do-complete=abc foo -" ] + ] + : List (List Text) -- cgit 1.4.1 From 7d84c35f506ebd0e76486ac5205e48c4c1757289 Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Sun, 15 Sep 2019 00:29:33 +0200 Subject: completion.dhall: add completion options for dhall command line --- pkgs/profpatsch/dhallsh/completion.dhall | 134 +++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 pkgs/profpatsch/dhallsh/completion.dhall diff --git a/pkgs/profpatsch/dhallsh/completion.dhall b/pkgs/profpatsch/dhallsh/completion.dhall new file mode 100644 index 00000000..9df63144 --- /dev/null +++ b/pkgs/profpatsch/dhallsh/completion.dhall @@ -0,0 +1,134 @@ +let Void = + https://raw.githubusercontent.com/sellout/dada/master/Void/Type sha256:a413d5091ac5fb02410f02bdbede12eacd89ae52a933a6d24bb68eadbff92613 + +let Option = + { short : + Optional Text + , long : + Text + , description : + Text + , argument : + Optional Text + } + +let Command = + λ(a : Type) + → { name : + Text + , description : + Text + , options : + List Option + , subcommands : + List a + } + +let opt = + λ(long : Text) + → λ(description : Text) + → { long = + long + , description = + description + , argument = + None Text + , short = + None Text + } + +let fileOpt = + opt "file" "Read expression from a file instead of standard input" + ⫽ { argument = Some "FILE" } + +let alphaOpt = opt "alpha" "α-normalize expression" + +let inplaceOpt = + opt "inplace" "Modify the specified file in-place" + ⫽ { argument = Some "FILE" } + +let jsonOpt = opt "json" "Use JSON representation of CBOR" + +let leafCommand = + λ(name : Text) + → λ(description : Text) + → { options = + [] : List Option + , subcommands = + [] : List Void + , name = + name + , description = + description + } + +in { name = + "dhall" + , description = + "Interpreter for the Dhall language" + , options = + [ opt "annotate" "Add a type annotation to the output" + , alphaOpt + , opt "explain" "Explain error messages in more detail" + , opt "plain" "Disable syntax highlighting" + , opt "ascii" "Format code using only ASCII syntax" + , opt "standard-version" "The standard version to use" + ⫽ { argument = Some "X.Y.Z" } + ] + , subcommands = + [ leafCommand + "version" + "Display version" + , leafCommand "resolve" "Resolve an expression's imports" + ⫽ { options = + [ fileOpt + , opt "dot" "Output import dependency graph in dot format" + , opt + "immediate-dependencies" + "List immediate import dependencies" + , opt + "transitive-dependencies" + "List transitive import dependencies" + ] + } + , leafCommand "type" "Infer an expression's type" + ⫽ { options = [ fileOpt ] } + , leafCommand "normalize" "Normalize an expression" + ⫽ { options = [ fileOpt, alphaOpt ] } + , leafCommand "repl" "Interpret expressions in a REPL" + , leafCommand + "diff" + "Render the difference between the normal form of two expressions" + , leafCommand "hash" "Compute semantic hashes for Dhall expressions" + , leafCommand "lint" "Improve Dhall code" + ⫽ { options = [ inplaceOpt ] } + , leafCommand "format" "Formatter for the Dhall language" + ⫽ { options = + [ opt "check" "Only check if the input is formatted" + , inplaceOpt + ] + } + , leafCommand + "freeze" + "Add integrity checks to remote import statements of an expression" + ⫽ { options = + [ inplaceOpt + , opt + "all" + "Add integrity checks to all imports (not just remote imports)" + , opt + "cache" + "Add fallback unprotected imports when using integrity checks purely for caching purposes" + ] + } + , leafCommand "encode" "Encode a Dhall expression to binary" + ⫽ { options = [ fileOpt, jsonOpt ] } + , leafCommand "decode" "Decode a Dhall expression from binary" + ⫽ { options = [ fileOpt, jsonOpt ] } + , leafCommand + "text" + "Render a Dhall expression that evaluates to a Text literal" + ⫽ { options = [ fileOpt ] } + ] + } + : Command (Command Void) -- cgit 1.4.1 From c6ffd4102d5f250225551a18dda7bb13b5eab354 Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Sun, 15 Sep 2019 00:43:48 +0200 Subject: completion: move to Completion module & factor out types --- .../dhallsh/Completion/Command/type.dhall | 10 ++ .../dhallsh/Completion/Option/type.dhall | 9 ++ .../profpatsch/dhallsh/Completion/completion.dhall | 114 ++++++++++++++++++ pkgs/profpatsch/dhallsh/completion.dhall | 134 --------------------- 4 files changed, 133 insertions(+), 134 deletions(-) create mode 100644 pkgs/profpatsch/dhallsh/Completion/Command/type.dhall create mode 100644 pkgs/profpatsch/dhallsh/Completion/Option/type.dhall create mode 100644 pkgs/profpatsch/dhallsh/Completion/completion.dhall delete mode 100644 pkgs/profpatsch/dhallsh/completion.dhall diff --git a/pkgs/profpatsch/dhallsh/Completion/Command/type.dhall b/pkgs/profpatsch/dhallsh/Completion/Command/type.dhall new file mode 100644 index 00000000..a0fd4e98 --- /dev/null +++ b/pkgs/profpatsch/dhallsh/Completion/Command/type.dhall @@ -0,0 +1,10 @@ + λ(a : Type) +→ { name : + Text + , description : + Text + , options : + List ../Option/type.dhall + , subcommands : + List a + } diff --git a/pkgs/profpatsch/dhallsh/Completion/Option/type.dhall b/pkgs/profpatsch/dhallsh/Completion/Option/type.dhall new file mode 100644 index 00000000..44f62d2e --- /dev/null +++ b/pkgs/profpatsch/dhallsh/Completion/Option/type.dhall @@ -0,0 +1,9 @@ +{ short : + Optional Text +, long : + Text +, description : + Text +, argument : + Optional Text +} diff --git a/pkgs/profpatsch/dhallsh/Completion/completion.dhall b/pkgs/profpatsch/dhallsh/Completion/completion.dhall new file mode 100644 index 00000000..e5b849a7 --- /dev/null +++ b/pkgs/profpatsch/dhallsh/Completion/completion.dhall @@ -0,0 +1,114 @@ +let Void = ../imports/Void.dhall + +let Option = ./Option/type.dhall + +let Command = ./Command/type.dhall + +let opt = + λ(long : Text) + → λ(description : Text) + → { long = + long + , description = + description + , argument = + None Text + , short = + None Text + } + +let fileOpt = + opt "file" "Read expression from a file instead of standard input" + ⫽ { argument = Some "FILE" } + +let alphaOpt = opt "alpha" "α-normalize expression" + +let inplaceOpt = + opt "inplace" "Modify the specified file in-place" + ⫽ { argument = Some "FILE" } + +let jsonOpt = opt "json" "Use JSON representation of CBOR" + +let leafCommand = + λ(name : Text) + → λ(description : Text) + → { options = + [] : List Option + , subcommands = + [] : List Void + , name = + name + , description = + description + } + +in { name = + "dhall" + , description = + "Interpreter for the Dhall language" + , options = + [ opt "annotate" "Add a type annotation to the output" + , alphaOpt + , opt "explain" "Explain error messages in more detail" + , opt "plain" "Disable syntax highlighting" + , opt "ascii" "Format code using only ASCII syntax" + , opt "standard-version" "The standard version to use" + ⫽ { argument = Some "X.Y.Z" } + ] + , subcommands = + [ leafCommand + "version" + "Display version" + , leafCommand "resolve" "Resolve an expression's imports" + ⫽ { options = + [ fileOpt + , opt "dot" "Output import dependency graph in dot format" + , opt + "immediate-dependencies" + "List immediate import dependencies" + , opt + "transitive-dependencies" + "List transitive import dependencies" + ] + } + , leafCommand "type" "Infer an expression's type" + ⫽ { options = [ fileOpt ] } + , leafCommand "normalize" "Normalize an expression" + ⫽ { options = [ fileOpt, alphaOpt ] } + , leafCommand "repl" "Interpret expressions in a REPL" + , leafCommand + "diff" + "Render the difference between the normal form of two expressions" + , leafCommand "hash" "Compute semantic hashes for Dhall expressions" + , leafCommand "lint" "Improve Dhall code" + ⫽ { options = [ inplaceOpt ] } + , leafCommand "format" "Formatter for the Dhall language" + ⫽ { options = + [ opt "check" "Only check if the input is formatted" + , inplaceOpt + ] + } + , leafCommand + "freeze" + "Add integrity checks to remote import statements of an expression" + ⫽ { options = + [ inplaceOpt + , opt + "all" + "Add integrity checks to all imports (not just remote imports)" + , opt + "cache" + "Add fallback unprotected imports when using integrity checks purely for caching purposes" + ] + } + , leafCommand "encode" "Encode a Dhall expression to binary" + ⫽ { options = [ fileOpt, jsonOpt ] } + , leafCommand "decode" "Decode a Dhall expression from binary" + ⫽ { options = [ fileOpt, jsonOpt ] } + , leafCommand + "text" + "Render a Dhall expression that evaluates to a Text literal" + ⫽ { options = [ fileOpt ] } + ] + } + : Command (Command Void) diff --git a/pkgs/profpatsch/dhallsh/completion.dhall b/pkgs/profpatsch/dhallsh/completion.dhall deleted file mode 100644 index 9df63144..00000000 --- a/pkgs/profpatsch/dhallsh/completion.dhall +++ /dev/null @@ -1,134 +0,0 @@ -let Void = - https://raw.githubusercontent.com/sellout/dada/master/Void/Type sha256:a413d5091ac5fb02410f02bdbede12eacd89ae52a933a6d24bb68eadbff92613 - -let Option = - { short : - Optional Text - , long : - Text - , description : - Text - , argument : - Optional Text - } - -let Command = - λ(a : Type) - → { name : - Text - , description : - Text - , options : - List Option - , subcommands : - List a - } - -let opt = - λ(long : Text) - → λ(description : Text) - → { long = - long - , description = - description - , argument = - None Text - , short = - None Text - } - -let fileOpt = - opt "file" "Read expression from a file instead of standard input" - ⫽ { argument = Some "FILE" } - -let alphaOpt = opt "alpha" "α-normalize expression" - -let inplaceOpt = - opt "inplace" "Modify the specified file in-place" - ⫽ { argument = Some "FILE" } - -let jsonOpt = opt "json" "Use JSON representation of CBOR" - -let leafCommand = - λ(name : Text) - → λ(description : Text) - → { options = - [] : List Option - , subcommands = - [] : List Void - , name = - name - , description = - description - } - -in { name = - "dhall" - , description = - "Interpreter for the Dhall language" - , options = - [ opt "annotate" "Add a type annotation to the output" - , alphaOpt - , opt "explain" "Explain error messages in more detail" - , opt "plain" "Disable syntax highlighting" - , opt "ascii" "Format code using only ASCII syntax" - , opt "standard-version" "The standard version to use" - ⫽ { argument = Some "X.Y.Z" } - ] - , subcommands = - [ leafCommand - "version" - "Display version" - , leafCommand "resolve" "Resolve an expression's imports" - ⫽ { options = - [ fileOpt - , opt "dot" "Output import dependency graph in dot format" - , opt - "immediate-dependencies" - "List immediate import dependencies" - , opt - "transitive-dependencies" - "List transitive import dependencies" - ] - } - , leafCommand "type" "Infer an expression's type" - ⫽ { options = [ fileOpt ] } - , leafCommand "normalize" "Normalize an expression" - ⫽ { options = [ fileOpt, alphaOpt ] } - , leafCommand "repl" "Interpret expressions in a REPL" - , leafCommand - "diff" - "Render the difference between the normal form of two expressions" - , leafCommand "hash" "Compute semantic hashes for Dhall expressions" - , leafCommand "lint" "Improve Dhall code" - ⫽ { options = [ inplaceOpt ] } - , leafCommand "format" "Formatter for the Dhall language" - ⫽ { options = - [ opt "check" "Only check if the input is formatted" - , inplaceOpt - ] - } - , leafCommand - "freeze" - "Add integrity checks to remote import statements of an expression" - ⫽ { options = - [ inplaceOpt - , opt - "all" - "Add integrity checks to all imports (not just remote imports)" - , opt - "cache" - "Add fallback unprotected imports when using integrity checks purely for caching purposes" - ] - } - , leafCommand "encode" "Encode a Dhall expression to binary" - ⫽ { options = [ fileOpt, jsonOpt ] } - , leafCommand "decode" "Decode a Dhall expression from binary" - ⫽ { options = [ fileOpt, jsonOpt ] } - , leafCommand - "text" - "Render a Dhall expression that evaluates to a Text literal" - ⫽ { options = [ fileOpt ] } - ] - } - : Command (Command Void) -- cgit 1.4.1 From de078b5a13e50aef7b28f65ea728c84936a2783b Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Mon, 16 Sep 2019 00:56:37 +0200 Subject: Mostly implement nice completion for dhall A few bugs are still remainaing, but it can recognize when files should be completed for example. --- .../dhallsh/Completion/Command/Arguments.dhall | 1 + .../dhallsh/Completion/Command/package.dhall | 1 + .../dhallsh/Completion/Command/type.dhall | 4 +- .../dhallsh/Completion/Option/type.dhall | 10 +- .../profpatsch/dhallsh/Completion/completion.dhall | 168 ++++++++++---------- pkgs/profpatsch/dhallsh/Completion/package.dhall | 1 + .../dhallsh/Fish/Complete/toCommand.dhall | 2 +- pkgs/profpatsch/dhallsh/imports/Void.dhall | 1 + pkgs/profpatsch/dhallsh/main.dhall | 173 ++++++++++++++++----- 9 files changed, 235 insertions(+), 126 deletions(-) create mode 100644 pkgs/profpatsch/dhallsh/Completion/Command/Arguments.dhall create mode 100644 pkgs/profpatsch/dhallsh/Completion/Command/package.dhall create mode 100644 pkgs/profpatsch/dhallsh/Completion/package.dhall create mode 100644 pkgs/profpatsch/dhallsh/imports/Void.dhall diff --git a/pkgs/profpatsch/dhallsh/Completion/Command/Arguments.dhall b/pkgs/profpatsch/dhallsh/Completion/Command/Arguments.dhall new file mode 100644 index 00000000..e9ec3663 --- /dev/null +++ b/pkgs/profpatsch/dhallsh/Completion/Command/Arguments.dhall @@ -0,0 +1 @@ +λ(a : Type) → < Subcommands : List a | Files > diff --git a/pkgs/profpatsch/dhallsh/Completion/Command/package.dhall b/pkgs/profpatsch/dhallsh/Completion/Command/package.dhall new file mode 100644 index 00000000..6475acf9 --- /dev/null +++ b/pkgs/profpatsch/dhallsh/Completion/Command/package.dhall @@ -0,0 +1 @@ +{ Type = ./type.dhall, Arguments = ./Arguments.dhall } diff --git a/pkgs/profpatsch/dhallsh/Completion/Command/type.dhall b/pkgs/profpatsch/dhallsh/Completion/Command/type.dhall index a0fd4e98..ffbcd2bf 100644 --- a/pkgs/profpatsch/dhallsh/Completion/Command/type.dhall +++ b/pkgs/profpatsch/dhallsh/Completion/Command/type.dhall @@ -5,6 +5,6 @@ Text , options : List ../Option/type.dhall - , subcommands : - List a + , arguments : + ./Arguments.dhall a } diff --git a/pkgs/profpatsch/dhallsh/Completion/Option/type.dhall b/pkgs/profpatsch/dhallsh/Completion/Option/type.dhall index 44f62d2e..9f5d14f1 100644 --- a/pkgs/profpatsch/dhallsh/Completion/Option/type.dhall +++ b/pkgs/profpatsch/dhallsh/Completion/Option/type.dhall @@ -1,9 +1 @@ -{ short : - Optional Text -, long : - Text -, description : - Text -, argument : - Optional Text -} +{ short : Optional Text, long : Text, description : Text, takes-files : Bool } diff --git a/pkgs/profpatsch/dhallsh/Completion/completion.dhall b/pkgs/profpatsch/dhallsh/Completion/completion.dhall index e5b849a7..4b5bdad0 100644 --- a/pkgs/profpatsch/dhallsh/Completion/completion.dhall +++ b/pkgs/profpatsch/dhallsh/Completion/completion.dhall @@ -2,30 +2,30 @@ let Void = ../imports/Void.dhall let Option = ./Option/type.dhall -let Command = ./Command/type.dhall +let Command = ./Command/package.dhall let opt = λ(long : Text) → λ(description : Text) → { long = long - , description = - description - , argument = - None Text , short = None Text + , description = + description + , takes-files = + False } let fileOpt = opt "file" "Read expression from a file instead of standard input" - ⫽ { argument = Some "FILE" } + ⫽ { takes-files = True } let alphaOpt = opt "alpha" "α-normalize expression" let inplaceOpt = opt "inplace" "Modify the specified file in-place" - ⫽ { argument = Some "FILE" } + ⫽ { takes-files = True } let jsonOpt = opt "json" "Use JSON representation of CBOR" @@ -34,81 +34,93 @@ let leafCommand = → λ(description : Text) → { options = [] : List Option - , subcommands = - [] : List Void + , arguments = + (Command.Arguments Void).Subcommands ([] : List Void) , name = name , description = description } -in { name = - "dhall" - , description = - "Interpreter for the Dhall language" - , options = - [ opt "annotate" "Add a type annotation to the output" - , alphaOpt - , opt "explain" "Explain error messages in more detail" - , opt "plain" "Disable syntax highlighting" - , opt "ascii" "Format code using only ASCII syntax" - , opt "standard-version" "The standard version to use" - ⫽ { argument = Some "X.Y.Z" } - ] - , subcommands = - [ leafCommand - "version" - "Display version" - , leafCommand "resolve" "Resolve an expression's imports" - ⫽ { options = - [ fileOpt - , opt "dot" "Output import dependency graph in dot format" - , opt - "immediate-dependencies" - "List immediate import dependencies" - , opt - "transitive-dependencies" - "List transitive import dependencies" - ] - } - , leafCommand "type" "Infer an expression's type" - ⫽ { options = [ fileOpt ] } - , leafCommand "normalize" "Normalize an expression" - ⫽ { options = [ fileOpt, alphaOpt ] } - , leafCommand "repl" "Interpret expressions in a REPL" - , leafCommand - "diff" - "Render the difference between the normal form of two expressions" - , leafCommand "hash" "Compute semantic hashes for Dhall expressions" - , leafCommand "lint" "Improve Dhall code" - ⫽ { options = [ inplaceOpt ] } - , leafCommand "format" "Formatter for the Dhall language" - ⫽ { options = - [ opt "check" "Only check if the input is formatted" - , inplaceOpt - ] - } - , leafCommand - "freeze" - "Add integrity checks to remote import statements of an expression" - ⫽ { options = - [ inplaceOpt - , opt - "all" - "Add integrity checks to all imports (not just remote imports)" - , opt - "cache" - "Add fallback unprotected imports when using integrity checks purely for caching purposes" - ] - } - , leafCommand "encode" "Encode a Dhall expression to binary" - ⫽ { options = [ fileOpt, jsonOpt ] } - , leafCommand "decode" "Decode a Dhall expression from binary" - ⫽ { options = [ fileOpt, jsonOpt ] } - , leafCommand - "text" - "Render a Dhall expression that evaluates to a Text literal" - ⫽ { options = [ fileOpt ] } - ] +in { toplevelCommandIsSubcommand = + True + , command = + { name = + "dhall" + , description = + "Interpreter for the Dhall language" + , options = + [ fileOpt + , opt "annotate" "Add a type annotation to the output" + , alphaOpt + , opt "explain" "Explain error messages in more detail" + , opt "plain" "Disable syntax highlighting" + , opt "ascii" "Format code using only ASCII syntax" + , opt "standard-version" "The standard version to use" + ] + , arguments = + ( Command.Arguments + (Command.Type Void) + ).Subcommands + [ leafCommand "version" "Display version" + , leafCommand "resolve" "Resolve an expression's imports" + ⫽ { options = + [ fileOpt + , opt "dot" "Output import dependency graph in dot format" + , opt + "immediate-dependencies" + "List immediate import dependencies" + , opt + "transitive-dependencies" + "List transitive import dependencies" + ] + } + , leafCommand "type" "Infer an expression's type" + ⫽ { options = [ fileOpt ] } + , leafCommand "normalize" "Normalize an expression" + ⫽ { options = [ fileOpt, alphaOpt ] } + , leafCommand "repl" "Interpret expressions in a REPL" + , leafCommand + "diff" + "Render the difference between the normal form of two expressions" + ⫽ { arguments = (Command.Arguments Void).Files } + , leafCommand + "hash" + "Compute semantic hashes for Dhall expressions" + , leafCommand "lint" "Improve Dhall code" + ⫽ { options = [ inplaceOpt ] } + , leafCommand "format" "Formatter for the Dhall language" + ⫽ { options = + [ opt "check" "Only check if the input is formatted" + , inplaceOpt + ] + } + , leafCommand + "freeze" + "Add integrity checks to remote import statements of an expression" + ⫽ { options = + [ inplaceOpt + , opt + "all" + "Add integrity checks to all imports (not just remote imports)" + , opt + "cache" + "Add fallback unprotected imports when using integrity checks purely for caching purposes" + ] + } + , leafCommand "encode" "Encode a Dhall expression to binary" + ⫽ { options = [ fileOpt, jsonOpt ] } + , leafCommand "decode" "Decode a Dhall expression from binary" + ⫽ { options = [ fileOpt, jsonOpt ] } + , leafCommand + "text" + "Render a Dhall expression that evaluates to a Text literal" + ⫽ { options = [ fileOpt ] } + ] + } + } + : { command : + Command.Type (Command.Type Void) + , toplevelCommandIsSubcommand : + Bool } - : Command (Command Void) diff --git a/pkgs/profpatsch/dhallsh/Completion/package.dhall b/pkgs/profpatsch/dhallsh/Completion/package.dhall new file mode 100644 index 00000000..01044c54 --- /dev/null +++ b/pkgs/profpatsch/dhallsh/Completion/package.dhall @@ -0,0 +1 @@ +{ Option = ./Option/type.dhall, Command = ./Command/package.dhall } diff --git a/pkgs/profpatsch/dhallsh/Fish/Complete/toCommand.dhall b/pkgs/profpatsch/dhallsh/Fish/Complete/toCommand.dhall index f7453b65..67327b5f 100644 --- a/pkgs/profpatsch/dhallsh/Fish/Complete/toCommand.dhall +++ b/pkgs/profpatsch/dhallsh/Fish/Complete/toCommand.dhall @@ -43,7 +43,6 @@ in λ(conditionOptionPrinter : OptionPrinter) let args = [ long "command" (Some c.cmd) - , long "description" (Some c.description) , Prelude.Optional.map (Command Argument) Argument @@ -60,6 +59,7 @@ in λ(conditionOptionPrinter : OptionPrinter) , flag "keep-order" c.keep-order , flag "no-files" c.no-files , flag "require-parameter" c.require-parameter + , long "description" (Some c.description) ] : List (Optional Argument) diff --git a/pkgs/profpatsch/dhallsh/imports/Void.dhall b/pkgs/profpatsch/dhallsh/imports/Void.dhall new file mode 100644 index 00000000..55a3760e --- /dev/null +++ b/pkgs/profpatsch/dhallsh/imports/Void.dhall @@ -0,0 +1 @@ +https://raw.githubusercontent.com/sellout/dada/master/Void/Type sha256:a413d5091ac5fb02410f02bdbede12eacd89ae52a933a6d24bb68eadbff92613 diff --git a/pkgs/profpatsch/dhallsh/main.dhall b/pkgs/profpatsch/dhallsh/main.dhall index abf53032..f89f7ed1 100644 --- a/pkgs/profpatsch/dhallsh/main.dhall +++ b/pkgs/profpatsch/dhallsh/main.dhall @@ -1,8 +1,12 @@ +let Void = ./imports/Void.dhall + +let Prelude = ./imports/Prelude.dhall + let Command = ./Command/type.dhall let Argument = ./Argument/type.dhall -let Complete = ./Fish/Complete/type.dhall +let FishComplete = ./Fish/Complete/type.dhall let argCommandToList : Command Argument → List Text @@ -13,44 +17,141 @@ let argCommandToList let complete = ./Fish/Complete/default.dhall let completeToCommand - : Complete → Command Argument + : FishComplete → Command Argument = ./Fish/Complete/toCommand.dhall ./OptionPrinter/newStyle.dhall +let Completion = ./Completion/package.dhall + +let InSubcommand = < No | ToplevelSpecial | Subcommand : Text > + in let fishSeenSubcommandFn = "__fish_seen_subcommand_from" let fishUseSubcommandFn = "__fish_use_subcommand" - let fooSubcommand - : Command Argument - = completeToCommand - ( complete { cmd = "abc", description = "this is foo option" } - ⫽ { condition = - Some { cmd = fishUseSubcommandFn, args = [] : List Argument } - , argument = - Some "foo" - } - ) - - let fooSubcommandBarOption - : Command Argument - = completeToCommand - ( complete { cmd = "abc", description = "will bar the baz" } - ⫽ { condition = - Some - { cmd = - fishSeenSubcommandFn - , args = - [ Argument.Plain "foo" ] - } - , long-option = - Some "bar" - , short-option = - Some "b" - } - ) - - in [ argCommandToList fooSubcommand - , argCommandToList fooSubcommandBarOption - , [ "complete", "--do-complete=abc foo -" ] - ] - : List (List Text) + let fishCommandLineExactlyFn = "__fish_command_line_exactly" + + let subcommandCond = + λ(programName : Text) + → λ(inSubcommand : InSubcommand) + → merge + { ToplevelSpecial = + Some + { cmd = + fishCommandLineExactlyFn + , args = + [ Argument.Plain programName ] + } + , Subcommand = + λ(sub : Text) + → Some + { cmd = fishSeenSubcommandFn, args = [ Argument.Plain sub ] } + , No = + None (Command Argument) + } + inSubcommand + : Optional (Command Argument) + + let optionsComplete = + λ(programName : Text) + → λ(inSubcommand : InSubcommand) + → λ(options : List Completion.Option) + → let optcompl = + λ(option : Completion.Option) + → complete + { cmd = programName, description = option.description } + ⫽ { condition = + subcommandCond programName inSubcommand + , short-option = + option.short + , long-option = + Some option.long + } + + in Prelude.List.map Completion.Option FishComplete optcompl options + + let mergeCommandArguments = + λ(programName : Text) + → λ(inSubcommand : InSubcommand) + → λ(a : Type) + → λ(f : List a → List FishComplete) + → λ(arguments : Completion.Command.Arguments a) + → let filesBlock = + complete { cmd = programName, description = "" } + ⫽ { condition = + subcommandCond programName inSubcommand + , no-files = + True + } + + in merge + { Subcommands = + λ(cmds : List a) → f cmds # [ filesBlock ] + , Files = + [] : List FishComplete + } + arguments + : List FishComplete + + let subcommandToFishComplete = + λ(programName : Text) + → λ(command : Completion.Command.Type Void) + → let subcommandComplete = + [ complete + { cmd = programName, description = command.description } + ⫽ { condition = + Some + { cmd = + fishUseSubcommandFn + , args = + [] : List Argument + } + , argument = + Some command.name + , no-files = + False + } + ] + # optionsComplete + programName + (InSubcommand.Subcommand command.name) + command.options + + in subcommandComplete + # mergeCommandArguments + programName + (InSubcommand.Subcommand command.name) + Void + (λ(_ : List Void) → [] : List FishComplete) + command.arguments + + let simpleCommandToFishComplete = + λ ( c + : { command : + Completion.Command.Type (Completion.Command.Type Void) + , toplevelCommandIsSubcommand : + Bool + } + ) + → optionsComplete c.command.name InSubcommand.No c.command.options + # mergeCommandArguments + c.command.name + ( if c.toplevelCommandIsSubcommand + + then InSubcommand.ToplevelSpecial + + else InSubcommand.No + ) + (Completion.Command.Type Void) + ( Prelude.List.concatMap + (Completion.Command.Type Void) + FishComplete + (subcommandToFishComplete c.command.name) + ) + c.command.arguments + + in Prelude.List.map + FishComplete + (List Text) + (λ(c : FishComplete) → argCommandToList (completeToCommand c)) + (simpleCommandToFishComplete ./Completion/completion.dhall) + # [ [ "complete", "--do-complete=dhall " ] ] -- cgit 1.4.1