diff options
author | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2020-09-19 21:21:33 -0400 |
---|---|---|
committer | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2020-09-19 21:21:33 -0400 |
commit | 7b4c611ed4d804bd52aeda0a619a54bea9b1e13d (patch) | |
tree | 7ba31fff7d5de171aadfc32c67f81dd64428b3ba /src/commands/new_directory.rs | |
parent | 7741d4d2c8798ad0bb609e97fb3bda86c5318a36 (diff) |
Change command to use an enum instead of polymorphism
Diffstat (limited to 'src/commands/new_directory.rs')
-rw-r--r-- | src/commands/new_directory.rs | 44 |
1 files changed, 8 insertions, 36 deletions
diff --git a/src/commands/new_directory.rs b/src/commands/new_directory.rs index b2372ae..2c5fd57 100644 --- a/src/commands/new_directory.rs +++ b/src/commands/new_directory.rs @@ -1,45 +1,17 @@ use std::path; -use crate::commands::{JoshutoCommand, JoshutoRunnable}; use crate::context::JoshutoContext; use crate::error::JoshutoResult; use crate::history::DirectoryHistory; -use crate::ui::TuiBackend; use crate::util::load_child::LoadChild; -#[derive(Clone, Debug)] -pub struct NewDirectory { - path: path::PathBuf, -} - -impl NewDirectory { - pub fn new(path: path::PathBuf) -> Self { - NewDirectory { path } - } - pub const fn command() -> &'static str { - "mkdir" - } -} - -impl JoshutoCommand for NewDirectory {} - -impl std::fmt::Display for NewDirectory { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - f.write_str(Self::command()) - } -} - -impl JoshutoRunnable for NewDirectory { - fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> { - std::fs::create_dir_all(&self.path)?; - - let options = context.config_t.sort_option.clone(); - let curr_path = context.tab_context_ref().curr_tab_ref().pwd().to_path_buf(); - for tab in context.tab_context_mut().iter_mut() { - tab.history_mut().reload(&curr_path, &options)?; - } - - LoadChild::load_child(context)?; - Ok(()) +pub fn new_directory(context: &mut JoshutoContext, p: &path::Path) -> JoshutoResult<()> { + std::fs::create_dir_all(p)?; + let options = context.config_t.sort_option.clone(); + let curr_path = context.tab_context_ref().curr_tab_ref().pwd().to_path_buf(); + for tab in context.tab_context_mut().iter_mut() { + tab.history_mut().reload(&curr_path, &options)?; } + LoadChild::load_child(context)?; + Ok(()) } |