Fix 907 and improve substring

This commit is contained in:
Jonathan Turner 2019-11-03 07:49:28 +13:00
parent 51879d022e
commit f589d3c795
2 changed files with 10 additions and 15 deletions

View File

@ -10,7 +10,6 @@ pub struct Get;
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct GetArgs { pub struct GetArgs {
member: ColumnPath, member: ColumnPath,
rest: Vec<ColumnPath>,
} }
impl WholeStreamCommand for Get { impl WholeStreamCommand for Get {
@ -118,13 +117,10 @@ pub fn get_column_path(
} }
pub fn get( pub fn get(
GetArgs { GetArgs { member }: GetArgs,
member,
rest: fields,
}: GetArgs,
RunnableContext { input, .. }: RunnableContext, RunnableContext { input, .. }: RunnableContext,
) -> Result<OutputStream, ShellError> { ) -> Result<OutputStream, ShellError> {
trace!("get {:?} {:?}", member, fields); trace!("get {:?}", member);
let stream = input let stream = input
.values .values
@ -133,12 +129,7 @@ pub fn get(
let member = vec![member.clone()]; let member = vec![member.clone()];
let column_paths = vec![&member, &fields] for path in member {
.into_iter()
.flatten()
.collect::<Vec<&ColumnPath>>();
for path in column_paths {
let res = get_column_path(&path, &item); let res = get_column_path(&path, &item);
match res { match res {

View File

@ -41,9 +41,13 @@ impl Str {
if start > input.len() - 1 { if start > input.len() - 1 {
Value::string("") Value::string("")
} else { } else {
// Index operator isn't perfect: Value::string(
// https://users.rust-lang.org/t/how-to-get-a-substring-of-a-string/1351 &input
Value::string(&input[start..end]) .chars()
.skip(start)
.take(end - start)
.collect::<String>(),
)
} }
} }
Some(Action::ToInteger) => match input.trim() { Some(Action::ToInteger) => match input.trim() {