Add error info to preview::extract_elements

This commit is contained in:
Csonka Mihaly 2020-03-21 01:43:11 +01:00
parent f1182279a9
commit 0a84a0a2c9
2 changed files with 6 additions and 6 deletions

View file

@ -1,16 +1,16 @@
use crate::display;
use std::error::Error;
use anyhow::Error;
use std::process;
fn extract_elements(argstr: &str) -> (&str, &str, &str) {
let mut parts = argstr.split(display::DELIMITER).skip(3);
let tags = parts.next().unwrap();
let comment = parts.next().unwrap();
let snippet = parts.next().unwrap();
let tags = parts.next().expect("No `tags` element provided.");
let comment = parts.next().expect("No `comment` element provided.");
let snippet = parts.next().expect("No `snippet` element provided.");
(tags, comment, snippet)
}
pub fn main(line: &str) -> Result<(), Box<dyn Error>> {
pub fn main(line: &str) -> Result<(), Error> {
let (tags, comment, snippet) = extract_elements(line);
display::preview(comment, tags, snippet);
process::exit(0)

View file

@ -9,7 +9,7 @@ pub fn handle_config(mut config: Config) -> Result<(), Box<dyn Error>> {
match config.cmd.as_mut() {
None => flows::core::main(Variant::Core, config, true),
Some(c) => match c {
Preview { line } => flows::preview::main(&line[..]),
Preview { line } => Ok(flows::preview::main(&line[..])?),
Query { query } => flows::query::main(query.clone(), config),
Best { query, args } => flows::best::main(query.clone(), args.to_vec(), config),
Search { query } => flows::search::main(query.clone(), config),