Skip to content

Commit 5a443ee

Browse files
committed
ShellParams: Add example app
Signed-off-by: Daniel Schaefer <[email protected]>
1 parent ab19c99 commit 5a443ee

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// ANCHOR: all
2+
// ANCHOR: features
3+
#![no_main]
4+
#![no_std]
5+
// ANCHOR_END: features
6+
7+
use log::error;
8+
// ANCHOR: use
9+
use uefi::{prelude::*, proto::shell_params::ShellParameters};
10+
use uefi_services::println;
11+
12+
extern crate alloc;
13+
use alloc::string::{String, ToString};
14+
use alloc::vec::Vec;
15+
// ANCHOR_END: use
16+
17+
// ANCHOR: entry
18+
#[entry]
19+
fn main(image_handle: Handle, mut system_table: SystemTable<Boot>) -> Status {
20+
// ANCHOR_END: entry
21+
// ANCHOR: services
22+
uefi_services::init(&mut system_table).unwrap();
23+
let boot_services = system_table.boot_services();
24+
// ANCHOR_END: services
25+
26+
// ANCHOR: params
27+
let shell_params =
28+
boot_services.open_protocol_exclusive::<ShellParameters>(image_handle);
29+
let shell_params = match shell_params {
30+
Ok(s) => s,
31+
Err(e) => {
32+
error!("Failed to get ShellParameters protocol");
33+
return e.status();
34+
}
35+
};
36+
37+
// Get as Vec of String, only with alloc feature
38+
let args: Vec<String> =
39+
shell_params.args().map(|x| x.to_string()).collect();
40+
println!("Args: {:?}", args);
41+
42+
// Or without allocating, get a slice of the pointers
43+
println!("Num args: {}", args.len());
44+
if shell_params.args_len() > 1 {
45+
println!("First real arg: '{}'", args[1]);
46+
}
47+
// ANCHOR_END: params
48+
49+
// ANCHOR: return
50+
Status::SUCCESS
51+
}
52+
// ANCHOR_END: return
53+
// ANCHOR_END: all

0 commit comments

Comments
 (0)