fixed top-level keys

This commit is contained in:
Emma Tebibyte 2022-12-19 14:19:08 -05:00
parent f404de7a2d
commit 4e3c5e21f5

View File

@ -40,20 +40,26 @@ fn main() {
} else { content = input.to_string(); }
let mut tabkey: Vec<&str> = arguments[0].split(".").collect();
let mut indexvec: Vec<&str> = tabkey[1].split(&['[', ']'][..]).collect();
tabkey[1] = indexvec.remove(0);
let mut indexvec = Vec::new();
let mut index: usize = 0;
if ! indexvec.is_empty() {
let istr = indexvec.remove(0);
match usize::from_str(istr) {
Ok(i) => index = i,
Err(_) => {
eprintln!("{}: {}: Cannot index by given value.", argv0, istr);
process::exit(65); // sysexits(3) EX_DATAERR
},
};
}
match tabkey.iter().skip(1).peekable().peek() {
Some(_) => {
indexvec = tabkey[1].split(&['[', ']'][..]).collect();
tabkey[1] = indexvec.remove(0);
if ! indexvec.is_empty() {
let istr = indexvec.remove(0);
match usize::from_str(istr) {
Ok(i) => index = i,
Err(_) => {
eprintln!("{}: {}: Cannot index by given value.", argv0, istr);
process::exit(65); // sysexits(3) EX_DATAERR
},
};
}
},
None => {},
};
let mut root = content.parse::<Value>().unwrap();