perseus_cli/
export_error_page.rs

1use crate::cmd::run_cmd;
2use crate::errors::ExecutionError;
3use crate::install::Tools;
4use crate::parse::{ExportErrorPageOpts, Opts};
5use std::path::PathBuf;
6
7/// Exports a single error page for the given HTTP status code to the given
8/// location.
9pub fn export_error_page(
10    dir: PathBuf,
11    opts: &ExportErrorPageOpts,
12    tools: &Tools,
13    global_opts: &Opts,
14    prompt: bool,
15) -> Result<i32, ExecutionError> {
16    // This function would tell the user everything if something goes wrong
17    let (_stdout, _stderr, exit_code) = run_cmd(
18        format!(
19            "{} run {} -- {} {}",
20            tools.cargo_engine,
21            global_opts.cargo_engine_args,
22            // These are mandatory
23            opts.code,
24            opts.output,
25        ),
26        &dir,
27        vec![
28            ("PERSEUS_ENGINE_OPERATION", "export_error_page"),
29            ("CARGO_TARGET_DIR", "dist/target_engine"),
30            ("RUSTFLAGS", "--cfg=engine"),
31            ("CARGO_TERM_COLOR", "always"),
32        ],
33        || {},
34        global_opts.verbose,
35    )?;
36
37    if prompt {
38        println!("🖨 Error page exported for code '{}'!", opts.code);
39    }
40
41    Ok(exit_code)
42}