feat(options): --boot now supports selecting by entry name or index, not just title

This commit is contained in:
2025-10-24 16:32:48 -07:00
parent d3f9e876fb
commit 911b617d92
5 changed files with 118 additions and 35 deletions

View File

@@ -1,5 +1,5 @@
use crate::context::SproutContext;
use crate::entries::EntryDeclaration;
use crate::entries::{BootableEntry, EntryDeclaration};
use crate::generators::bls::entry::BlsEntry;
use crate::utils;
use anyhow::{Context, Result};
@@ -42,10 +42,7 @@ fn quirk_initrd_remove_tuned(input: String) -> String {
/// Generates entries from the BLS entries directory using the specified `bls` configuration and
/// `context`. The BLS conversion is best-effort and will ignore any unsupported entries.
pub fn generate(
context: Rc<SproutContext>,
bls: &BlsConfiguration,
) -> Result<Vec<(Rc<SproutContext>, EntryDeclaration)>> {
pub fn generate(context: Rc<SproutContext>, bls: &BlsConfiguration) -> Result<Vec<BootableEntry>> {
let mut entries = Vec::new();
// Stamp the path to the BLS entries directory.
@@ -116,7 +113,7 @@ pub fn generate(
// Produce a new sprout context for the entry with the extracted values.
let mut context = context.fork();
let title = entry.title().unwrap_or(name);
let title = entry.title().unwrap_or_else(|| name.clone());
let chainload = entry.chainload_path().unwrap_or_default();
let options = entry.options().unwrap_or_default();
@@ -129,7 +126,12 @@ pub fn generate(
context.set("initrd", initrd);
// Add the entry to the list with a frozen context.
entries.push((context.freeze(), bls.entry.clone()));
entries.push(BootableEntry::new(
name,
bls.entry.title.clone(),
context.freeze(),
bls.entry.clone(),
));
}
Ok(entries)

View File

@@ -1,5 +1,5 @@
use crate::context::SproutContext;
use crate::entries::EntryDeclaration;
use crate::entries::{BootableEntry, EntryDeclaration};
use anyhow::Result;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
@@ -54,13 +54,13 @@ fn build_matrix(input: &BTreeMap<String, Vec<String>>) -> Vec<BTreeMap<String, S
pub fn generate(
context: Rc<SproutContext>,
matrix: &MatrixConfiguration,
) -> Result<Vec<(Rc<SproutContext>, EntryDeclaration)>> {
) -> Result<Vec<BootableEntry>> {
// Produce all the combinations of the input values.
let combinations = build_matrix(&matrix.values);
let mut entries = Vec::new();
// For each combination, create a new context and entry.
for combination in combinations {
for (index, combination) in combinations.into_iter().enumerate() {
let mut context = context.fork();
// Insert the combination into the context.
context.insert(&combination);
@@ -68,14 +68,18 @@ pub fn generate(
// Stamp the entry title and actions from the template.
let mut entry = matrix.entry.clone();
entry.title = context.stamp(&entry.title);
entry.actions = entry
.actions
.into_iter()
.map(|action| context.stamp(action))
.collect();
// Push the entry into the list with the new context.
entries.push((context, entry));
entries.push(BootableEntry::new(
index.to_string(),
entry.title.clone(),
context,
entry,
));
}
Ok(entries)