@@ -18,6 +18,8 @@ enum Commands {
1818 Measure ( MachineConfig ) ,
1919}
2020
21+ type Bool = bool ;
22+
2123#[ derive( Parser ) ]
2224struct MachineConfig {
2325 /// Number of CPUs
@@ -33,18 +35,18 @@ struct MachineConfig {
3335
3436 /// Enable two-pass add pages
3537 #[ arg( long, default_value = "true" ) ]
36- two_pass_add_pages : bool ,
38+ two_pass_add_pages : Bool ,
3739
3840 /// Enable PIC
3941 #[ arg( long, default_value = "true" ) ]
40- pic : bool ,
42+ pic : Bool ,
4143
4244 /// Enable SMM
4345 #[ arg( long, default_value = "false" ) ]
44- smm : bool ,
46+ smm : Bool ,
4547
46- /// PCI hole64 size
47- #[ arg( long) ]
48+ /// PCI hole64 size (accepts decimal or hex with 0x prefix)
49+ #[ arg( long, value_parser = parse_memory_size ) ]
4850 pci_hole64_size : Option < u64 > ,
4951
5052 /// Enable hugepages
@@ -61,18 +63,20 @@ struct MachineConfig {
6163
6264 /// Disable hotplug
6365 #[ arg( long, default_value = "false" ) ]
64- hotplug_off : bool ,
66+ hotplug_off : Bool ,
6567
6668 /// Enable root verity
6769 #[ arg( long, default_value = "true" ) ]
68- root_verity : bool ,
70+ root_verity : Bool ,
6971
7072 /// Output JSON
71- #[ arg( long, default_value = "false" ) ]
73+ #[ arg( long) ]
7274 json : bool ,
7375}
7476
7577fn main ( ) -> Result < ( ) > {
78+ tracing_subscriber:: fmt:: init ( ) ;
79+
7680 let cli = Cli :: parse ( ) ;
7781 match & cli. command {
7882 Commands :: Measure ( config) => {
@@ -123,20 +127,22 @@ fn main() -> Result<()> {
123127 Ok ( ( ) )
124128}
125129
130+ /// Parse a memory size value that can be decimal or hexadecimal (with 0x prefix)
126131fn parse_memory_size ( s : & str ) -> Result < u64 > {
127132 let s = s. trim ( ) ;
128133
129- // Check if the string is empty
130134 if s. is_empty ( ) {
131135 return Err ( anyhow ! ( "Empty memory size" ) ) ;
132136 }
137+ if s. starts_with ( "0x" ) || s. starts_with ( "0X" ) {
138+ let hex_str = & s[ 2 ..] ;
139+ return u64:: from_str_radix ( hex_str, 16 )
140+ . map_err ( |e| anyhow ! ( "Invalid hexadecimal value: {}" , e) ) ;
141+ }
133142
134- // Handle bare number (bytes)
135143 if s. chars ( ) . all ( |c| c. is_ascii_digit ( ) ) {
136144 return Ok ( s. parse :: < u64 > ( ) ?) ;
137145 }
138-
139- // Handle suffixes
140146 let len = s. len ( ) ;
141147 let ( num_part, suffix) = match s. chars ( ) . last ( ) . unwrap ( ) {
142148 'k' | 'K' => ( & s[ 0 ..len - 1 ] , 1024u64 ) ,
0 commit comments