Skip to content

Commit fe20dd3

Browse files
committed
Switch to clap parser
1 parent 1904a86 commit fe20dd3

40 files changed

+124
-3343
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,10 @@ build
55

66
/target
77
/Cargo.lock
8+
9+
10+
# Added by cargo
11+
#
12+
# already existing elements were commented out
13+
14+
#/target

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ name = "efivar"
1717
path = "src/bin/efivar.rs"
1818

1919
[dependencies]
20-
clap = { version = "4.1.13", default-features = false, features = ["std"] }
20+
clap = { version = "4.1.13", default-features = false, features = ["std", "cargo", "help", "wrap_help", "usage"] }

src/bin/efivar.rs

Lines changed: 113 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,120 @@
11
extern crate efivar;
2-
extern crate argparse;
32

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;
57
use std::process::ExitCode;
68

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+
}
1019

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);
1422

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);
23120
}

src/lib/efivar/efivar_display.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::fmt;
2-
use types::{EfiVariable, EfiVariableAttribute};
2+
use crate::types::{EfiVariable, EfiVariableAttribute};
33

44
pub struct Verbose<'a>(pub &'a EfiVariable<'a>);
55
pub struct Decimal<'a>(pub &'a EfiVariable<'a>);

src/lib/efivar/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ pub mod types;
22
pub mod efivar_display;
33

44
pub mod efi_variable_attributes {
5-
use types::EfiVariableAttribute;
5+
use crate::types::EfiVariableAttribute;
66

77
pub static NON_VOLATILE:EfiVariableAttribute
88
= EfiVariableAttribute::init("Non-Volatile", 0x1);

src/lib/efivar/types/efi_guid.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::fmt;
33
use std::iter;
44
use std::str::FromStr;
55
use super::EfiGuidError;
6-
use types::efi_guid_error;
6+
use crate::types::efi_guid_error;
77

88
#[derive(Debug, Clone, PartialEq, Eq, Copy)]
99
pub struct EfiGuid {

src/lib/rust-argparse/.gitignore

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/lib/rust-argparse/.travis.yml

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/lib/rust-argparse/Cargo.toml

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/lib/rust-argparse/LICENSE

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)