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
|
||||
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}
|
||||
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,8 +70,11 @@ 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) =>
|
||||
if ((← read).printAll) || !(name.startsWith ".") then
|
||||
showDirName name
|
||||
let contents ← path.readDir
|
||||
withReader (·.inDirectory)
|
||||
|
|
Loading…
Reference in a new issue