... This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. ... If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. (.require [library [lux (.except local) ["[0]" program] ["[0]" debug] [abstract [monad (.only do)]] [control ["[0]" io (.only IO)] ["[0]" maybe] ["[0]" try (.only Try) (.use "[1]#[0]" functor)] ["[0]" exception (.only Exception)] [concurrency ["[0]" async (.only Async) (.use "[1]#[0]" monad)]]] [data [binary (.only Binary)] ["[0]" text (.only) ["%" \\format (.only format)] [encoding ["[0]" utf8]]] [format ["[0]" xml]] [collection ["[0]" set] ["[0]" dictionary (.only Dictionary)] ["[0]" list (.use "[1]#[0]" functor)]]] [meta [compiler [language [lux ["[0]" syntax]]]]] [world ["[0]" shell (.only Exit Shell)] ["[0]" console (.only Console)] ["[0]" environment] ["[0]" file (.only Path) ["[0]" watch]] [net ["[0]" http ["[1]" client]]]]]] ["[0]" / ["[1]" profile] ["[1][0]" action (.only Action)] ["[1][0]" project (.only Project)] ["[1][0]" input] ["[1][0]" pom] ["[1][0]" cli] ["[1][0]" dependency ["[1]" resolution (.only Resolution)]] ["[1][0]" repository (.only Repository) ["[1]/[0]" remote (.only Address)] ["[1]/[0]" local]] ["[1][0]" command (.only Command) ["[1]/[0]" version] ["[1]/[0]" clean] ["[1]/[0]" pom] ["[1]/[0]" install] ["[1]/[0]" deps] ["[1]/[0]" build] ["[1]/[0]" test] ["[1]/[0]" auto] ["[1]/[0]" deploy]]]) (def repositories (-> /.Profile (List (Repository Async))) (|>> (the /.#repositories) set.list (list#each (|>> (/repository/remote.repository http.default {.#None}) /repository.async)))) (def environment (environment.async environment.default)) (def fs (file.async file.default)) (def local (/repository/local.repository ..environment ..fs)) (def (with_dependencies environment console command profile) (All (_ a) (-> (environment.Environment Async) (Console Async) (-> (Console Async) (environment.Environment Async) (file.System Async) (Shell Async) Resolution (Command [Exit a])) (Command a))) (do /action.monad [resolution (/command/deps.do! console (/repository/local.repository environment (file.async file.default)) (..repositories profile) (|>> (/repository/remote.repository http.default {.#None}) /repository.async) profile) [exit_code output] ((command console environment (file.async file.default) (shell.async shell.default) resolution) profile) _ (when exit_code shell.normal (in []) _ (do async.monad [_ (of environment exit exit_code)] (in {try.#Failure ""})))] (in output))) (exception.def (cannot_find_repository [repository options]) (Exception [Text (Dictionary Text Address)]) (exception.report (list ["Repository" (%.text repository)] ["Options" (exception.listing (function (_ [name repo]) (format (%.text name) " := " (%.text repo))) (dictionary.entries options))]))) (def succeed! (IO Any) (of environment.default exit shell.normal)) (def (fail! error) (-> Text (IO Any)) (exec (debug.log! error) (of environment.default exit shell.error))) (def (command action) (All (_ a) (-> (Async (Try a)) (IO Any))) (exec (do async.monad [outcome action] (async.future (when outcome {try.#Success _} ..succeed! {try.#Failure error} (..fail! error)))) (of io.monad in []))) (exception.def .public invalid_operation) (`` (def write_only (Console IO) (implementation (,, (with_template [] [(def ( _) (io.io (exception.except ..invalid_operation [])))] [read] [read_line] [close] )) (def (write it) (<| io.io {try.#Success} debug.log! (if (text.ends_with? text.\n it) (maybe.trusted (text.clip 0 (-- (text.size it)) it)) it)))))) (def _ (program.program [[profiles operation] /cli.command] (do [! io.monad] [console (of ! each (|>> (try.else ..write_only) console.async) console.default)] (when operation {/cli.#Version} (..command (/command/version.do! console (of /.monoid identity))) _ (do ! [?profile (/input.read io.monad file.default profiles)] (when ?profile {try.#Failure error} (..fail! error) {try.#Success profile} (when operation {/cli.#Version} (in []) {/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 (/command/install.do! console ..fs ..local profile)) {/cli.#Deploy repository identity} (..command (when (the /.#identity profile) {.#Some artifact} (when (dictionary.value repository (the /.#deploy_repositories profile)) {.#Some remote} (/command/deploy.do! ..environment (shell.async shell.default) console ..local (/repository.async (/repository/remote.repository http.default {.#Some identity} remote)) (file.async file.default) artifact profile) {.#None} (async#in (exception.except ..cannot_find_repository [repository (the /.#deploy_repositories profile)]))) {.#None} (async#in (exception.except /.no_identity [])))) {/cli.#Dependencies} (..command (/command/deps.do! console (/repository/local.repository ..environment (file.async file.default)) (..repositories profile) (|>> (/repository/remote.repository http.default {.#None}) /repository.async) profile)) {/cli.#Compilation compilation} (when compilation {/cli.#Build} (..command (..with_dependencies ..environment console /command/build.do! profile)) {/cli.#Test} (..command (..with_dependencies ..environment console /command/test.do! profile))) {/cli.#Auto auto} (do ! [?watcher watch.default] (when ?watcher {try.#Failure error} (..fail! error) {try.#Success watcher} (..command (when auto {/cli.#Build} (..with_dependencies ..environment console (/command/auto.do! /command/auto.delay watcher /command/build.do!) profile) {/cli.#Test} (..with_dependencies ..environment console (/command/auto.do! /command/auto.delay watcher /command/test.do!) profile)))))) ))))))