Skip to content

Commit 8ad22ea

Browse files
committed
Add full CLI skeleton
1 parent b4adc26 commit 8ad22ea

File tree

1 file changed

+59
-17
lines changed

1 file changed

+59
-17
lines changed

src/bin/efivar.rs

Lines changed: 59 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clap;
2-
use efivar::efi_guids;
2+
use efivar;
33
use ignore_result::Ignore;
44
use std::io;
55
use std::process::ExitCode;
@@ -79,7 +79,7 @@ fn create_parser() -> clap::Command {
7979
.short('g')
8080
.long("guids-list-path")
8181
.value_name("guids-list-path")
82-
.default_value(efi_guids::DEFAULT_GUIDS_LIST_PATH)
82+
.default_value(efivar::efi_guids::DEFAULT_GUIDS_LIST_PATH)
8383
.help(format!("specify path to GUIDs list file."))
8484
.action(clap::ArgAction::Set)
8585
)
@@ -109,25 +109,67 @@ fn create_parser() -> clap::Command {
109109
);
110110
}
111111

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+
112152
fn main() -> ExitCode {
113153
let mut parser = create_parser();
114154
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);
128171
} else {
129172
parser.write_help(&mut io::stderr()).ignore();
130-
return std::process::ExitCode::from(1);
173+
return std::process::ExitCode::from(22 /* EINVAL */);
131174
}
132-
return std::process::ExitCode::from(0);
133175
}

0 commit comments

Comments
 (0)