|
1 | 1 | use clap; |
2 | | -use efivar::efi_guids; |
| 2 | +use efivar; |
3 | 3 | use ignore_result::Ignore; |
4 | 4 | use std::io; |
5 | 5 | use std::process::ExitCode; |
@@ -79,7 +79,7 @@ fn create_parser() -> clap::Command { |
79 | 79 | .short('g') |
80 | 80 | .long("guids-list-path") |
81 | 81 | .value_name("guids-list-path") |
82 | | - .default_value(efi_guids::DEFAULT_GUIDS_LIST_PATH) |
| 82 | + .default_value(efivar::efi_guids::DEFAULT_GUIDS_LIST_PATH) |
83 | 83 | .help(format!("specify path to GUIDs list file.")) |
84 | 84 | .action(clap::ArgAction::Set) |
85 | 85 | ) |
@@ -109,25 +109,67 @@ fn create_parser() -> clap::Command { |
109 | 109 | ); |
110 | 110 | } |
111 | 111 |
|
| 112 | +fn list_variables(parser_args: clap::ArgMatches) -> ExitCode { |
| 113 | + return std::process::ExitCode::from(0); |
| 114 | +} |
| 115 | + |
| 116 | +fn print_variable(parser_args: clap::ArgMatches, print_mode: efivar::types::PrintMode) -> ExitCode { |
| 117 | + return std::process::ExitCode::from(0); |
| 118 | +} |
| 119 | + |
| 120 | +fn append_attributes(parser_args: clap::ArgMatches) -> ExitCode { |
| 121 | + return std::process::ExitCode::from(0); |
| 122 | +} |
| 123 | + |
| 124 | +fn list_guids(parser_args: clap::ArgMatches) -> ExitCode { |
| 125 | + let mut guid_list: efivar::efi_guids::EfiGuidList = Default::default(); |
| 126 | + match guid_list.load(parser_args.get_one("guids-list-path").unwrap()) { |
| 127 | + Ok(()) => { |
| 128 | + for g in guid_list.guids(efivar::efi_guids::GuidListSortField::Guid) { |
| 129 | + println!("{}", g); |
| 130 | + } |
| 131 | + } |
| 132 | + Err(e) => { |
| 133 | + eprintln!("Failed to read GUIDs list file: {}", e); |
| 134 | + return std::process::ExitCode::from(e.raw_os_error().unwrap_or(1) as u8); |
| 135 | + } |
| 136 | + } |
| 137 | + return std::process::ExitCode::from(0); |
| 138 | +} |
| 139 | + |
| 140 | +fn write_variable(parser_args: clap::ArgMatches) -> ExitCode { |
| 141 | + return std::process::ExitCode::from(0); |
| 142 | +} |
| 143 | + |
| 144 | +fn import_variable(parser_args: clap::ArgMatches) -> ExitCode { |
| 145 | + return std::process::ExitCode::from(0); |
| 146 | +} |
| 147 | + |
| 148 | +fn export_variable(parser_args: clap::ArgMatches) -> ExitCode { |
| 149 | + return std::process::ExitCode::from(0); |
| 150 | +} |
| 151 | + |
112 | 152 | fn main() -> ExitCode { |
113 | 153 | let mut parser = create_parser(); |
114 | 154 | let matches = parser.get_matches_mut(); |
115 | | - if matches.get_flag("list-guids") { |
116 | | - let mut guid_list: efi_guids::EfiGuidList = Default::default(); |
117 | | - match guid_list.load(matches.get_one("guids-list-path").unwrap()) { |
118 | | - Ok(()) => { |
119 | | - for g in guid_list.guids(efi_guids::GuidListSortField::Guid) { |
120 | | - println!("{}", g); |
121 | | - } |
122 | | - } |
123 | | - Err(e) => { |
124 | | - eprintln!("Failed to read GUIDs list file: {}", e); |
125 | | - return std::process::ExitCode::from(1); |
126 | | - } |
127 | | - } |
| 155 | + if matches.get_flag("list") { |
| 156 | + return list_variables(matches); |
| 157 | + } else if matches.get_flag("print") { |
| 158 | + return print_variable(matches, efivar::types::PrintMode::VERBOSE); |
| 159 | + } else if matches.get_flag("append") { |
| 160 | + return append_attributes(matches); |
| 161 | + } else if matches.get_flag("list-guids") { |
| 162 | + return list_guids(matches); |
| 163 | + } else if matches.get_flag("write") { |
| 164 | + return write_variable(matches); |
| 165 | + } else if matches.get_flag("print-decimal") { |
| 166 | + return print_variable(matches, efivar::types::PrintMode::DECIMAL); |
| 167 | + } else if matches.get_one::<&str>("import").is_some() { |
| 168 | + return import_variable(matches); |
| 169 | + } else if matches.get_one::<&str>("export").is_some() { |
| 170 | + return export_variable(matches); |
128 | 171 | } else { |
129 | 172 | parser.write_help(&mut io::stderr()).ignore(); |
130 | | - return std::process::ExitCode::from(1); |
| 173 | + return std::process::ExitCode::from(22 /* EINVAL */); |
131 | 174 | } |
132 | | - return std::process::ExitCode::from(0); |
133 | 175 | } |
0 commit comments