diff options
author | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-06-29 22:19:47 -0400 |
---|---|---|
committer | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-06-29 22:23:31 -0400 |
commit | 65f0f33a564d91bd8126ce684c02f245e5ea9a1f (patch) | |
tree | bc9bb5d877cee131dc7870c5f9f5d0c71898efbd /src/commands/rename_file.rs | |
parent | 58f6428e2aead58b7f930008b294ce56df59e3cb (diff) |
rework error system
- JoshutoErrorKind now envelops all possible errors by Joshuto
- JoshutoError behaves like std::io::Error
- add JoshutoResult
Diffstat (limited to 'src/commands/rename_file.rs')
-rw-r--r-- | src/commands/rename_file.rs | 29 |
1 files changed, 7 insertions, 22 deletions
diff --git a/src/commands/rename_file.rs b/src/commands/rename_file.rs index a43de07..02eadfb 100644 --- a/src/commands/rename_file.rs +++ b/src/commands/rename_file.rs @@ -2,7 +2,7 @@ use std::path; use crate::commands::{CommandLine, JoshutoCommand, JoshutoRunnable}; use crate::context::JoshutoContext; -use crate::error::JoshutoError; +use crate::error::JoshutoResult; use crate::window::JoshutoView; use rustyline::completion::{escape, Quote}; @@ -60,11 +60,7 @@ impl std::fmt::Display for RenameFile { } impl JoshutoRunnable for RenameFile { - fn execute( - &self, - context: &mut JoshutoContext, - view: &JoshutoView, - ) -> Result<(), JoshutoError> { + fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) -> JoshutoResult<()> { let mut path: Option<path::PathBuf> = None; let curr_list = &context.tabs[context.curr_tab_index].curr_list; @@ -73,10 +69,7 @@ impl JoshutoRunnable for RenameFile { } if let Some(path) = path { - match self.rename_file(&path, context, view) { - Ok(_) => {} - Err(e) => return Err(JoshutoError::IO(e)), - } + self.rename_file(&path, context, view)?; ncurses::doupdate(); } Ok(()) @@ -99,7 +92,7 @@ impl RenameFileAppend { context: &mut JoshutoContext, view: &JoshutoView, file_name: String, - ) -> Result<(), JoshutoError> { + ) -> JoshutoResult<()> { let prefix; let suffix; if let Some(ext) = file_name.rfind('.') { @@ -124,11 +117,7 @@ impl std::fmt::Display for RenameFileAppend { } impl JoshutoRunnable for RenameFileAppend { - fn execute( - &self, - context: &mut JoshutoContext, - view: &JoshutoView, - ) -> Result<(), JoshutoError> { + fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) -> JoshutoResult<()> { let curr_list = &context.tabs[context.curr_tab_index].curr_list; let file_name = match curr_list.get_curr_ref() { Some(s) => { @@ -167,7 +156,7 @@ impl RenameFilePrepend { context: &mut JoshutoContext, view: &JoshutoView, file_name: String, - ) -> Result<(), JoshutoError> { + ) -> JoshutoResult<()> { let prefix = String::from("rename "); let suffix = file_name; @@ -185,11 +174,7 @@ impl std::fmt::Display for RenameFilePrepend { } impl JoshutoRunnable for RenameFilePrepend { - fn execute( - &self, - context: &mut JoshutoContext, - view: &JoshutoView, - ) -> Result<(), JoshutoError> { + fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) -> JoshutoResult<()> { let curr_list = &context.tabs[context.curr_tab_index].curr_list; let file_name = match curr_list.get_curr_ref() { Some(s) => { |