diff --git a/Doug/Basic.lean b/Doug/Basic.lean index 7189115..55de2b5 100644 --- a/Doug/Basic.lean +++ b/Doug/Basic.lean @@ -2,6 +2,7 @@ def hello := "world" structure Config where useASCII : Bool := false + printAll : Bool := false currentPrefix : String := "" abbrev ConfigIO (α : Type) : Type := ReaderT Config IO α @@ -20,12 +21,16 @@ def currentConfig : ConfigIO Config := def usage : String := "Usage: doug [--ascii] Options: -\t--ascii\tUse ASCII characters to display the directry structure" +\t--ascii\tUse ASCII characters to display the directry structure +\t-a\tShow hidden entries" -def configFromArgs : List String → Option Config - | [] => some {} - | ["--ascii"] => some {useASCII := true} - | _ => none +def configFromArgs (args : List String) : Option Config := + let parse_arg cfg arg := + match arg with + | "--ascii" => some {cfg with useASCII := true} + | "-a" => some {cfg with printAll := true} + | _ => none + args.foldlM parse_arg {} inductive Entry where | file : String → Entry @@ -65,13 +70,16 @@ def doList [Applicative f] : List α → (α → f Unit) → f Unit partial def dirTree (path : System.FilePath) : ConfigIO Unit := do match ← toEntry path with | none => pure () - | some (.file name) => showFileName name + | some (.file name) => + if ((← read).printAll) || !(name.startsWith ".") then + showFileName name | some (.dir name) => - showDirName name - let contents ← path.readDir - withReader (·.inDirectory) - (doList contents.toList fun d => - dirTree d.path) + if ((← read).printAll) || !(name.startsWith ".") then + showDirName name + let contents ← path.readDir + withReader (·.inDirectory) + (doList contents.toList fun d => + dirTree d.path) def main (args : List String) : IO UInt32 := do match configFromArgs args with