Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(efiboot/list): allow to show a single namespace #44

Merged
merged 1 commit into from
Jul 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions efiboot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ efivar = { version = "1.0.14", path = "../efivar", features = ["store"] }
itertools = "0.10.5"
paw = "1.0.0"
structopt = { version = "0.3.26", features = ["paw"] }
uuid = { version = "1.3.4" }

[package.metadata.binstall]
pkg-url = "{ repo }/releases/download/v{ version }/{ name }_{ target }{ archive-suffix }"
Expand Down
30 changes: 27 additions & 3 deletions efiboot/src/cli/list.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
use efivar::VarManager;
use efivar::{efi::VariableVendor, VarManager};

pub fn run(enumerator: Box<dyn VarManager>) {
fn list_all(enumerator: Box<dyn VarManager>) {
println!("{: >36} Variable", "Namespace");

Check warning on line 4 in efiboot/src/cli/list.rs

View check run for this annotation

Codecov / codecov/patch

efiboot/src/cli/list.rs#L3-L4

Added lines #L3 - L4 were not covered by tests
for var in enumerator
.get_var_names()
.expect("Failed to list variable names")
{
println!("{}", var.short_name());
println!("{} {}", var.vendor(), var.variable());
}
}

Check warning on line 11 in efiboot/src/cli/list.rs

View check run for this annotation

Codecov / codecov/patch

efiboot/src/cli/list.rs#L9-L11

Added lines #L9 - L11 were not covered by tests

fn list_namespace(enumerator: Box<dyn VarManager>, vendor: VariableVendor) {
println!("Variables in namespace {} :", vendor);
for var in enumerator
.get_var_names()
.expect("Failed to list variable names")

Check warning on line 17 in efiboot/src/cli/list.rs

View check run for this annotation

Codecov / codecov/patch

efiboot/src/cli/list.rs#L13-L17

Added lines #L13 - L17 were not covered by tests
{
if var.vendor() == &vendor {
println!("{}", var.variable());
}

Check warning on line 21 in efiboot/src/cli/list.rs

View check run for this annotation

Codecov / codecov/patch

efiboot/src/cli/list.rs#L19-L21

Added lines #L19 - L21 were not covered by tests
}
}

Check warning on line 23 in efiboot/src/cli/list.rs

View check run for this annotation

Codecov / codecov/patch

efiboot/src/cli/list.rs#L23

Added line #L23 was not covered by tests

pub fn run(enumerator: Box<dyn VarManager>, namespace: Option<uuid::Uuid>, all: bool) {
if all {
list_all(enumerator);
} else {
list_namespace(
enumerator,
namespace.map_or(VariableVendor::Efi, VariableVendor::Custom),
);

Check warning on line 32 in efiboot/src/cli/list.rs

View check run for this annotation

Codecov / codecov/patch

efiboot/src/cli/list.rs#L25-L32

Added lines #L25 - L32 were not covered by tests
}
}
13 changes: 10 additions & 3 deletions efiboot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@
string: bool,
},
/// List known EFI variables
List,
List {
/// GUID of the namespace. Default: EFI standard namespace

Check warning on line 20 in efiboot/src/main.rs

View check run for this annotation

Codecov / codecov/patch

efiboot/src/main.rs#L20

Added line #L20 was not covered by tests
#[structopt(value_name = "GUID")]
namespace: Option<uuid::Uuid>,
/// ignore --namespace and show all namespaces
#[structopt(short, long)]
all: bool,
},
}

#[derive(StructOpt)]
Expand Down Expand Up @@ -48,8 +55,8 @@
Command::Read { name, string } => {
cli::read(manager, &name, string);
}
Command::List => {
cli::list(manager);
Command::List { namespace, all } => {
cli::list(manager, namespace, all);
}
}
}