32 lines
731 B
Rust
32 lines
731 B
Rust
use crate::opt::{ActiveOpt, OptKind};
|
|
|
|
#[derive(Debug)]
|
|
pub struct Context {
|
|
opts: Vec<ActiveOpt>,
|
|
}
|
|
|
|
impl Context {
|
|
pub(crate) fn new(opts: Vec<ActiveOpt>) -> Self {
|
|
Self { opts }
|
|
}
|
|
|
|
pub fn flag(&self, name: &str) -> bool {
|
|
self.opts
|
|
.iter()
|
|
.any(|o| o.definition.name == name && matches!(o.definition.kind, OptKind::Flag))
|
|
}
|
|
|
|
pub fn get_string(&self, name: &str) -> Option<String> {
|
|
self.opts
|
|
.iter()
|
|
.find_map(|o| {
|
|
if o.definition.name == name {
|
|
Some(o.raw_value.first().cloned())
|
|
} else {
|
|
None
|
|
}
|
|
})
|
|
.flatten()
|
|
}
|
|
}
|