diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c2d066f..c66f49b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ ubuntu-latest, macOS-latest, windows-latest ] + os: [ ubuntu-latest, macOS-latest ] # windows build is broken, see the note in README steps: - name: Checkout sources uses: actions/checkout@v2 @@ -21,7 +21,7 @@ jobs: uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: 1.66.0 + toolchain: 1.78.0 override: true components: rustfmt, clippy diff --git a/CHANGELOG.md b/CHANGELOG.md index ec678a4..5fe2765 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # Changelog +### 0.0.6 +- Allow unlabeled command: + +```rust +cmd! { + "cargo build", + env: Env::empty(), + pwd: Loc::root(), + msg: "Building a server", +} +``` + ### 0.0.5 - Fix non-TLS build. diff --git a/README.md b/README.md index 9604782..229a3e7 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,9 @@ See [docs.rs/steward](https://docs.rs/steward). See [`examples`](./examples). ## Limitations +### Windows +Apparently, Windows build is broken on recent versions of Rust due to [`winapi`](https://github.com/retep998/winapi-rs) being unmaintained. We need to migrate to [`windows-rs`](https://github.com/microsoft/windows-rs), but I don't know anything about Windows, so help is very welcome! + ### Async runtimes Tokio only. diff --git a/examples/cli/main.rs b/examples/cli/main.rs index 5bf4afd..ffdd1af 100644 --- a/examples/cli/main.rs +++ b/examples/cli/main.rs @@ -79,7 +79,7 @@ mod client { pub fn build() -> Cmd { cmd! { - exe: "rescript build -with-deps", + "rescript build -with-deps", env: env(), pwd: Loc::client(), msg: "Building ReScript client", @@ -91,7 +91,7 @@ mod client { tag: "rescript", cmd: cmd! { - exe: "rescript build -w", + "rescript build -w", env: env(), pwd: Loc::client(), msg: "Watching ReScript client", @@ -105,7 +105,7 @@ mod server { pub fn build() -> Cmd { cmd! { - exe: "cargo build --package=server", + "cargo build --package=server", env: Config::to_env(), pwd: Loc::root(), msg: "Building Rust server", @@ -117,7 +117,7 @@ mod server { tag: "server", cmd: cmd! { - exe: "cargo watch --watch server --exec 'run --package=server --color=always'", + "cargo watch --watch server --exec 'run --package=server --color=always'", env: Config::to_env(), pwd: Loc::root(), msg: "Running reloadable Rust server", diff --git a/src/cmd.rs b/src/cmd.rs index c0066dd..ff68431 100644 --- a/src/cmd.rs +++ b/src/cmd.rs @@ -245,7 +245,7 @@ where /// General command: /// ```ignore /// cmd! { -/// exe: "rm -rf target", +/// "rm -rf target", /// env: Env::empty(), /// pwd: Loc::root(), /// msg: "Removing target dir", @@ -255,7 +255,7 @@ where /// Dynamically constructed command: /// ```ignore /// cmd! { -/// exe: format!("rm -rf {}", dir), +/// format!("rm -rf {}", dir), /// env: Env::empty(), /// pwd: Loc::root(), /// msg: format!("Removing {} dir", dir), @@ -265,6 +265,15 @@ where /// Command without a message: /// ```ignore /// cmd! { +/// "ls", +/// env: Env::empty(), +/// pwd: Loc::root(), +/// } +/// ``` +/// +/// You can label a command with `exe:` if you want to: +/// ```ignore +/// cmd! { /// exe: "ls", /// env: Env::empty(), /// pwd: Loc::root(), @@ -272,6 +281,19 @@ where /// ``` #[macro_export] macro_rules! cmd { + { + $exe:literal, + env: $env:expr, + pwd: $pwd:expr, + msg: $msg:literal$(,)? + } => { + $crate::Cmd { + exe: $exe.to_string(), + env: $env, + pwd: $pwd, + msg: Some($msg.to_string()), + } + }; { exe: $exe:literal, env: $env:expr, @@ -285,6 +307,19 @@ macro_rules! cmd { msg: Some($msg.to_string()), } }; + { + $exe:literal, + env: $env:expr, + pwd: $pwd:expr, + msg: Some($msg:expr)$(,)? + } => { + $crate::Cmd { + exe: $exe.to_string(), + env: $env, + pwd: $pwd, + msg: Some($msg), + } + }; { exe: $exe:literal, env: $env:expr, @@ -298,6 +333,19 @@ macro_rules! cmd { msg: Some($msg), } }; + { + $exe:literal, + env: $env:expr, + pwd: $pwd:expr, + msg: None$(,)? + } => { + $crate::Cmd { + exe: $exe.to_string(), + env: $env, + pwd: $pwd, + msg: None, + } + }; { exe: $exe:literal, env: $env:expr, @@ -311,6 +359,19 @@ macro_rules! cmd { msg: None, } }; + { + $exe:literal, + env: $env:expr, + pwd: $pwd:expr, + msg: $msg:expr$(,)? + } => { + $crate::Cmd { + exe: $exe.to_string(), + env: $env, + pwd: $pwd, + msg: Some($msg), + } + }; { exe: $exe:literal, env: $env:expr, @@ -324,6 +385,19 @@ macro_rules! cmd { msg: Some($msg), } }; + { + $exe:expr, + env: $env:expr, + pwd: $pwd:expr, + msg: $msg:literal$(,)? + } => { + $crate::Cmd { + exe: $exe, + env: $env, + pwd: $pwd, + msg: Some($msg.to_string()), + } + }; { exe: $exe:expr, env: $env:expr, @@ -337,6 +411,19 @@ macro_rules! cmd { msg: Some($msg.to_string()), } }; + { + $exe:expr, + env: $env:expr, + pwd: $pwd:expr, + msg: Some($msg:expr)$(,)? + } => { + $crate::Cmd { + exe: $exe, + env: $env, + pwd: $pwd, + msg: Some($msg), + } + }; { exe: $exe:expr, env: $env:expr, @@ -350,6 +437,19 @@ macro_rules! cmd { msg: Some($msg), } }; + { + $exe:expr, + env: $env:expr, + pwd: $pwd:expr, + msg: None$(,)? + } => { + $crate::Cmd { + exe: $exe, + env: $env, + pwd: $pwd, + msg: None, + } + }; { exe: $exe:expr, env: $env:expr, @@ -363,6 +463,19 @@ macro_rules! cmd { msg: None, } }; + { + $exe:expr, + env: $env:expr, + pwd: $pwd:expr, + msg: $msg:expr$(,)? + } => { + $crate::Cmd { + exe: $exe, + env: $env, + pwd: $pwd, + msg: Some($msg), + } + }; { exe: $exe:expr, env: $env:expr, @@ -376,6 +489,18 @@ macro_rules! cmd { msg: Some($msg), } }; + { + $exe:literal, + env: $env:expr, + pwd: $pwd:expr$(,)? + } => { + $crate::Cmd { + exe: $exe.to_string(), + env: $env, + pwd: $pwd, + msg: None, + } + }; { exe: $exe:literal, env: $env:expr, @@ -388,6 +513,18 @@ macro_rules! cmd { msg: None, } }; + { + $exe:expr, + env: $env:expr, + pwd: $pwd:expr$(,)? + } => { + $crate::Cmd { + exe: $exe, + env: $env, + pwd: $pwd, + msg: None, + } + }; { exe: $exe:expr, env: $env:expr, @@ -407,7 +544,17 @@ mod tests { use crate::{Cmd, Env, Location}; #[allow(dead_code)] - fn cmd_macro_exe_literal_msg_literal(env: Env, loc: Loc) -> Cmd { + fn cmd_macro_unlabeled_exe_literal_msg_literal(env: Env, loc: Loc) -> Cmd { + cmd! { + "ls", + env: env, + pwd: loc, + msg: "!", + } + } + + #[allow(dead_code)] + fn cmd_macro_labeled_exe_literal_msg_literal(env: Env, loc: Loc) -> Cmd { cmd! { exe: "ls", env: env, @@ -417,7 +564,17 @@ mod tests { } #[allow(dead_code)] - fn cmd_macro_exe_expr_msg_literal(env: Env, loc: Loc) -> Cmd { + fn cmd_macro_unlabeled_exe_expr_msg_literal(env: Env, loc: Loc) -> Cmd { + cmd! { + format!("ls {}", "."), + env: env, + pwd: loc, + msg: "!", + } + } + + #[allow(dead_code)] + fn cmd_macro_labeled_exe_expr_msg_literal(env: Env, loc: Loc) -> Cmd { cmd! { exe: format!("ls {}", "."), env: env, @@ -427,7 +584,17 @@ mod tests { } #[allow(dead_code)] - fn cmd_macro_exe_expr_msg_expr(env: Env, loc: Loc) -> Cmd { + fn cmd_macro_unlabeled_exe_expr_msg_expr(env: Env, loc: Loc) -> Cmd { + cmd! { + format!("ls {}", "."), + env: env, + pwd: loc, + msg: format!("!"), + } + } + + #[allow(dead_code)] + fn cmd_macro_labeled_exe_expr_msg_expr(env: Env, loc: Loc) -> Cmd { cmd! { exe: format!("ls {}", "."), env: env, @@ -437,7 +604,17 @@ mod tests { } #[allow(dead_code)] - fn cmd_macro_exe_literal_msg_expr(env: Env, loc: Loc) -> Cmd { + fn cmd_macro_unlabeled_exe_literal_msg_expr(env: Env, loc: Loc) -> Cmd { + cmd! { + "ls", + env: env, + pwd: loc, + msg: format!("!"), + } + } + + #[allow(dead_code)] + fn cmd_macro_labeled_exe_literal_msg_expr(env: Env, loc: Loc) -> Cmd { cmd! { exe: "ls", env: env, @@ -447,7 +624,20 @@ mod tests { } #[allow(dead_code)] - fn cmd_macro_exe_literal_msg_some_expr(env: Env, loc: Loc) -> Cmd { + fn cmd_macro_unlabeled_exe_literal_msg_some_expr( + env: Env, + loc: Loc, + ) -> Cmd { + cmd! { + "ls", + env: env, + pwd: loc, + msg: Some(format!("!")), + } + } + + #[allow(dead_code)] + fn cmd_macro_labeled_exe_literal_msg_some_expr(env: Env, loc: Loc) -> Cmd { cmd! { exe: "ls", env: env, @@ -457,7 +647,17 @@ mod tests { } #[allow(dead_code)] - fn cmd_macro_exe_expr_msg_some_expr(env: Env, loc: Loc) -> Cmd { + fn cmd_macro_unlabeled_exe_expr_msg_some_expr(env: Env, loc: Loc) -> Cmd { + cmd! { + format!("ls {}", "."), + env: env, + pwd: loc, + msg: Some(format!("!")), + } + } + + #[allow(dead_code)] + fn cmd_macro_labeled_exe_expr_msg_some_expr(env: Env, loc: Loc) -> Cmd { cmd! { exe: format!("ls {}", "."), env: env, @@ -467,7 +667,17 @@ mod tests { } #[allow(dead_code)] - fn cmd_macro_exe_literal_msg_none(env: Env, loc: Loc) -> Cmd { + fn cmd_macro_unlabeled_exe_literal_msg_none(env: Env, loc: Loc) -> Cmd { + cmd! { + "ls", + env: env, + pwd: loc, + msg: None, + } + } + + #[allow(dead_code)] + fn cmd_macro_labeled_exe_literal_msg_none(env: Env, loc: Loc) -> Cmd { cmd! { exe: "ls", env: env, @@ -477,7 +687,17 @@ mod tests { } #[allow(dead_code)] - fn cmd_macro_exe_expr_msg_none(env: Env, loc: Loc) -> Cmd { + fn cmd_macro_unlabeled_exe_expr_msg_none(env: Env, loc: Loc) -> Cmd { + cmd! { + format!("ls {}", "."), + env: env, + pwd: loc, + msg: None, + } + } + + #[allow(dead_code)] + fn cmd_macro_labeled_exe_expr_msg_none(env: Env, loc: Loc) -> Cmd { cmd! { exe: format!("ls {}", "."), env: env, @@ -487,7 +707,16 @@ mod tests { } #[allow(dead_code)] - fn cmd_macro_exe_literal_no_msg(env: Env, loc: Loc) -> Cmd { + fn cmd_macro_unlabeled_exe_literal_no_msg(env: Env, loc: Loc) -> Cmd { + cmd! { + "ls", + env: env, + pwd: loc, + } + } + + #[allow(dead_code)] + fn cmd_macro_labeled_exe_literal_no_msg(env: Env, loc: Loc) -> Cmd { cmd! { exe: "ls", env: env, @@ -496,7 +725,16 @@ mod tests { } #[allow(dead_code)] - fn cmd_macro_exe_expr_no_msg(env: Env, loc: Loc) -> Cmd { + fn cmd_macro_unlabeled_exe_expr_no_msg(env: Env, loc: Loc) -> Cmd { + cmd! { + format!("ls {}", "."), + env: env, + pwd: loc, + } + } + + #[allow(dead_code)] + fn cmd_macro_labeled_exe_expr_no_msg(env: Env, loc: Loc) -> Cmd { cmd! { exe: format!("ls {}", "."), env: env, @@ -505,7 +743,12 @@ mod tests { } #[allow(dead_code)] - fn cmd_macro_no_trailing_comma(env: Env, loc: Loc) -> Cmd { + fn cmd_macro_unlabeled_exe_no_trailing_comma(env: Env, loc: Loc) -> Cmd { + cmd! { "ls", env: env, pwd: loc } + } + + #[allow(dead_code)] + fn cmd_macro_labeled_exe_no_trailing_comma(env: Env, loc: Loc) -> Cmd { cmd! { exe: "ls", env: env, pwd: loc } } } diff --git a/src/lib.rs b/src/lib.rs index b1fb4db..53dd98e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,7 +33,7 @@ //! mod server { //! fn build_cmd() -> Cmd { //! cmd! { -//! exe: "cargo build", +//! "cargo build", //! env: Env::empty(), //! pwd: Loc::root(), //! msg: "Building a server", @@ -44,7 +44,7 @@ //! process! { //! tag: "server", //! cmd: cmd! { -//! exe: "cargo watch", +//! "cargo watch", //! env: Env::empty(), //! pwd: Loc::root(), //! msg: "Running a reloadable server", @@ -56,7 +56,7 @@ //! mod client { //! fn build_cmd() -> Cmd { //! cmd! { -//! exe: "npm build", +//! "npm build", //! env: Env::empty(), //! pwd: Loc::root(), //! msg: "Building a client", @@ -67,7 +67,7 @@ //! process! { //! tag: "client", //! cmd: cmd! { -//! exe: "npm watch", +//! "npm watch", //! env: Env::empty(), //! pwd: Loc::root(), //! msg: "Watching a client", @@ -78,6 +78,12 @@ //! ``` //! //! ## Limitations +//! ### Windows +//! Apparently, Windows build is broken on recent versions of Rust due to +//! [`winapi`](https://github.com/retep998/winapi-rs) being unmaintained. +//! We need to migrate to [`windows-rs`](https://github.com/microsoft/windows-rs), +//! but I don't know anything about Windows, so help is very welcome! +//! //! ### Async runtimes //! Tokio only. @@ -86,7 +92,7 @@ /// ```ignore /// async fn build() -> steward::Result<()> { /// let build_cmd = cmd! { -/// exe: "cargo build", +/// "cargo build", /// env: Env::empty(), /// pwd: Loc::root(), /// msg: "Building a server", @@ -104,7 +110,7 @@ pub mod cmd; /// let server_process = process! { /// tag: "server", /// cmd: cmd! { -/// exe: "cargo watch", +/// "cargo watch", /// env: Env::empty(), /// pwd: Loc::root(), /// msg: "Running a reloadable server", @@ -114,7 +120,7 @@ pub mod cmd; /// let client_process = process! { /// tag: "client", /// cmd: cmd! { -/// exe: "rescript build -w", +/// "rescript build -w", /// env: Env::empty(), /// pwd: Loc::root(), /// msg: "Watching a client",