Skip to content

Commit 251e0f7

Browse files
committed
cmdline/serializer: Fix serializer to include hidden firstboot-args field
1 parent c1faf0c commit 251e0f7

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

src/cmdline/install.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ impl InstallConfig {
274274

275275
// Collect firstboot-args from all sources
276276
let mut firstboot_args = Vec::new();
277-
277+
278278
// Get firstboot-args from config files
279279
for path in &self.config_file {
280280
let config: InstallConfig = serde_yaml::from_reader(
@@ -284,12 +284,12 @@ impl InstallConfig {
284284
.with_context(|| format!("opening config file {path}"))?,
285285
)
286286
.with_context(|| format!("parsing config file {path}"))?;
287-
287+
288288
if let Some(args) = config.firstboot_args {
289289
firstboot_args.push(args);
290290
}
291291
}
292-
292+
293293
// Get firstboot-args from command line
294294
if let Some(args) = &self.firstboot_args {
295295
firstboot_args.push(args.clone());
@@ -314,10 +314,11 @@ impl InstallConfig {
314314
.with_context(|| format!("opening config file {path}"))?,
315315
)
316316
.with_context(|| format!("parsing config file {path}"))?;
317-
317+
318318
// Clear firstboot-args from config files since we handle them separately
319319
config.firstboot_args = None;
320-
config.to_args()
320+
config
321+
.to_args()
321322
.with_context(|| format!("serializing config file {path}"))
322323
})
323324
.collect::<Result<Vec<Vec<_>>>>()?
@@ -326,9 +327,10 @@ impl InstallConfig {
326327
.collect::<Vec<_>>();
327328

328329
// Add command line args (excluding firstboot-args)
329-
let cmdline_args = self.to_args()
330+
let cmdline_args = self
331+
.to_args()
330332
.context("serializing command-line arguments")?;
331-
333+
332334
// Remove firstboot-args from command line args
333335
let mut filtered_cmdline_args = Vec::new();
334336
let mut i = 0;
@@ -341,9 +343,9 @@ impl InstallConfig {
341343
i += 1;
342344
}
343345
}
344-
346+
345347
args.extend(filtered_cmdline_args);
346-
348+
347349
// Add the combined firstboot-args at the end
348350
if let Some(combined_args) = combined_firstboot_args {
349351
args.push("--firstboot-args".to_string());
@@ -598,15 +600,17 @@ dest-device: u
598600
f.as_file_mut()
599601
.write_all(b"dest-device: /dev/sda\nfirstboot-args: rd.multipath=default")
600602
.unwrap();
601-
603+
602604
let config = InstallConfig::from_args(&[
603-
"--config-file", f.path().to_str().unwrap(),
604-
"--firstboot-args", "ip=dhcp"
605+
"--config-file",
606+
f.path().to_str().unwrap(),
607+
"--firstboot-args",
608+
"ip=dhcp",
605609
])
606610
.unwrap()
607611
.expand_config_files()
608612
.unwrap();
609-
613+
610614
// Should preserve both firstboot-args
611615
assert!(config.firstboot_args.is_some());
612616
let args = config.firstboot_args.unwrap();

src/cmdline/serializer.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ impl Serializer {
4949
fn push_field(&mut self, name: &'static str) {
5050
let field = if self.help_text.contains(&format!(" --{name} ")) {
5151
Some(name)
52+
} else if name == "firstboot-args" {
53+
// Special case for firstboot-args
54+
Some(name)
5255
} else {
5356
// don't serialize to --option
5457
None

0 commit comments

Comments
 (0)