sim_run_core/boot.rs
1use std::{ffi::OsString, path::PathBuf};
2
3use crate::{LibSourceSpec, boot_codec_name, codec_lib_symbol};
4
5/// Parsed bootloader controls and payload data.
6#[derive(Clone, Debug, Default, PartialEq, Eq)]
7pub struct CliBoot {
8 /// Codec name selected with `--codec`, or `None` for the default.
9 pub codec: Option<String>,
10 /// Library sources to load, in `--load` order.
11 pub loads: Vec<LibSourceSpec>,
12 /// Optional native audio provider source requested by the operator.
13 pub native_audio_provider: Option<Box<LibSourceSpec>>,
14 /// Whether `--list` requested a loaded-lib listing.
15 pub list: bool,
16 /// Symbol passed to `--inspect`, if any.
17 pub inspect: Option<String>,
18 /// Payload data preserved for the loaded-lib handoff.
19 pub payload: Payload,
20}
21
22impl CliBoot {
23 /// Builds the data envelope handed to loaded libraries.
24 pub fn envelope(&self) -> CliEnvelope {
25 let codec_name = boot_codec_name(self);
26 CliEnvelope {
27 codec: codec_lib_symbol(codec_name),
28 verb: self
29 .payload
30 .args
31 .first()
32 .map(|arg| arg.to_string_lossy().into_owned()),
33 args: self.payload.args.clone(),
34 eval: self.payload.eval.clone(),
35 script: self.payload.script.clone(),
36 stdin: self.payload.stdin.clone(),
37 }
38 }
39}
40
41/// Payload preserved for loaded-lib behavior.
42#[derive(Clone, Debug, Default, PartialEq, Eq)]
43pub struct Payload {
44 /// Trailing positional arguments handed to the loaded entrypoint.
45 pub args: Vec<OsString>,
46 /// Eval text carried from `--eval`.
47 pub eval: Option<String>,
48 /// Script path carried from `--script`.
49 pub script: Option<PathBuf>,
50 /// Stdin text carried from `--stdin`.
51 pub stdin: Option<String>,
52}
53
54/// Data envelope supplied to the selected loaded-lib entrypoint.
55#[derive(Clone, Debug, PartialEq, Eq)]
56pub struct CliEnvelope {
57 /// Codec library symbol selected for the boot session.
58 pub codec: String,
59 /// First payload argument, exposed as the loaded-lib verb.
60 pub verb: Option<String>,
61 /// Full payload argument list.
62 pub args: Vec<OsString>,
63 /// Eval text carried from `--eval`.
64 pub eval: Option<String>,
65 /// Script path carried from `--script`.
66 pub script: Option<PathBuf>,
67 /// Stdin text carried from `--stdin`.
68 pub stdin: Option<String>,
69}