about summary refs log tree commit diff
path: root/pkgs/profpatsch/dhallsh
diff options
context:
space:
mode:
authorProfpatsch <mail@profpatsch.de>2019-09-14 22:59:15 +0200
committerProfpatsch <mail@profpatsch.de>2020-02-24 00:57:55 +0100
commit98f961b23f6551f1b9abd785e2aa0b21c4dc85da (patch)
treef1086523f7c54731a117bdd71869b1928a86338b /pkgs/profpatsch/dhallsh
parent2ace5fa1648b530f5cf0b19ad32c9a4fe44334fc (diff)
main: factor out basic fish completion commands
Diffstat (limited to 'pkgs/profpatsch/dhallsh')
-rw-r--r--pkgs/profpatsch/dhallsh/Fish/Complete/default.dhall28
-rw-r--r--pkgs/profpatsch/dhallsh/Fish/Complete/toCommand.dhall77
-rw-r--r--pkgs/profpatsch/dhallsh/Fish/Complete/type.dhall27
-rw-r--r--pkgs/profpatsch/dhallsh/main.dhall193
4 files changed, 176 insertions, 149 deletions
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)