mirror of
https://github.com/nushell/nushell
synced 2024-12-27 05:23:11 +00:00
Merge pull request #106 from jonathandturner/obj_path_idx
Add basic obj path indexing
This commit is contained in:
commit
a3c3c4d776
2 changed files with 48 additions and 5 deletions
|
@ -51,14 +51,50 @@ pub fn ls(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||||
let sep_string = std::path::MAIN_SEPARATOR.to_string();
|
let sep_string = std::path::MAIN_SEPARATOR.to_string();
|
||||||
let sep = OsStr::new(&sep_string);
|
let sep = OsStr::new(&sep_string);
|
||||||
for p in full_path.iter() {
|
for p in full_path.iter() {
|
||||||
|
//let p = p.to_string_lossy();
|
||||||
match p {
|
match p {
|
||||||
x if x == sep => {}
|
x if x == sep => {}
|
||||||
step => match viewed.get_data_by_key(step.to_str().unwrap()) {
|
step => {
|
||||||
|
let tmp = step.to_string_lossy();
|
||||||
|
let split_tmp = tmp.split('[');
|
||||||
|
let mut first = true;
|
||||||
|
|
||||||
|
for s in split_tmp {
|
||||||
|
if !first {
|
||||||
|
match s.find(']') {
|
||||||
|
Some(finish) => {
|
||||||
|
let idx = s[0..finish].parse::<usize>();
|
||||||
|
match idx {
|
||||||
|
Ok(idx) => match viewed.get_data_by_index(idx) {
|
||||||
|
Some(v) => {
|
||||||
|
viewed = v;
|
||||||
|
}
|
||||||
|
_ => println!("Idx not found"),
|
||||||
|
},
|
||||||
|
_ => println!("idx not a number"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => println!("obj not some"),
|
||||||
|
/*
|
||||||
|
_ => match viewed.get_data_by_key(s) {
|
||||||
Some(v) => {
|
Some(v) => {
|
||||||
viewed = v;
|
viewed = v;
|
||||||
}
|
}
|
||||||
_ => println!("Obj not Some"),
|
_ => println!("Obj not Some"),
|
||||||
},
|
},
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
match viewed.get_data_by_key(s) {
|
||||||
|
Some(v) => {
|
||||||
|
viewed = v;
|
||||||
|
}
|
||||||
|
_ => println!("Obj not Some"),
|
||||||
|
}
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
match viewed {
|
match viewed {
|
||||||
|
|
|
@ -202,6 +202,13 @@ impl Value {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
crate fn get_data_by_index(&'a self, idx: usize) -> Option<&Value> {
|
||||||
|
match self {
|
||||||
|
Value::List(l) => l.iter().nth(idx),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
crate fn get_data(&'a self, desc: &DataDescriptor) -> MaybeOwned<'a, Value> {
|
crate fn get_data(&'a self, desc: &DataDescriptor) -> MaybeOwned<'a, Value> {
|
||||||
match self {
|
match self {
|
||||||
p @ Value::Primitive(_) => MaybeOwned::Borrowed(p),
|
p @ Value::Primitive(_) => MaybeOwned::Borrowed(p),
|
||||||
|
|
Loading…
Reference in a new issue