aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/program/aedifex/command/clean.lux
diff options
context:
space:
mode:
authorEduardo Julian2021-07-06 21:34:21 -0400
committerEduardo Julian2021-07-06 21:34:21 -0400
commit2b909032e7a0bd10cd7db52067d2fb701bfa95e5 (patch)
tree0e2aaef228f80f3336715327f7f34065c309de22 /stdlib/source/program/aedifex/command/clean.lux
parent5cf4efa861075f8276f43a2516f5beacaf610b44 (diff)
Simplified the API for file-system operations.
Diffstat (limited to 'stdlib/source/program/aedifex/command/clean.lux')
-rw-r--r--stdlib/source/program/aedifex/command/clean.lux56
1 files changed, 24 insertions, 32 deletions
diff --git a/stdlib/source/program/aedifex/command/clean.lux b/stdlib/source/program/aedifex/command/clean.lux
index 142451113..c37c46367 100644
--- a/stdlib/source/program/aedifex/command/clean.lux
+++ b/stdlib/source/program/aedifex/command/clean.lux
@@ -3,54 +3,46 @@
[abstract
["." monad (#+ do)]]
[control
- ["." try (#+ Try)]
- ["." exception]
+ [try (#+ Try)]
[concurrency
["." promise (#+ Promise)]]]
[data
[text
["%" format (#+ format)]]]
[world
- ["." file (#+ Path File Directory)]
+ ["." file (#+ Path)]
["." console (#+ Console)]]]
["." /// #_
[command (#+ Command)]
["#" profile]
["#." action (#+ Action)]])
-(def: (clean_files! root)
- (-> (Directory Promise) (Promise (Try Any)))
- (do {! ///action.monad}
- [nodes (: (Promise (Try (List (File Promise))))
- (\ root files []))
- _ (monad.map ! (function (_ node)
- (\ node delete []))
- nodes)]
- (wrap [])))
+(def: (clean_files! fs root)
+ (-> (file.System Promise) Path (Promise (Try Any)))
+ (let [! ///action.monad]
+ (|> root
+ (\ fs directory_files)
+ (\ ! map (monad.map ! (\ fs delete)))
+ (\ ! join))))
-(def: #export (success path)
+(def: #export success
(-> ///.Target Text)
- (format "Successfully cleaned target directory: " path))
+ (|>> (format "Successfully cleaned target directory: ")))
(def: #export (do! console fs profile)
(-> (Console Promise) (file.System Promise) (Command Any))
- (do promise.monad
+ (do {! promise.monad}
[#let [target (get@ #///.target profile)]
- root (: (Promise (Try (Directory Promise)))
- (\ fs directory target))]
- (case root
- (#try.Success root)
- (do {! ///action.monad}
- [_ (loop [root root]
+ ? (\ fs directory? target)
+ _ (let [! ///action.monad]
+ (if ?
+ (loop [root target]
(do !
- [_ (..clean_files! root)
- subs (: (Promise (Try (List (Directory Promise))))
- (\ root directories []))
- _ (monad.map ! recur subs)]
- (\ root discard [])))]
- (console.write_line (..success target) console))
-
- (#try.Failure error)
- (if (exception.match? file.cannot_find_directory error)
- (console.write_line (..success target) console)
- (\ promise.monad wrap (#try.Failure error))))))
+ [_ (..clean_files! fs root)
+ _ (|> root
+ (\ fs sub_directories)
+ (\ ! map (monad.map ! recur))
+ (\ ! join))]
+ (\ fs delete root)))
+ (\ ! wrap [])))]
+ (console.write_line (..success target) console)))