From 2b909032e7a0bd10cd7db52067d2fb701bfa95e5 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Tue, 6 Jul 2021 21:34:21 -0400 Subject: Simplified the API for file-system operations. --- stdlib/source/program/aedifex/command/clean.lux | 56 +++++++++++-------------- 1 file changed, 24 insertions(+), 32 deletions(-) (limited to 'stdlib/source/program/aedifex/command/clean.lux') 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))) -- cgit v1.2.3