implement a new sprout command line options mechanism

This commit is contained in:
2025-10-20 18:17:29 -07:00
parent 3d2c31ee1a
commit c749c8d38e
5 changed files with 170 additions and 17 deletions

View File

@@ -1,4 +1,5 @@
use crate::actions::ActionDeclaration;
use crate::options::SproutOptions;
use anyhow::Result;
use anyhow::anyhow;
use std::collections::{BTreeMap, BTreeSet};
@@ -13,15 +14,18 @@ pub struct RootContext {
actions: BTreeMap<String, ActionDeclaration>,
/// The device path of the loaded Sprout image.
loaded_image_path: Option<Box<DevicePath>>,
/// The global options of Sprout.
options: SproutOptions,
}
impl RootContext {
/// Creates a new root context with the `loaded_image_device_path` which will be stored
/// in the context for easy access.
pub fn new(loaded_image_device_path: Box<DevicePath>) -> Self {
pub fn new(loaded_image_device_path: Box<DevicePath>, options: SproutOptions) -> Self {
Self {
actions: BTreeMap::new(),
loaded_image_path: Some(loaded_image_device_path),
options,
}
}
@@ -41,6 +45,11 @@ impl RootContext {
.as_deref()
.ok_or_else(|| anyhow!("no loaded image path"))
}
/// Access the global Sprout options.
pub fn options(&self) -> &SproutOptions {
&self.options
}
}
/// A context of Sprout. This is passed around different parts of Sprout and represents