|
1 | 1 | extern crate efivar; |
2 | | -extern crate argparse; |
3 | 2 |
|
4 | | -use argparse::{ArgumentParser, StoreTrue, StoreFalse}; |
| 3 | +use clap; |
| 4 | +use efivar::{efivar_display, efi_variable_attributes}; |
| 5 | +use std::collections::HashSet; |
| 6 | +use std::convert::TryInto; |
5 | 7 | use std::process::ExitCode; |
6 | 8 |
|
7 | | -fn main() -> ExitCode { |
8 | | - let mut verbose = false; |
9 | | - let mut parser = ArgumentParser::new(); |
| 9 | +#[derive(Eq, Hash, PartialEq)] |
| 10 | +enum ActionType { |
| 11 | + Append, |
| 12 | + Export, |
| 13 | + Import, |
| 14 | + List, |
| 15 | + ListGuids, |
| 16 | + Print, |
| 17 | + Write |
| 18 | +} |
10 | 19 |
|
11 | | - parser.refer(&mut verbose) |
12 | | - .add_option(&["-v", "--verbose"], StoreTrue, "Be verbose") |
13 | | - .add_option(&["-q", "--quiet"], StoreFalse, "Be quiet"); |
| 20 | +#[derive(Eq, Hash, PartialEq)] |
| 21 | +struct EfivarAction(ActionType); |
14 | 22 |
|
15 | | - match parser.parse_args() { |
16 | | - Ok(()) => { |
17 | | - std::process::ExitCode::from(0) |
18 | | - } |
19 | | - Err(x) => { |
20 | | - std::process::ExitCode::from(x as u8) |
21 | | - } |
22 | | - } |
| 23 | +fn main() -> ExitCode { |
| 24 | + let parser = clap::command!() |
| 25 | + .args_override_self(true) |
| 26 | + .disable_help_flag(true) |
| 27 | + .disable_version_flag(true) |
| 28 | + .max_term_width(90) |
| 29 | + .term_width(90) |
| 30 | + .arg(clap::Arg::new("attributes") |
| 31 | + .short('A') |
| 32 | + .long("attributes") |
| 33 | + .help("attributes to use on append") |
| 34 | + .action(clap::ArgAction::Set) |
| 35 | + ) |
| 36 | + .arg(clap::Arg::new("list") |
| 37 | + .short('l') |
| 38 | + .long("list") |
| 39 | + .help("list current variables") |
| 40 | + .action(clap::ArgAction::Set) |
| 41 | + ) |
| 42 | + .arg(clap::Arg::new("print") |
| 43 | + .short('p') |
| 44 | + .long("print") |
| 45 | + .help("Print variable specified by --name") |
| 46 | + .action(clap::ArgAction::SetTrue) |
| 47 | + ) |
| 48 | + .arg(clap::Arg::new("dmpstore") |
| 49 | + .short('D') |
| 50 | + .long("dmpstore") |
| 51 | + .help("use DMPSTORE format when exporting") |
| 52 | + .action(clap::ArgAction::SetTrue) |
| 53 | + ) |
| 54 | + .arg(clap::Arg::new("print-decimal") |
| 55 | + .short('d') |
| 56 | + .long("print-decimal") |
| 57 | + .help("print variable in decimal values specified by --name") |
| 58 | + .action(clap::ArgAction::SetTrue) |
| 59 | + ) |
| 60 | + .arg(clap::Arg::new("name") |
| 61 | + .short('n') |
| 62 | + .long("name") |
| 63 | + .value_name("guid-name") |
| 64 | + .help("variable to manipulate, in the form 8be4df61-93ca-11d2-aa0d-00e098032b8c-Boot0000") |
| 65 | + .action(clap::ArgAction::Set) |
| 66 | + ) |
| 67 | + .arg(clap::Arg::new("append") |
| 68 | + .short('a') |
| 69 | + .long("append") |
| 70 | + .help("append to variable specified by --name") |
| 71 | + .action(clap::ArgAction::SetTrue) |
| 72 | + ) |
| 73 | + .arg(clap::Arg::new("datafile") |
| 74 | + .short('f') |
| 75 | + .long("datafile") |
| 76 | + .value_name("file") |
| 77 | + .help("load or save variable contents from or to <file>") |
| 78 | + .action(clap::ArgAction::Set) |
| 79 | + ) |
| 80 | + .arg(clap::Arg::new("export") |
| 81 | + .short('e') |
| 82 | + .long("export") |
| 83 | + .value_name("file") |
| 84 | + .help("export variable to <file>") |
| 85 | + .action(clap::ArgAction::Set) |
| 86 | + ) |
| 87 | + .arg(clap::Arg::new("import") |
| 88 | + .short('i') |
| 89 | + .long("import") |
| 90 | + .value_name("file") |
| 91 | + .help("import variable from <file>") |
| 92 | + .action(clap::ArgAction::Set) |
| 93 | + ) |
| 94 | + .arg(clap::Arg::new("list-guids") |
| 95 | + .short('L') |
| 96 | + .long("list-guids") |
| 97 | + .help("show internal GUID list") |
| 98 | + .action(clap::ArgAction::SetTrue) |
| 99 | + ) |
| 100 | + .arg(clap::Arg::new("write") |
| 101 | + .short('w') |
| 102 | + .long("write") |
| 103 | + .help("Write to variable specified by --name") |
| 104 | + .action(clap::ArgAction::SetTrue) |
| 105 | + ) |
| 106 | + .arg(clap::Arg::new("help") |
| 107 | + .short('?') |
| 108 | + .long("help") |
| 109 | + .help("Show this help message") |
| 110 | + .action(clap::ArgAction::Help) |
| 111 | + ) |
| 112 | + .arg(clap::Arg::new("usage") |
| 113 | + .short(None) |
| 114 | + .long("usage") |
| 115 | + .help("ignored for compatibility") |
| 116 | + .action(clap::ArgAction::Help) |
| 117 | + ) |
| 118 | + .get_matches(); |
| 119 | + return std::process::ExitCode::from(0); |
23 | 120 | } |
0 commit comments