Skip to content

Commit ab93da8

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

File tree

1 file changed

+57
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)