Skip to main content

Hook

Trait Hook 

Source
pub trait Hook {
    // Required method
    fn build_command(self: Box<Self>, server: &DevServer) -> Command;
}
Available on non-WebAssembly only.
Expand description

A type that can produce a process::Command given the final DevServer configuration.

Implement this trait to build a command whose arguments or environment depend on the server’s configuration — for example to pass --dist-dir, --port, or other runtime values.

A blanket implementation is provided for process::Command itself, so existing call sites that pass a plain command continue to work without any changes.

§Examples

use std::process;
use xtask_wasm::{anyhow::Result, clap, DevServer, Hook};

struct NotifyOnPort;

impl Hook for NotifyOnPort {
    fn build_command(self: Box<Self>, server: &DevServer) -> process::Command {
        let mut cmd = process::Command::new("notify-send");
        cmd.arg(format!("dev server on port {}", server.port));
        cmd
    }
}

#[derive(clap::Parser)]
enum Opt {
    Start(xtask_wasm::DevServer),
}

fn main() -> Result<()> {
    let opt: Opt = clap::Parser::parse();

    match opt {
        Opt::Start(dev_server) => {
            dev_server
                .xtask("dist")
                .post(NotifyOnPort)
                .start()?;
        }
    }

    Ok(())
}

Required Methods§

Source

fn build_command(self: Box<Self>, server: &DevServer) -> Command

Construct the process::Command to run, using server as context.

Implementations on Foreign Types§

Source§

impl Hook for Command

Source§

fn build_command(self: Box<Self>, _server: &DevServer) -> Command

Implementors§