Skip to content
Snippets Groups Projects
Commit 0fa73071 authored by Tom Almeida's avatar Tom Almeida
Browse files

Merge branch 'allow-map-index-numbers' into 'master'

Add the ability to use numbers for indexing map types

Closes #840

See merge request redox-os/ion!891
parents 23fdefd4 dfb36bf9
No related branches found
No related tags found
No related merge requests found
...@@ -496,6 +496,17 @@ impl<'a> Expander for Shell { ...@@ -496,6 +496,17 @@ impl<'a> Expander for Shell {
hmap.get(&*key).unwrap_or(&VariableType::Str("".into())) hmap.get(&*key).unwrap_or(&VariableType::Str("".into()))
)]) )])
} }
Select::Index(index) => {
use ranges::Index;
return Some(array![format!(
"{}",
hmap.get(&types::Str::from(match index {
Index::Forward(n) => n as isize,
Index::Backward(n) => -((n+1) as isize)
}.to_string()))
.unwrap_or(&VariableType::Str("".into()))
)])
}
_ => (), _ => (),
} }
} else if let Some(bmap) = self.variables.get::<types::BTreeMap>(name) { } else if let Some(bmap) = self.variables.get::<types::BTreeMap>(name) {
...@@ -525,6 +536,17 @@ impl<'a> Expander for Shell { ...@@ -525,6 +536,17 @@ impl<'a> Expander for Shell {
bmap.get(&*key).unwrap_or(&VariableType::Str("".into())) bmap.get(&*key).unwrap_or(&VariableType::Str("".into()))
)]) )])
} }
Select::Index(index) => {
use ranges::Index;
return Some(array![format!(
"{}",
bmap.get(&types::Str::from(match index {
Index::Forward(n) => n as isize,
Index::Backward(n) => -((n+1) as isize)
}.to_string()))
.unwrap_or(&VariableType::Str("".into()))
)])
}
_ => (), _ => (),
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment