mirror of
https://github.com/nushell/nushell
synced 2024-12-26 13:03:07 +00:00
Add basic obj path indexing
This commit is contained in:
parent
a537fc96c0
commit
108439f3d1
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 => {
|
||||||
Some(v) => {
|
let tmp = step.to_string_lossy();
|
||||||
viewed = v;
|
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) => {
|
||||||
|
viewed = v;
|
||||||
|
}
|
||||||
|
_ => println!("Obj not Some"),
|
||||||
|
},
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
match viewed.get_data_by_key(s) {
|
||||||
|
Some(v) => {
|
||||||
|
viewed = v;
|
||||||
|
}
|
||||||
|
_ => println!("Obj not Some"),
|
||||||
|
}
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ => println!("Obj not Some"),
|
}
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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