@@ -7,8 +7,6 @@ use std::path::PathBuf;
7
7
use clap:: { Parser , Subcommand , ValueEnum } ;
8
8
use vmm:: cpu_config:: templates:: { GetCpuTemplate , GetCpuTemplateError } ;
9
9
10
- use crate :: utils:: UtilsError ;
11
-
12
10
mod fingerprint;
13
11
mod template;
14
12
mod utils;
@@ -26,7 +24,7 @@ enum HelperError {
26
24
/// Failed to serialize/deserialize JSON file: {0}
27
25
Serde ( #[ from] serde_json:: Error ) ,
28
26
/// {0}
29
- Utils ( #[ from] UtilsError ) ,
27
+ Utils ( #[ from] utils :: UtilsError ) ,
30
28
/// {0}
31
29
TemplateDump ( #[ from] template:: dump:: DumpError ) ,
32
30
/// {0}
@@ -127,12 +125,10 @@ fn run(cli: Cli) -> Result<(), HelperError> {
127
125
write ( output, cpu_config_json) ?;
128
126
}
129
127
TemplateOperation :: Strip { paths, suffix } => {
130
- let mut templates = Vec :: with_capacity ( paths. len ( ) ) ;
131
- for path in & paths {
132
- let template_json = read_to_string ( path) ?;
133
- let template = serde_json:: from_str ( & template_json) ?;
134
- templates. push ( template) ;
135
- }
128
+ let templates = paths
129
+ . iter ( )
130
+ . map ( utils:: load_cpu_template)
131
+ . collect :: < Result < Vec < _ > , utils:: UtilsError > > ( ) ?;
136
132
137
133
let stripped_templates = template:: strip:: strip ( templates) ?;
138
134
@@ -144,13 +140,10 @@ fn run(cli: Cli) -> Result<(), HelperError> {
144
140
}
145
141
TemplateOperation :: Verify { config, template } => {
146
142
let config = config. map ( read_to_string) . transpose ( ) ?;
147
- let template = match template {
148
- Some ( path) => {
149
- let template_json = read_to_string ( path) ?;
150
- Some ( serde_json:: from_str ( & template_json) ?)
151
- }
152
- None => None ,
153
- } ;
143
+ let template = template
144
+ . as_ref ( )
145
+ . map ( utils:: load_cpu_template)
146
+ . transpose ( ) ?;
154
147
let ( vmm, vm_resources) = utils:: build_microvm_from_config ( config, template) ?;
155
148
156
149
let cpu_template = vm_resources
0 commit comments