git clone https://garage44.eu/jeroen/pinnacle.git.. /kernel/src/args.rs
//! The kernel's command line, as its loader gave it (the device tree's
//! `/chosen/bootargs` on ARM, Multiboot2's or PVH's on a PC): words, some
//! of them `key=value`. Kept once at boot for whoever asks later.
use crate::sync::SpinLock;
use alloc::string::String;
static LINE: SpinLock<String> = SpinLock::new(String::new());
/// Keeps `line` as the command line.
pub fn set(line: &str) {
*LINE.lock() = String::from(line.trim());
}
/// The whole line.
pub fn line() -> String {
LINE.lock().clone()
}
/// Whether `word` is one of its words.
pub fn has(word: &str) -> bool {
LINE.lock().split(' ').any(|w| w == word)
}
/// The value of its `key=value` word, if it has one.
pub fn value(key: &str) -> Option<String> {
LINE.lock()
.split(' ')
.find_map(|w| w.strip_prefix(key)?.strip_prefix('=').map(String::from))
}