controlling the display of dotfiles
Some checks are pending
Lean Action CI / build (push) Waiting to run
Some checks are pending
Lean Action CI / build (push) Waiting to run
This commit is contained in:
parent
e2003d0898
commit
de3fe6dd6d
1 changed files with 19 additions and 11 deletions
|
@ -2,6 +2,7 @@ def hello := "world"
|
||||||
|
|
||||||
structure Config where
|
structure Config where
|
||||||
useASCII : Bool := false
|
useASCII : Bool := false
|
||||||
|
printAll : Bool := false
|
||||||
currentPrefix : String := ""
|
currentPrefix : String := ""
|
||||||
|
|
||||||
abbrev ConfigIO (α : Type) : Type := ReaderT Config IO α
|
abbrev ConfigIO (α : Type) : Type := ReaderT Config IO α
|
||||||
|
@ -20,12 +21,16 @@ def currentConfig : ConfigIO Config :=
|
||||||
def usage : String :=
|
def usage : String :=
|
||||||
"Usage: doug [--ascii]
|
"Usage: doug [--ascii]
|
||||||
Options:
|
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
|
def configFromArgs (args : List String) : Option Config :=
|
||||||
| [] => some {}
|
let parse_arg cfg arg :=
|
||||||
| ["--ascii"] => some {useASCII := true}
|
match arg with
|
||||||
| _ => none
|
| "--ascii" => some {cfg with useASCII := true}
|
||||||
|
| "-a" => some {cfg with printAll := true}
|
||||||
|
| _ => none
|
||||||
|
args.foldlM parse_arg {}
|
||||||
|
|
||||||
inductive Entry where
|
inductive Entry where
|
||||||
| file : String → Entry
|
| 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
|
partial def dirTree (path : System.FilePath) : ConfigIO Unit := do
|
||||||
match ← toEntry path with
|
match ← toEntry path with
|
||||||
| none => pure ()
|
| none => pure ()
|
||||||
| some (.file name) => showFileName name
|
| some (.file name) =>
|
||||||
|
if ((← read).printAll) || !(name.startsWith ".") then
|
||||||
|
showFileName name
|
||||||
| some (.dir name) =>
|
| some (.dir name) =>
|
||||||
showDirName name
|
if ((← read).printAll) || !(name.startsWith ".") then
|
||||||
let contents ← path.readDir
|
showDirName name
|
||||||
withReader (·.inDirectory)
|
let contents ← path.readDir
|
||||||
(doList contents.toList fun d =>
|
withReader (·.inDirectory)
|
||||||
dirTree d.path)
|
(doList contents.toList fun d =>
|
||||||
|
dirTree d.path)
|
||||||
|
|
||||||
def main (args : List String) : IO UInt32 := do
|
def main (args : List String) : IO UInt32 := do
|
||||||
match configFromArgs args with
|
match configFromArgs args with
|
||||||
|
|
Loading…
Reference in a new issue