Skip to content

Instantly share code, notes, and snippets.

@silverjam
Created September 20, 2019 18:21
Show Gist options
  • Save silverjam/3d5cab6793ed82902db72260bc193a03 to your computer and use it in GitHub Desktop.
Save silverjam/3d5cab6793ed82902db72260bc193a03 to your computer and use it in GitHub Desktop.
Generating lots of YAML with Dhall (recursive incoation translation)
let Argument : Type =
List
{ mapKey : Text
, mapValue :
{ help : Text
, index : Integer
, required : Bool
, takes_value : Bool
, value_name : Text
}
}
let LiArg : Type = List Argument
let OpLiArg : Type = Optional LiArg
let mkAddressArgument : Text → Argument = λ(op : Text) →
[{ mapKey = "address",
mapValue = { help = "The address to use for a " ++ op
, value_name = "ADDRESS"
, takes_value = True
, required = True
, index = +1
}
}]
let Subcommand0 : Type =
List { mapKey: Text, mapValue: { about: Text, args: OpLiArg} }
let Subcommand1 : Type =
List { mapKey: Text, mapValue: { about: Text, args: OpLiArg,
subcommands: Optional (List Subcommand0) } }
let Subcommand2 : Type =
List { mapKey: Text, mapValue: { about: Text, args: OpLiArg,
subcommands: Optional (List Subcommand1) } }
let Subcommand3 : Type =
List { mapKey: Text, mapValue: { about: Text, args: OpLiArg,
subcommands: Optional (List Subcommand2) } }
let Subcommand4 : Type =
List { mapKey: Text, mapValue: { about: Text, args: OpLiArg,
subcommands: Optional (List Subcommand3) } }
let Subcommand5 : Type =
List { mapKey: Text, mapValue: { about: Text, args: OpLiArg,
subcommands: Optional (List Subcommand4) } }
let Subcommand6 : Type =
List { mapKey: Text, mapValue: { about : Text, args: OpLiArg,
subcommands: Optional (List Subcommand5) } }
let makeSubcommand0
{- The types -}
: Text
→ Text
→ OpLiArg
→ Subcommand0
{- Argument extraction -}
= λ(_name : Text)
→ λ(_about : Text)
→ λ(_args : OpLiArg)
[
{ mapKey = _name
, mapValue = { about = _about, args = _args }
}
]
let LiSubc0 = List Subcommand0
let OpLiSubc0 = Optional LiSubc0
let makeSubcommand1
{- The types -}
: Text → Text → OpLiArg → OpLiSubc0 → Subcommand1
{- Argument extraction -}
= λ(_name : Text)
→ λ(_about : Text)
→ λ(_args : OpLiArg)
→ λ(_subcommands : OpLiSubc0)
[
{ mapKey = _name
, mapValue = { about = _about, args = _args, subcommands = _subcommands }
}
]
let LiSubc1 = List Subcommand1
let OpLiSubc1 = Optional LiSubc1
let makeSubcommand2
{- The types -}
: Text → Text → OpLiArg → OpLiSubc1 → Subcommand2
{- Argument extraction -}
= λ(_name : Text)
→ λ(_about : Text)
→ λ(_args : OpLiArg)
→ λ(_subcommands : OpLiSubc1)
[
{ mapKey = _name
, mapValue = { about = _about , args = _args , subcommands = _subcommands }
}
]
let LiSubc2 = List Subcommand2
let OpLiSubc2 = Optional LiSubc2
let makeSubcommand3
{- The types -}
: Text → Text → OpLiArg → OpLiSubc2 → Subcommand3
{- Argument extraction -}
= λ(_name : Text)
→ λ(_about : Text)
→ λ(_args : OpLiArg)
→ λ(_subcommands : OpLiSubc2)
[
{ mapKey = _name
, mapValue = { about = _about, args = _args, subcommands = _subcommands }
}
]
let LiSubc3 = List Subcommand3
let OpLiSubc3 = Optional LiSubc3
let makeSubcommand4
{- The types -}
: Text → Text → OpLiArg → OpLiSubc3 → Subcommand4
{- Argument extraction -}
= λ(_name : Text)
→ λ(_about : Text)
→ λ(_args : OpLiArg)
→ λ(_subcommands : OpLiSubc3)
[
{ mapKey = _name
, mapValue = { about = _about, args = _args, subcommands = _subcommands }
}
]
let LiSubc4 = List Subcommand4
let OpLiSubc4 = Optional LiSubc4
let makeSubcommand5
{- The types -}
: Text → Text → OpLiArg → OpLiSubc4 → Subcommand5
{- Argument extraction -}
= λ(_name : Text)
→ λ(_about : Text)
→ λ(_args : OpLiArg)
→ λ(_subcommands : OpLiSubc4)
[
{ mapKey = _name
, mapValue = { about = _about, args = _args, subcommands = _subcommands }
}
]
let LiSubc5 = List Subcommand5
let OpLiSubc5 = Optional LiSubc5
let makeSubcommand6
{- The types -}
: Text → Text → OpLiArg → OpLiSubc5 → Subcommand6
{- Argument extraction -}
= λ(_name : Text)
→ λ(_about : Text)
→ λ(_args : OpLiArg)
→ λ(_subcommands : OpLiSubc5)
[
{ mapKey = _name
, mapValue = { about = _about , args = _args , subcommands = _subcommands }
}
]
let noArgs = None LiArg
let inStdinHelp : Text = "Read from standard input"
let inStdinName : Text = "in=stdin"
let inTcpListenHelp : Text = "Listen on a TCP port for input"
let inTcpListenName : Text = "in=tcp-listen"
let inTcpListenArg = mkAddressArgument "TCP listen"
let inTcpConnectHelp : Text = "Connect to a TCP port for input"
let inTcpConnectName : Text = "in=tcp-connect"
let inTcpConnectArg = mkAddressArgument "TCP connection"
let outTcpConnectHelp : Text = "Connect to a TCP port for output"
let outTcpConnectName : Text = "out=tcp-connect"
let outTcpConnectArg = mkAddressArgument "TCP connection"
let outTcpListenHelp : Text = "Connect to a TCP port for output"
let outTcpListenName : Text = "out=tcp-connect"
let outTcpListenArg = mkAddressArgument "TCP connection"
let inTcpListen0 = makeSubcommand0 inTcpListenName inTcpListenHelp (Some [ inTcpListenArg ])
let inTcpConnect0 = makeSubcommand0 inTcpConnectName inTcpConnectHelp (Some [ inTcpConnectArg ])
let outTcpListen0 = makeSubcommand0 outTcpListenName outTcpListenHelp (Some [ outTcpListenArg ])
let outTcpConnect0 = makeSubcommand0 outTcpConnectName outTcpConnectHelp (Some [ outTcpConnectArg ])
let subcommands0 = [ inTcpConnect0, inTcpListen0, outTcpConnect0, outTcpListen0 ]
let inTcpListen1 = makeSubcommand1 inTcpListenName inTcpListenHelp (Some [ inTcpListenArg ])
(Some subcommands0)
let inTcpConnect1 = makeSubcommand1 inTcpConnectName inTcpConnectHelp (Some [ inTcpConnectArg ])
(Some subcommands0)
let outTcpListen1 = makeSubcommand1 outTcpListenName outTcpListenHelp (Some [ outTcpListenArg ])
(Some subcommands0)
let outTcpConnect1 = makeSubcommand1 outTcpConnectName outTcpConnectHelp (Some [ outTcpConnectArg ])
(Some subcommands0)
let subcommands1 = [ inTcpConnect1, inTcpListen1, outTcpConnect1, outTcpListen1 ]
let inTcpListen2 = makeSubcommand2 inTcpListenName inTcpListenHelp (Some [ inTcpListenArg ])
(Some subcommands1)
let inTcpConnect2 = makeSubcommand2 inTcpConnectName inTcpConnectHelp (Some [ inTcpConnectArg ])
(Some subcommands1)
let outTcpListen2 = makeSubcommand2 outTcpListenName outTcpListenHelp (Some [ outTcpListenArg ])
(Some subcommands1)
let outTcpConnect2 = makeSubcommand2 outTcpConnectName outTcpConnectHelp (Some [ outTcpConnectArg ])
(Some subcommands1)
let subcommands2 = [ inTcpConnect2, inTcpListen2, outTcpConnect2, outTcpListen2 ]
let inTcpListen3 = makeSubcommand3 inTcpListenName inTcpListenHelp (Some [ inTcpListenArg ])
(Some subcommands2)
let inTcpConnect3 = makeSubcommand3 inTcpConnectName inTcpConnectHelp (Some [ inTcpConnectArg ])
(Some subcommands2)
let outTcpListen3 = makeSubcommand3 outTcpListenName outTcpListenHelp (Some [ outTcpListenArg ])
(Some subcommands2)
let outTcpConnect3 = makeSubcommand3 outTcpConnectName outTcpConnectHelp (Some [ outTcpConnectArg ])
(Some subcommands2)
let subcommands3 = [ inTcpConnect3, inTcpListen3, outTcpConnect3, outTcpListen3 ]
let inTcpListen4 = makeSubcommand4 inTcpListenName inTcpListenHelp (Some [ inTcpListenArg ])
(Some subcommands3)
let inTcpConnect4 = makeSubcommand4 inTcpConnectName inTcpConnectHelp (Some [ inTcpConnectArg ])
(Some subcommands3)
let outTcpListen4 = makeSubcommand4 outTcpListenName outTcpListenHelp (Some [ outTcpListenArg ])
(Some subcommands3)
let outTcpConnect4 = makeSubcommand4 outTcpConnectName outTcpConnectHelp (Some [ outTcpConnectArg ])
(Some subcommands3)
let subcommands4 = [ inTcpConnect4, inTcpListen4, outTcpConnect4, outTcpListen4 ]
let inTcpListen5 = makeSubcommand5 inTcpListenName inTcpListenHelp (Some [ inTcpListenArg ])
(Some subcommands4)
let inTcpConnect5 = makeSubcommand5 inTcpConnectName inTcpConnectHelp (Some [ inTcpConnectArg ])
(Some subcommands4)
let outTcpListen5 = makeSubcommand5 outTcpListenName outTcpListenHelp (Some [ outTcpListenArg ])
(Some subcommands4)
let outTcpConnect5 = makeSubcommand5 outTcpConnectName outTcpConnectHelp (Some [ outTcpConnectArg ])
(Some subcommands4)
let subcommands5 = [ inTcpConnect5, inTcpListen5, outTcpConnect5, outTcpListen5 ]
let inTcpListen6 =
makeSubcommand6 inTcpListenName inTcpListenHelp (Some [ inTcpListenArg ])
(Some subcommands5)
let inTcpConnect6 = makeSubcommand6 inTcpConnectName inTcpConnectHelp (Some [ inTcpConnectArg ])
(Some subcommands5)
let inStdin6 = makeSubcommand6 inStdinName inStdinHelp noArgs
(Some subcommands5)
in
{ name = "Sokatio"
, version = "0.1.0"
, author = "Swift Navigation <[email protected]>"
, about = "Sokatio is socket server in the vein of socat and str2str"
, subcommands =
[ inTcpConnect6
, inTcpListen6
, inStdin6
]
}
-- vim: sts=2:et:ts=2:sw=2:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment