Fixed error handling.

Signed-off-by: Pavel Kirilin <win10@list.ru>
This commit is contained in:
2020-04-05 21:40:56 +04:00
parent 60b10d9dd0
commit 9d81cf5dc6
7 changed files with 31 additions and 7 deletions

14
Cargo.lock generated
View File

@ -37,9 +37,10 @@ dependencies = [
[[package]]
name = "awatch"
version = "0.1.0"
version = "0.3.1"
dependencies = [
"alphanumeric-sort",
"colored",
"failure",
"failure_derive",
"lazy_static",
@ -107,6 +108,17 @@ dependencies = [
"vec_map",
]
[[package]]
name = "colored"
version = "1.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4ffc801dacf156c5854b9df4f425a626539c3a6ef7893cc0c5084a23f0b6c59"
dependencies = [
"atty",
"lazy_static",
"winapi",
]
[[package]]
name = "failure"
version = "0.1.7"

View File

@ -1,6 +1,6 @@
[package]
name = "awatch"
version = "0.1.0"
version = "0.3.1"
authors = ["Pavel Kirilin <win10@list.ru>"]
edition = "2018"
@ -18,3 +18,4 @@ alphanumeric-sort = "1.0.12" # Used to search for videos.
regex = "1" # Regular expressions.
termion = "1.5.5" # For interacting with terminal.
term_grid = "0.1.7" # For showing matched files while initialization
colored = "1.9" # For terminal coloring

View File

@ -20,4 +20,6 @@ pub enum RunMode {
Next,
#[structopt(name = "update", about = "Update saved config")]
Update,
#[structopt(name = "reset", about = "Set episode to 0")]
Reset,
}

View File

@ -15,6 +15,7 @@ use structopt::StructOpt;
use crate::run_modes::run;
use crate::result::AppResult;
use colored::{Colorize, Color};
pub mod result;
pub mod config;
@ -26,6 +27,12 @@ include!("cli.rs");
fn main() -> AppResult<()> {
let opt: Opt = Opt::from_args();
run(opt)?;
if let Err(error) = run(opt) {
println!("{dashes} {title} {dashes}",
dashes = "#######".color(Color::BrightRed),
title= "Error".color(Color::BrightRed)
);
println!("{}", error);
}
Ok(())
}

View File

@ -6,7 +6,7 @@ pub enum AppError {
StdErr(String),
#[fail(display = "Config processing failed: {}", _0)]
ParseError(String),
#[fail(display = "Error was found: {}", _0)]
#[fail(display = "{}", _0)]
RuntimeError(String),
}

View File

@ -2,7 +2,7 @@ use crate::{Opt, RunMode};
use crate::result::{AppResult, AppError};
use crate::initialization::init_config;
use crate::config::{update_episode, update_config, Config};
use std::process::{Command};
use std::process::Command;
pub fn run(opts: Opt) -> AppResult<()> {
let mode = opts.mode.unwrap_or_else(|| RunMode::Play);
@ -22,6 +22,9 @@ pub fn run(opts: Opt) -> AppResult<()> {
RunMode::Update => {
update_config()
}
RunMode::Reset => {
update_episode(|_| { Ok(0) })
}
}
}

View File

@ -124,7 +124,6 @@ pub fn read_tty_line(
Key::Char(c) => {
buffer.insert(current_pos - 1, c.clone());
current_pos += 1;
println!("{:#?}", c);
}
Key::Backspace => {
if let Some(pos) = current_pos.checked_sub(2) {