argument for starting directory (completed)
Some checks failed
Lean Action CI / build (push) Has been cancelled
Some checks failed
Lean Action CI / build (push) Has been cancelled
This commit is contained in:
parent
de3fe6dd6d
commit
244ace87c3
2 changed files with 14 additions and 4 deletions
|
@ -3,7 +3,9 @@ def hello := "world"
|
||||||
structure Config where
|
structure Config where
|
||||||
useASCII : Bool := false
|
useASCII : Bool := false
|
||||||
printAll : Bool := false
|
printAll : Bool := false
|
||||||
|
rootPath : System.FilePath := "."
|
||||||
currentPrefix : String := ""
|
currentPrefix : String := ""
|
||||||
|
deriving Repr
|
||||||
|
|
||||||
abbrev ConfigIO (α : Type) : Type := ReaderT Config IO α
|
abbrev ConfigIO (α : Type) : Type := ReaderT Config IO α
|
||||||
|
|
||||||
|
@ -29,7 +31,11 @@ def configFromArgs (args : List String) : Option Config :=
|
||||||
match arg with
|
match arg with
|
||||||
| "--ascii" => some {cfg with useASCII := true}
|
| "--ascii" => some {cfg with useASCII := true}
|
||||||
| "-a" => some {cfg with printAll := true}
|
| "-a" => some {cfg with printAll := true}
|
||||||
| _ => none
|
| path =>
|
||||||
|
if path.startsWith "-" then
|
||||||
|
none
|
||||||
|
else
|
||||||
|
some {cfg with rootPath := path}
|
||||||
args.foldlM parse_arg {}
|
args.foldlM parse_arg {}
|
||||||
|
|
||||||
inductive Entry where
|
inductive Entry where
|
||||||
|
@ -84,8 +90,13 @@ partial def dirTree (path : System.FilePath) : ConfigIO Unit := do
|
||||||
def main (args : List String) : IO UInt32 := do
|
def main (args : List String) : IO UInt32 := do
|
||||||
match configFromArgs args with
|
match configFromArgs args with
|
||||||
| some config =>
|
| some config =>
|
||||||
(dirTree (← IO.currentDir)).run config
|
if ← config.rootPath.pathExists then
|
||||||
pure 0
|
(dirTree (← IO.FS.realPath config.rootPath)).run config
|
||||||
|
IO.println s!"config {repr config}"
|
||||||
|
pure 0
|
||||||
|
else
|
||||||
|
IO.eprintln s!"Path doesn't exist {config.rootPath}"
|
||||||
|
pure 1
|
||||||
| none =>
|
| none =>
|
||||||
IO.eprintln s!"Didn't understand argument(s) {" ".intercalate args}\n"
|
IO.eprintln s!"Didn't understand argument(s) {" ".intercalate args}\n"
|
||||||
IO.eprintln usage
|
IO.eprintln usage
|
||||||
|
|
|
@ -24,7 +24,6 @@ script test (args) do
|
||||||
let proc ← IO.Process.spawn
|
let proc ← IO.Process.spawn
|
||||||
⟨{stdin := .inherit, stdout := .piped, stderr := .piped},
|
⟨{stdin := .inherit, stdout := .piped, stderr := .piped},
|
||||||
exe.toString, args.toArray, none, #[], false ⟩
|
exe.toString, args.toArray, none, #[], false ⟩
|
||||||
IO.println s!"{← proc.tryWait}"
|
|
||||||
IO.print (← proc.stdout.readToEnd)
|
IO.print (← proc.stdout.readToEnd)
|
||||||
IO.eprintln (← IO.FS.Handle.readToEnd proc.stderr)
|
IO.eprintln (← IO.FS.Handle.readToEnd proc.stderr)
|
||||||
let ret ← proc.wait
|
let ret ← proc.wait
|
||||||
|
|
Loading…
Reference in a new issue