mindustry logic execution, map- and schematic- parsing and rendering
Diffstat (limited to 'src/args.rs')
-rw-r--r--src/args.rs23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/args.rs b/src/args.rs
index 62a2596..eea8b80 100644
--- a/src/args.rs
+++ b/src/args.rs
@@ -177,7 +177,7 @@ impl OptionHandler
Self{options: Vec::new(), short_map: HashMap::new(), long_map: HashMap::new(), literals: Vec::new()}
}
- pub fn add(&mut self, opt: ArgOption) -> Result<(), (ArgOption, &ArgOption)>
+ pub fn add(&mut self, opt: ArgOption) -> Result<OptionRef, (ArgOption, &ArgOption)>
{
match opt.short
{
@@ -210,7 +210,7 @@ impl OptionHandler
let k = &**s;
self.long_map.insert(k.to_owned(), idx);
}
- Ok(())
+ Ok(OptionRef(idx))
}
pub fn options(&self) -> &Vec<(ArgOption, OptionValue)>
@@ -218,6 +218,22 @@ impl OptionHandler
&self.options
}
+ pub fn get(&self, opt_ref: OptionRef) -> (&ArgOption, &OptionValue)
+ {
+ let opt = &self.options[opt_ref.0];
+ (&opt.0, &opt.1)
+ }
+
+ pub fn get_option(&self, opt_ref: OptionRef) -> &ArgOption
+ {
+ &self.options[opt_ref.0].0
+ }
+
+ pub fn get_value(&self, opt_ref: OptionRef) -> &OptionValue
+ {
+ &self.options[opt_ref.0].1
+ }
+
pub fn get_short(&self, name: char) -> Option<&(ArgOption, OptionValue)>
{
self.short_map.get(&name).map(|&i| &self.options[i])
@@ -254,6 +270,9 @@ impl OptionHandler
}
}
+#[derive(Clone, Copy, Debug)]
+pub struct OptionRef(usize);
+
impl ArgHandler for OptionHandler
{
type Error = OptionError;