(.module: [lux (#- Name) [program (#+ program:)] ["." debug] [abstract [monad (#+ do)]] [control [pipe (#+ do>)] ["." io (#+ IO)] ["." try (#+ Try) ("#\." functor)] ["." exception (#+ exception:)] [parser [environment (#+ Environment)]] [security ["!" capability]] [concurrency ["." promise (#+ Promise) ("#\." monad)]]] [data [binary (#+ Binary)] ["." text ["%" format (#+ format)] ["." encoding]] [format ["." xml]] [collection ["." set] ["." dictionary (#+ Dictionary)] ["." list ("#\." functor)]]] [tool [compiler [language [lux ["." syntax]]]]] [world ["." shell (#+ Shell)] ["." console (#+ Console)] ["." program (#+ Program)] ["." file (#+ Path) ["." watch]]]] ["." / #_ ["#" profile] ["#." action (#+ Action)] ["#." project (#+ Project)] ["#." input] ["#." parser] ["#." pom] ["#." cli] ["#." dependency #_ ["#" resolution (#+ Resolution)]] ["#." repository (#+ Repository) ["#/." remote (#+ Address)] ["#/." local]] ["#." command (#+ Command) ["#/." version] ["#/." clean] ["#/." pom] ["#/." install] ["#/." deps] ["#/." build] ["#/." test] ["#/." auto] ["#/." deploy]]]) (def: repositories (-> /.Profile (List (Repository Promise))) (|>> (get@ #/.repositories) set.to_list (list\map (|>> (/repository/remote.repository #.None) /repository.async)))) (def: (with_dependencies program console command profile) (All [a] (-> (Program Promise) (Console Promise) (-> (Console Promise) (Program Promise) (file.System Promise) (Shell Promise) Resolution (Command a)) (Command a))) (do /action.monad [resolution (/command/deps.do! console (/repository/local.repository program (file.async file.default)) (..repositories profile) profile)] ((command console program (file.async file.default) (shell.async shell.default) resolution) profile))) (exception: (cannot_find_repository {repository Text} {options (Dictionary Text Address)}) (exception.report ["Repository" (%.text repository)] ["Options" (exception.enumerate (function (_ [name repo]) (format (%.text name) " := " (%.text repo))) (dictionary.entries options))])) (def: succeed! (IO Any) (\ program.default exit shell.normal)) (def: (fail! error) (-> Text (IO Any)) (exec (debug.log! error) (\ program.default exit shell.error))) (def: (command action) (All [a] (-> (Promise (Try a)) (IO Any))) (exec (do promise.monad [outcome action] (promise.future (case outcome (#try.Success _) ..succeed! (#try.Failure error) (..fail! error)))) (\ io.monad wrap []))) (program: [{[profile operation] /cli.command}] (do {! io.monad} [?console console.default] (case (try\map console.async ?console) (#try.Failure error) (..fail! error) (#try.Success console) (case operation #/cli.Version (..command (/command/version.do! console (\ /.monoid identity))) _ (do ! [?profile (/input.read io.monad file.default profile)] (case ?profile (#try.Failure error) (..fail! error) (#try.Success profile) (let [program (program.async program.default)] (case operation #/cli.Version (wrap []) #/cli.Clean (..command (/command/clean.do! console (file.async file.default) profile)) #/cli.POM (..command (/command/pom.do! console (file.async file.default) profile)) #/cli.Install (..command (let [fs (file.async file.default)] (/command/install.do! console fs (/repository/local.repository program fs) profile))) (#/cli.Deploy repository identity) (..command (case [(get@ #/.identity profile) (dictionary.get repository (get@ #/.deploy_repositories profile))] [(#.Some artifact) (#.Some repository)] (/command/deploy.do! console (/repository.async (/repository/remote.repository (#.Some identity) repository)) (file.async file.default) artifact profile) [#.None _] (promise\wrap (exception.throw /.no_identity [])) [_ #.None] (promise\wrap (exception.throw ..cannot_find_repository [repository (get@ #/.deploy_repositories profile)])))) #/cli.Dependencies (..command (/command/deps.do! console (/repository/local.repository program (file.async file.default)) (..repositories profile) profile)) (#/cli.Compilation compilation) (case compilation #/cli.Build (..command (..with_dependencies program console /command/build.do! profile)) #/cli.Test (..command (..with_dependencies program console /command/test.do! profile))) (#/cli.Auto auto) (do ! [?watcher watch.default] (case ?watcher (#try.Failure error) (..fail! error) (#try.Success watcher) (..command (case auto #/cli.Build (..with_dependencies program console (/command/auto.do! watcher /command/build.do!) profile) #/cli.Test (..with_dependencies program console (/command/auto.do! watcher /command/test.do!) profile))))) _ (undefined))) ))))))