diff --git a/.dockerignore b/.dockerignore index 30f3436..bcd167d 100644 --- a/.dockerignore +++ b/.dockerignore @@ -5,10 +5,10 @@ # Now explicitly add the source code, Cargo files and readme: !Cargo.toml -!Cargo.lock !rustfmt.toml !deny.toml !src/ +!resources/ !README.rst !LICENSE.txt !ci/extra_checks.sh diff --git a/.gitignore b/.gitignore index 9e3dcf1..98ecab0 100644 --- a/.gitignore +++ b/.gitignore @@ -124,7 +124,7 @@ coverage # Bower dependency directory (https://bower.io/) bower_components -# node-waf configuration +# expression-waf configuration .lock-wscript # Compiled binary addons (https://nodejs.org/api/addons.html) diff --git a/Cargo.lock b/Cargo.lock index fcd52ad..4df55e6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -20,6 +20,12 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "anyhow" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28b2cd92db5cbd74e8e5028f7e27dd7aa3090e89e4f2a197cc7c8dfb69c7063b" + [[package]] name = "async-channel" version = "1.6.1" @@ -63,12 +69,11 @@ dependencies = [ [[package]] name = "async-io" -version = "1.4.1" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bbfd5cf2794b1e908ea8457e6c45f8f8f1f6ec5f74617bf4662623f47503c3b" +checksum = "a811e6a479f2439f0c04038796b5cfb3d2ad56c230e0f2d3f7b04d68cfee607b" dependencies = [ "concurrent-queue", - "fastrand", "futures-lite", "libc", "log", @@ -149,12 +154,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "autocfg" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" - [[package]] name = "bincode" version = "1.3.3" @@ -207,9 +206,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.6.1" +version = "3.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63396b8a4b9de3f4fdfb320ab6080762242f66a8ef174c49d8e19b674db4cdbe" +checksum = "9c59e7af012c713f529e7a3ee57ce9b31ddd858d4b512923602f74608b009631" [[package]] name = "byte-tools" @@ -241,9 +240,9 @@ checksum = "631ae5198c9be5e753e5cc215e1bd73c2b466a3565173db433f52bb9d3e66dba" [[package]] name = "cc" -version = "1.0.67" +version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd" +checksum = "4a72c244c1ff497a746a7e1fb3d14bd08420ecda70c8f25c7112f2781652d787" [[package]] name = "cfg-if" @@ -283,11 +282,10 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4feb231f0d4d6af81aed15928e58ecf5816aa62a2393e2c82f46973e92a9a278" +checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db" dependencies = [ - "autocfg", "cfg-if 1.0.0", "lazy_static", ] @@ -333,9 +331,9 @@ dependencies = [ [[package]] name = "env_logger" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17392a012ea30ef05a610aa97dfb49496e71c9f676b27879922ea5bdf60d9d3f" +checksum = "a19187fea3ac7e84da7dacf48de0c45d63c6a76f9490dae389aead16c243fce3" dependencies = [ "atty", "humantime", @@ -420,9 +418,9 @@ checksum = "acc499defb3b348f8d8f3f66415835a9131856ff7714bf10dadfc4ec4bdb29a1" [[package]] name = "futures-lite" -version = "1.11.3" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4481d0cd0de1d204a4fa55e7d45f07b1d958abcb06714b3446438e2eff695fb" +checksum = "7694489acd39452c77daa48516b894c153f192c3578d5a839b62c58099fcbf48" dependencies = [ "fastrand", "futures-core", @@ -455,15 +453,21 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" +checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" dependencies = [ "cfg-if 1.0.0", "libc", "wasi 0.10.2+wasi-snapshot-preview1", ] +[[package]] +name = "glob" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" + [[package]] name = "gloo-timers" version = "0.2.1" @@ -479,18 +483,18 @@ dependencies = [ [[package]] name = "heck" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cbf45460356b7deeb5e3415b5563308c0a9b057c85e12b06ad551f98d0a6ac" +checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" dependencies = [ "unicode-segmentation", ] [[package]] name = "hermit-abi" -version = "0.1.18" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" dependencies = [ "libc", ] @@ -518,6 +522,30 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "include_dir" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23d58bdeb22b1c4691106c084b1063781904c35d0f22eda2a283598968eac61a" +dependencies = [ + "glob", + "include_dir_impl", + "proc-macro-hack", +] + +[[package]] +name = "include_dir_impl" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327869970574819d24d1dca25c891856144d29159ab797fa9dc725c5c3f57215" +dependencies = [ + "anyhow", + "proc-macro-hack", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "instant" version = "0.1.9" @@ -605,9 +633,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.94" +version = "0.2.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18794a8ad5b29321f790b55d93dfba91e125cb1a9edbd4f8e3150acc771c1a5e" +checksum = "320cfe77175da3a483efed4bc0adc1968ca050b098ce4f2f1c13a56626128790" [[package]] name = "lock_api" @@ -636,6 +664,7 @@ dependencies = [ "bincode", "dirs", "env_logger", + "include_dir", "jemallocator", "lazy_static", "log", @@ -727,9 +756,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.7.2" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3" +checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" [[package]] name = "opaque-debug" @@ -803,9 +832,9 @@ checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" [[package]] name = "pin-project-lite" -version = "0.2.6" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905" +checksum = "8d31d11c69a6b52a174b42bdc0c30e5e11670f90788b2c471c31c1d17d449443" [[package]] name = "pin-utils" @@ -815,14 +844,14 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "polling" -version = "2.0.3" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fc12d774e799ee9ebae13f4076ca003b40d18a11ac0f3641e6f899618580b7b" +checksum = "92341d779fa34ea8437ef4d82d440d5e1ce3f3ff7f824aa64424cd481f9a1f25" dependencies = [ "cfg-if 1.0.0", "libc", "log", - "wepoll-sys", + "wepoll-ffi", "winapi 0.3.9", ] @@ -856,11 +885,17 @@ dependencies = [ "version_check", ] +[[package]] +name = "proc-macro-hack" +version = "0.5.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" + [[package]] name = "proc-macro2" -version = "1.0.26" +version = "1.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a152013215dca273577e18d2bf00fa862b89b24169fb78c4c95aeb07992c9cec" +checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038" dependencies = [ "unicode-xid", ] @@ -889,14 +924,14 @@ dependencies = [ [[package]] name = "rand" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e" +checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8" dependencies = [ "libc", - "rand_chacha 0.3.0", - "rand_core 0.6.2", - "rand_hc 0.3.0", + "rand_chacha 0.3.1", + "rand_core 0.6.3", + "rand_hc 0.3.1", ] [[package]] @@ -911,12 +946,12 @@ dependencies = [ [[package]] name = "rand_chacha" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core 0.6.2", + "rand_core 0.6.3", ] [[package]] @@ -930,11 +965,11 @@ dependencies = [ [[package]] name = "rand_core" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" +checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" dependencies = [ - "getrandom 0.2.2", + "getrandom 0.2.3", ] [[package]] @@ -948,18 +983,18 @@ dependencies = [ [[package]] name = "rand_hc" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73" +checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7" dependencies = [ - "rand_core 0.6.2", + "rand_core 0.6.3", ] [[package]] name = "redox_syscall" -version = "0.2.8" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "742739e41cd49414de871ea5e549afb7e2a3ac77b589bcbebe8c82fab37147fc" +checksum = "5ab49abadf3f9e1c4bc499e8845e152ad87d2ad2d30371841171169e9d75feee" dependencies = [ "bitflags", ] @@ -970,7 +1005,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "528532f3d801c87aec9def2add9ca802fe569e44a544afe633765267840abe64" dependencies = [ - "getrandom 0.2.2", + "getrandom 0.2.3", "redox_syscall", ] @@ -1107,9 +1142,9 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] name = "structopt" -version = "0.3.21" +version = "0.3.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5277acd7ee46e63e5168a80734c9f6ee81b1367a7d8772a2d765df2a3705d28c" +checksum = "69b041cdcb67226aca307e6e7be44c8806423d83e018bd662360a93dabce4d71" dependencies = [ "clap", "lazy_static", @@ -1119,9 +1154,9 @@ dependencies = [ [[package]] name = "structopt-derive" -version = "0.4.14" +version = "0.4.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ba9cdfda491b814720b6b06e0cac513d922fc407582032e8706e9f137976f90" +checksum = "7813934aecf5f51a54775e00068c237de98489463968231a51746bbbc03f9c10" dependencies = [ "heck", "proc-macro-error", @@ -1132,9 +1167,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.72" +version = "1.0.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1e8cdbefb79a9a5a65e0db8b47b723ee907b7c7f8496c76a1770b5c310bab82" +checksum = "f71489ff30030d2ae598524f61326b902466f72a0fb1a8564c001cc63425bcc7" dependencies = [ "proc-macro2", "quote", @@ -1149,7 +1184,7 @@ checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" dependencies = [ "cfg-if 1.0.0", "libc", - "rand 0.8.3", + "rand 0.8.4", "redox_syscall", "remove_dir_all", "winapi 0.3.9", @@ -1205,18 +1240,18 @@ dependencies = [ [[package]] name = "unicode-normalization" -version = "0.1.17" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07fbfce1c8a97d547e8b5334978438d9d6ec8c20e38f56d4a4374d181493eaef" +checksum = "d54590932941a9e9266f0832deed84ebe1bf2e4c9e4a3554d393d18f5e854bf9" dependencies = [ "tinyvec", ] [[package]] name = "unicode-segmentation" -version = "1.7.1" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" +checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b" [[package]] name = "unicode-width" @@ -1244,11 +1279,12 @@ dependencies = [ [[package]] name = "value-bag" -version = "1.0.0-alpha.6" +version = "1.0.0-alpha.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b676010e055c99033117c2343b33a40a30b91fecd6c49055ac9cd2d6c305ab1" +checksum = "dd320e1520f94261153e96f7534476ad869c14022aee1e59af7c778075d840ae" dependencies = [ "ctor", + "version_check", ] [[package]] @@ -1358,10 +1394,10 @@ dependencies = [ ] [[package]] -name = "wepoll-sys" -version = "3.0.1" +name = "wepoll-ffi" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fcb14dea929042224824779fbc82d9fab8d2e6d3cbc0ac404de8edf489e77ff" +checksum = "d743fdedc5c64377b5fc2bc036b01c7fd642205a0d96356034ae3404d49eb7fb" dependencies = [ "cc", ] diff --git a/Cargo.toml b/Cargo.toml index 3f7ccd9..5842f73 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,18 +17,19 @@ name = "mango" path = "src/main.rs" [dependencies] -serde = { version = "1.0.125", features = ["derive"] } +serde = { version = "1.0.126", features = ["derive"] } bincode = "1.3.3" serde_json = "1.0.64" dirs = "3.0.2" whoami = "1.1.2" -structopt = { version = "0.3.21", features = [ "paw" ] } +structopt = { version = "0.3.22", features = [ "paw" ] } lazy_static = "1.4.0" ws = "0.9.1" log = "0.4.14" async-std = "1.9.0" -env_logger = "0.8.3" +env_logger = "0.8.4" paw = "1.0.0" +include_dir = "0.6.0" [dev-dependencies] serial_test = "0.5.1" diff --git a/ci/simple.Dockerfile b/ci/simple.Dockerfile index dc410c1..bc1e9d8 100644 --- a/ci/simple.Dockerfile +++ b/ci/simple.Dockerfile @@ -1,33 +1,16 @@ -FROM clux/muslrust:nightly-2021-04-24 AS build - -ENV RUST_BACKTRACE=1 - -RUN rustup component add rustfmt -RUN rustup component add clippy -RUN cargo install cargo-outdated -RUN cargo install cargo-audit -RUN cargo install cargo-deny -RUN cargo install cargo-tree - -# Add the files needed to compile dependencies. -COPY ./Cargo.toml Cargo.lock ./ -RUN mkdir -p src && \ - printf '\nfn main() {\n\tprintln!("something went wrong while building the docker image")\n}\n' | tee src/main.rs - -# Build the dependencies, remove Cargo files so they have to be re-added. -RUN cargo build --tests &&\ - cargo build --release &&\ - rm -rf Cargo.toml Cargo.lock src/ +#TODO @mark: why compile still takes >1 min each despite pre-compiled dependencies? +FROM mangocode/mango_daily_base:2021-06-27 AS build # Copy the actual code. -COPY ./Cargo.toml ./Cargo.lock ./deny.toml ./rustfmt.toml ./ +# exclude .lock file for now as it slows down dependencies +COPY ./Cargo.toml ./deny.toml ./rustfmt.toml ./ COPY ./src/ ./src # Build (for test) RUN find . -name target -prune -o -type f &&\ touch -c src/main.rs &&\ - cargo --offline build --tests + cargo build --tests #TODO @mark: move up^ ENV RUST_LOG='debug,ws=warn,mio=warn' @@ -65,7 +48,8 @@ FROM scratch AS executable ENV PATH=/ ENV RUST_BACKTRACE=1 -ENV RUST_LOG='debug,ws=warn,mio=warn' +#ENV RUST_LOG='debug,ws=warn,mio=warn' +ENV RUST_LOG='warn' ENV MANGO_USER_CACHE_PATH='/cache' ENV MANGO_USER_CONFIG_PATH='/conf' WORKDIR /code diff --git a/resources/init/main.mnc b/resources/init/main.mnc new file mode 100644 index 0000000..17a3dd7 --- /dev/null +++ b/resources/init/main.mnc @@ -0,0 +1,10 @@ + +use sys.print + +main: + # add your own code here! + print('hello world!') + +test "make sure tests are run": + assert 1 + 1 == 2 + diff --git a/resources/init/mango.sh b/resources/init/mango.sh new file mode 100644 index 0000000..29f42e1 --- /dev/null +++ b/resources/init/mango.sh @@ -0,0 +1,62 @@ +#!/usr/bin/env sh + +# Wrapper that runs Mango using Docker. Arguments are passed on to Mango CLI. +# A continuously-running daemon container is started, if it is not running. + +# Configuration is done through environment variables +# - PROJECT_NAME: name of the project (no whitespace) +# - MANGO_DOCKER_IMAGE: docker image including tag to use + +if [ -z "$PROJECT_NAME" ]; +then + PROJECT_NAME="$(basename "$(pwd)")" +fi + +if [ -z "$MANGO_DOCKER_IMAGE" ]; +then + MANGO_DOCKER_IMAGE="mangocode/mango:latest" +fi + +# Checks + +set -eu + +if ! command -v docker 1> /dev/null 2> /dev/null +then + printf "Docker must be installed to run Mango\n" 1>&2 + exit 1 +fi + +#TODO @mark: check that this is the root dir of the Mango project + +# Docker network + +docker network inspect 'mangod-network' >/dev/null 2>/dev/null || \ + docker network create --driver bridge 'mangod-network' + +# Mango daemon + +if [ -z "$(docker ps -q -f name=mangod)" ] +then + printf "Starting mango daemon container (mangod)\n" + docker run \ + --name "mangod" \ + --label started-by="$PROJECT_NAME" \ + -d --rm \ + --network 'mangod-network' \ + -p 47558:47558 \ + "$MANGO_DOCKER_IMAGE" \ + run-as-daemon \ + --hostname 127.0.0.1 --port 47558 +fi + +# Mango cli + +docker run \ + --name "mango-$PROJECT_NAME" \ + -it --rm \ + --network 'mangod-network' \ + --mount type=bind,source="$(pwd)",target=/code \ + "$MANGO_DOCKER_IMAGE" \ + "$@" + diff --git a/resources/init/mod.mon b/resources/init/mod.mon new file mode 100644 index 0000000..3d7403f --- /dev/null +++ b/resources/init/mod.mon @@ -0,0 +1,16 @@ + +package = { + name = "$PROJECT_NAME$" + version = "0.1.0" +} + +targets = { + $PROJECT_NAME$: { + type = "executable" + path = "main.mns" + } +} + +dependencies = { + test_dependency = "1.0.0" +} diff --git a/src/cli/e2e.rs b/src/cli/e2e.rs index b160b5d..91e4719 100644 --- a/src/cli/e2e.rs +++ b/src/cli/e2e.rs @@ -77,7 +77,6 @@ fn run_with_daemon(args: &[&str], test: impl FnOnce(i32, &str, &str)) { .unwrap() .as_ref() .map(|exe_pth| { - eprintln!("HELLO A"); //TODO @mark: TEMPORARY! REMOVE THIS! let mut child = Command::new(&exe_pth) .arg("run-as-daemon") .arg("-p") @@ -85,13 +84,10 @@ fn run_with_daemon(args: &[&str], test: impl FnOnce(i32, &str, &str)) { .env("RUST_LOG", "debug,ws=warn,mio=warn") .spawn() .unwrap(); - eprintln!("HELLO B"); //TODO @mark: TEMPORARY! REMOVE THIS! let (_, out, _) = run_cli(&["daemon", "get", "status"]); - eprintln!("HELLO C"); //TODO @mark: TEMPORARY! REMOVE THIS! debug!("started mango daemon, status: {}", out); let (status, out, err) = run_cli_with(&exe_pth, args); test(status, &out, &err); - eprintln!("HELLO D"); //TODO @mark: TEMPORARY! REMOVE THIS! debug!("going to stop mango daemon"); sleep(Duration::from_millis(200)); //TODO @mark: TEMPORARY! REMOVE THIS! let (code, _, err) = run_cli(&["daemon", "stop"]); @@ -113,13 +109,13 @@ fn show_help() { //TODO @mark: - failing to start second daemon should fail test //TODO @mark: - it should not start a daemon because one is running //#[test] //TODO @mark: disabled -// fn compile_ir() { -// run_with_daemon(&["compile"], |status, out, err| { -// assert!(status == 0); -// println!("out: {}\n/out", out); //TODO @mark: TEMPORARY! REMOVE THIS! -// println!("err: {}\n/err", err); //TODO @mark: TEMPORARY! REMOVE THIS! -// }); -// } +//fn compile_ir() { +// run_with_daemon(&["compile"], |status, out, err| { +// assert!(status == 0); +// println!("out: {}\n/out", out); //TODO @mark: TEMPORARY! REMOVE THIS! +// println!("err: {}\n/err", err); //TODO @mark: TEMPORARY! REMOVE THIS! +// }); +//} #[test] fn daemon_start_stop() { diff --git a/src/cli/init/mod.rs b/src/cli/init/mod.rs new file mode 100644 index 0000000..4ce91da --- /dev/null +++ b/src/cli/init/mod.rs @@ -0,0 +1,21 @@ +use ::std::io::stdin; + +use crate::cli::options::init::InitCmd; + +pub fn handle_init_cmd(args: &InitCmd) -> Result<(), String> { + let name = args.name.clone() + .unwrap_or_else(|| ask_name("project name? ")?); + + + unimplemented!() +} + +fn ask_name(prompt: &str) -> Result { + print!("{}", prompt); + let q: Name = Name::new(); + let mut name = String::with_capacity(16); + loop { + let input = stdin().read_line(&mut name); + + } +} diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 37a7f0f..bc26c68 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -1,3 +1,4 @@ +pub mod init; pub mod compile; pub mod options; pub mod source; diff --git a/src/cli/options/init.rs b/src/cli/options/init.rs new file mode 100644 index 0000000..3177c07 --- /dev/null +++ b/src/cli/options/init.rs @@ -0,0 +1,11 @@ +use ::structopt::StructOpt; + +#[derive(StructOpt, Debug)] +pub struct InitCmd { + #[structopt( + short = "n", + long = "name", + help = "Name of the project to initialize. If omitted, you will be asked interactively." + )] + pub name: Option, +} diff --git a/src/cli/options/mod.rs b/src/cli/options/mod.rs index 17d511b..f57cf83 100644 --- a/src/cli/options/mod.rs +++ b/src/cli/options/mod.rs @@ -2,6 +2,7 @@ use ::structopt::StructOpt; use crate::common::util::MangodArgs; +pub mod init; pub mod clean; pub mod compile; pub mod daemon; @@ -34,19 +35,15 @@ pub struct MangoArgs { )] pub quiet: bool, - #[structopt( - long = "daemon", - help = "Only show the most important output.", - hidden_short_help=true - )] - pub daemon: bool, - #[structopt(subcommand)] pub cmd: MangoCommand, } #[derive(StructOpt, Debug)] pub enum MangoCommand { + #[structopt(about = "Initialize the current directory as a Mango project")] + Init(init::InitCmd), + // Note: this particular about text is part of a Github Action to check the CLI #[structopt(about = "Compile the code in the current directory to one of various formats")] Compile(compile::CompileCmd), diff --git a/src/main.rs b/src/main.rs index 814b7a9..bebb03d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,24 +7,28 @@ // #[allow(unused_imports)] // use ::mangolib; -#[global_allocator] -static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; - use ::std::process::exit; use ::env_logger; +use ::include_dir::{Dir, include_dir}; use crate::cli::compile::handle_compile_cmd; +use crate::cli::init::handle_init_cmd; use crate::cli::options::MangoArgs; use crate::cli::options::MangoCommand; use crate::cli::status::handle_daemon_cmd; use crate::common::util::MangodStatus; use crate::daemon::run_mango_daemon; +#[global_allocator] +static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; + mod cli; mod common; mod daemon; +pub(crate) const RESOURCES: Dir = include_dir!("resources"); + #[paw::main] fn main(args: MangoArgs) { env_logger::init(); @@ -45,6 +49,7 @@ pub fn cli(args: MangoArgs) -> Result<(), String> { // }; let status = MangodStatus::determine(); match args.cmd { + MangoCommand::Init(init) => handle_init_cmd(&init), MangoCommand::Compile(compile) => handle_compile_cmd(&compile, &status), //TODO @mark: // match compile.target {