Skip to content

Instantly share code, notes, and snippets.

@LightAndLight
Created August 13, 2020 00:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LightAndLight/825e1b3e4d8ad516efa4f8501fcf0ba8 to your computer and use it in GitHub Desktop.
Save LightAndLight/825e1b3e4d8ad516efa4f8501fcf0ba8 to your computer and use it in GitHub Desktop.
command {
name = "ls",
options = [
Flag{ name = "long", short = 'l' },
Flag{ name = "recursive", short = 'R', long = "recursive" },
Option{ name = "block-size", long = "block-size", type = Int, default = None },
Option{
name = "color",
long = "color",
type = < Always | Auto | Never >,
default = Some Always
}
],
arguments = [
{ name = "files", type = List Filepath }
],
type Output =
\opts ->
let
FileEntry =
if opts.long
then {
file : String,
owner : String,
permissions : Permissions,
size : Int,
modified : Datetime
}
else { file : String }
DirEntry =
if opts.long
then {
path : Filepath,
count : Int,
files : List FileEntry
}
else {
path : Filepath,
files : List FileEntry
}
in
if opts.recursive
then List DirEntry
else List FileEntry
program =
# type signatures can be omitted, but I've put them here for clarity
\(opts : {
long : Bool,
recursive : Bool,
block-size : Int,
color : < Always | Auto | Never >
},
args : {
files : List Filepath
}
) ->
if opts.recursive
then
# IO (List DirEntry)
if opts.long
then do
# IO (List {
# path : Filepath,
# count : Int,
# files : List {
# file : String,
# owner : String,
# permissions : Permissions,
# size : Int,
# modified : Datetime
# }
# })
result <- call("ls", [ "-l", "-R" ] ++ map toString args.files)
# TODO: parse `result` and good error handleing
_ result
else
# IO (List {
# path : Filepath,
# files : List { file : String }
# })
_
else
# List FileEntry
# etc.
_
}
-----------------------------------
repl> :t ls -l
IO (List {
file : String,
owner : String,
permissions : Permissions,
size : Int,
modified : Datetime
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment