controlling the display of dotfiles
Some checks are pending
Lean Action CI / build (push) Waiting to run

This commit is contained in:
qwjyh 2024-10-22 18:02:57 +09:00
parent e2003d0898
commit de3fe6dd6d

View file

@ -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