1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
use std::path::PathBuf;
use clap::Parser;
use efivar::VarManager;
use crate::exit_code::ExitCode;
use self::boot::BootCommand;
pub mod boot;
pub mod delete;
pub mod export;
pub mod import;
pub mod list;
pub mod read;
#[cfg(test)]
pub mod tests;
#[derive(Parser)]
pub enum Command {
/// Read the value of a variable
#[command(alias = "info")]
Read {
/// Name of the variable to read
#[arg(value_name = "VARIABLE")]
name: String,
/// GUID of the namespace. Default: EFI standard namespace
#[arg(short, long, value_name = "NAMESPACE")]
namespace: Option<uuid::Uuid>,
/// Print the value as an UTF-8 string
#[arg(short, long)]
string: bool,
/// Skip the header and print the raw variable value
#[arg(short, long)]
raw: bool,
},
/// List known EFI variables
List {
/// GUID of the namespace. Default: EFI standard namespace
#[arg(short, long, value_name = "NAMESPACE")]
namespace: Option<uuid::Uuid>,
/// ignore --namespace and show all namespaces
#[arg(short, long)]
all: bool,
},
/// Delete an EFI variabe
// #[arg(visible_alias = "del")]
// #[arg(visible_alias = "remove")]
#[command(alias = "del")]
#[command(alias = "remove")]
Delete {
/// Name of the variable to delete
#[arg(value_name = "VARIABLE")]
name: String,
/// GUID of the namespace. Default: EFI standard namespace
#[arg(short, long, value_name = "NAMESPACE")]
namespace: Option<uuid::Uuid>,
},
/// Manage boot-related variables
#[command(subcommand)]
Boot(BootCommand),
/// Export a variable to file
Export {
/// Name of the variable to export
#[arg(value_name = "VARIABLE")]
name: String,
/// GUID of the namespace. Default: EFI standard namespace
#[arg(short, long, value_name = "NAMESPACE")]
namespace: Option<uuid::Uuid>,
/// Output file
#[arg(value_name = "OUTPUT_FILE")]
output_file: PathBuf,
},
/// Import a variable from a file.
/// Putting `-` as a file will read from stdin instead
Import {
/// Input file
#[arg(value_name = "INPUT_FILE")]
input_file: PathBuf,
/// Name of the variable to create
#[arg(value_name = "VARIABLE")]
name: String,
/// GUID of the namespace. Default: EFI standard namespace
#[arg(short, long, value_name = "NAMESPACE")]
namespace: Option<uuid::Uuid>,
},
}
pub fn run(manager: &mut dyn VarManager, cmd: Command) -> ExitCode {
match cmd {
Command::Read {
name,
namespace,
string,
raw,
} => read::run(manager, &name, namespace, string, raw),
Command::List { namespace, all } => list::run(manager, namespace, all),
Command::Delete { name, namespace } => delete::run(manager, &name, namespace),
Command::Boot(arg) => boot::run(manager, arg),
Command::Export {
name,
namespace,
output_file,
} => export::run(manager, &name, namespace, &output_file),
Command::Import {
input_file,
name,
namespace,
} => import::run(manager, &input_file, &name, namespace),
}
}