diff --git a/src/commands/ls.rs b/src/commands/ls.rs index 67f9b15f4a..70cbf9d53e 100644 --- a/src/commands/ls.rs +++ b/src/commands/ls.rs @@ -51,14 +51,50 @@ pub fn ls(args: CommandArgs) -> Result { let sep_string = std::path::MAIN_SEPARATOR.to_string(); let sep = OsStr::new(&sep_string); for p in full_path.iter() { + //let p = p.to_string_lossy(); match p { x if x == sep => {} - step => match viewed.get_data_by_key(step.to_str().unwrap()) { - Some(v) => { - viewed = v; + 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::(); + 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 { diff --git a/src/object/base.rs b/src/object/base.rs index aaeb883a19..506de9e8d4 100644 --- a/src/object/base.rs +++ b/src/object/base.rs @@ -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> { match self { p @ Value::Primitive(_) => MaybeOwned::Borrowed(p),