fn run_server(
    exec: Arc<Mutex<String>>,
    dir: PathBuf,
    did_build: bool,
) -> Result<i32, ExecutionError> {
    let target = dir.join(".perseus/server");
    let num_steps = match did_build {
        true => 4,
        false => 2,
    };

    // First off, handle any issues with the executable path
    let exec_val = exec.lock().unwrap();
    if exec_val.is_empty() {
        return Err(ExecutionError::ParseServerExecutableFailed {
            err: "mutex value empty, implies uncaught thread termination (please report this as a bug)"
                .to_string()
    });
    }
    let server_exec_path = (*exec_val).to_string();

    // Manually run the generated binary (invoking in the right directory context for good measure if it ever needs it in future)
    let child = Command::new(&server_exec_path)
        .current_dir(target)
        // We should be able to access outputs in case there's an error
        .stdout(Stdio::piped())
        .stderr(Stdio::piped())
        .spawn()
        .map_err(|err| ExecutionError::CmdExecFailed {
            cmd: server_exec_path,
            source: err,
        })?;
    // Figure out what host/port the app will be live on (these have been set by the system)
    let host = env::var("PERSEUS_HOST").unwrap_or_else(|_| "localhost".to_string());
    let port = env::var("PERSEUS_PORT")
        .unwrap_or_else(|_| "8080".to_string())
        .parse::<u16>()
        .map_err(|err| ExecutionError::PortNotNumber { source: err })?;
    // Give the user a nice informational message
    println!(
        "  {} {} Your app is now live on <http://{host}:{port}>! To change this, re-run this command with different settings for `--host` and `--port`.",
        style(format!("[{}/{}]", num_steps, num_steps)).bold().dim(),
        SERVING,
        host=host,
        port=port
    );

    // Wait on the child process to finish (which it shouldn't unless there's an error), then perform error handling
    let output = child.wait_with_output().unwrap();
    let exit_code = match output.status.code() {
        Some(exit_code) => exit_code,         // If we have an exit code, use it
        None if output.status.success() => 0, // If we don't, but we know the command succeeded, return 0 (success code)
        None => 1, // If we don't know an exit code but we know that the command failed, return 1 (general error code)
    };
    // Print `stderr` and stdout` only if there's something therein and the exit code is non-zero
    if !output.stderr.is_empty() && exit_code != 0 {
        // We don't print any failure message other than the actual error right now (see if people want something else?)
        std::io::stderr().write_all(&output.stdout).unwrap();
        std::io::stderr().write_all(&output.stderr).unwrap();
        return Ok(1);
    }

    Ok(0)
}
/// Runs the server at the given path, handling any errors therewith. This will likely be a black hole until the user manually terminates
/// the process.
Runs the server at the given path, handling any errors therewith. This will likely be a black hole until the user manually terminates
the process.
Runs the server at the given path handling any errors therewith . This will likely be a black hole until the user manually terminates the process .
fn run_server(
    exec: Arc<Mutex<String>>,
    dir: PathBuf,
    did_build: bool,
) -> Result<i32, ExecutionError> {
    let target = dir.join(".perseus/server");
    let num_steps = match did_build {
        true => 4,
        false => 2,
    };
    // First off, handle any issues with the executable path
    let exec_val = exec.lock().unwrap();
    if exec_val.is_empty() {
        return Err(ExecutionError::ParseServerExecutableFailed {
            err: "mutex value empty, implies uncaught thread termination (please report this as a bug)"
                .to_string()
    });
    }
    let server_exec_path = (*exec_val).to_string();
    // Manually run the generated binary (invoking in the right directory context for good measure if it ever needs it in future)
    let child = Command::new(&server_exec_path)
        .current_dir(target)
        // We should be able to access outputs in case there's an error
        .stdout(Stdio::piped())
        .stderr(Stdio::piped())
        .spawn()
        .map_err(|err| ExecutionError::CmdExecFailed {
            cmd: server_exec_path,
            source: err,
        })?;
    // Figure out what host/port the app will be live on (these have been set by the system)
    let host = env::var("PERSEUS_HOST").unwrap_or_else(|_| "localhost".to_string());
    let port = env::var("PERSEUS_PORT")
        .unwrap_or_else(|_| "8080".to_string())
        .parse::<u16>()
        .map_err(|err| ExecutionError::PortNotNumber { source: err })?;
    // Give the user a nice informational message
    println!(
        "  {} {} Your app is now live on <http://{host}:{port}>! To change this, re-run this command with different settings for `--host` and `--port`.",
        style(format!("[{}/{}]", num_steps, num_steps)).bold().dim(),
        SERVING,
        host=host,
        port=port
    );
    // Wait on the child process to finish (which it shouldn't unless there's an error), then perform error handling
    let output = child.wait_with_output().unwrap();
    let exit_code = match output.status.code() {
        Some(exit_code) => exit_code,         // If we have an exit code, use it
        None if output.status.success() => 0, // If we don't, but we know the command succeeded, return 0 (success code)
        None => 1, // If we don't know an exit code but we know that the command failed, return 1 (general error code)
    };
    // Print `stderr` and stdout` only if there's something therein and the exit code is non-zero
    if !output.stderr.is_empty() && exit_code != 0 {
        // We don't print any failure message other than the actual error right now (see if people want something else?)
        std::io::stderr().write_all(&output.stdout).unwrap();
        std::io::stderr().write_all(&output.stderr).unwrap();
        return Ok(1);
    }
    Ok(0)
}
fn run_server ( exec : Arc < Mutex < String > > , dir : PathBuf , did_build : bool , ) -> Result < i32 , ExecutionError > { let target = dir . join ( " " ) ; let num_steps = match did_build { true => 4 , false => 2 , } ; // First off, handle any issues with the executable path let exec_val = exec . lock ( ) . unwrap ( ) ; if exec_val . is_empty ( ) { return Err ( ExecutionError :: ParseServerExecutableFailed { err : " " . to_string ( ) } ) ; } let server_exec_path = ( * exec_val ) . to_string ( ) ; // Manually run the generated binary (invoking in the right directory context for good measure if it ever needs it in future) let child = Command :: new ( & server_exec_path ) . current_dir ( target ) // We should be able to access outputs in case there's an error . stdout ( Stdio :: piped ( ) ) . stderr ( Stdio :: piped ( ) ) . spawn ( ) . map_err ( | err | ExecutionError :: CmdExecFailed { cmd : server_exec_path , source : err , } ) ? ; // Figure out what host/port the app will be live on (these have been set by the system) let host = env :: var ( " " ) . unwrap_or_else ( | _ | " " . to_string ( ) ) ; let port = env :: var ( " " ) . unwrap_or_else ( | _ | " " . to_string ( ) ) . parse :: < u16 > ( ) . map_err ( | err | ExecutionError :: PortNotNumber { source : err } ) ? ; // Give the user a nice informational message println ! ( " " style ( format ( " " num_steps num_steps ) ) bold ( ) dim ( ) SERVING host host port port ) ; // Wait on the child process to finish (which it shouldn't unless there's an error), then perform error handling let output = child . wait_with_output ( ) . unwrap ( ) ; let exit_code = match output . status . code ( ) { Some ( exit_code ) => exit_code , // If we have an exit code, use it None if output . status . success ( ) => 0 , // If we don't, but we know the command succeeded, return 0 (success code) None => 1 , // If we don't know an exit code but we know that the command failed, return 1 (general error code) } ; // Print `stderr` and stdout` only if there's something therein and the exit code is non-zero if ! output . stderr . is_empty ( ) && exit_code != 0 { // We don't print any failure message other than the actual error right now (see if people want something else?) std :: io :: stderr ( ) . write_all ( & output . stdout ) . unwrap ( ) ; std :: io :: stderr ( ) . write_all ( & output . stderr ) . unwrap ( ) ; return Ok ( 1 ) ; } Ok ( 0 ) }
Runs the server at the given path, handling any errors therewith.
Runs the server at the given path handling any errors therewith .
exec
Arc<Mutex<String>>
dir
PathBuf
did_build
bool
exec
Arc<Mutex<String>>
dir
PathBuf
did_build
bool