summaryrefslogtreecommitdiffstats
path: root/src/commands/new_directory.rs
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2019-04-24 22:36:09 -0400
committerJiayi Zhao <jeff.no.zhao@gmail.com>2019-04-24 23:15:13 -0400
commit2be79f4cd0ee0e89c5cadf5121a8b979391d0d51 (patch)
treeadbd77abb51ea2a4613c78d210896f1ed55b4498 /src/commands/new_directory.rs
parentc3919c91a866a7fd520d7dcb8b99c7d4aafbbb93 (diff)
major refactoring
- removed parent_list from JoshutoTab struct - parent_list will behave much like previewing now where the contents will be retrieved from the dictionary - completely remove DirHistory struct in favour of trait implemenation on top of HashMap
Diffstat (limited to 'src/commands/new_directory.rs')
-rw-r--r--src/commands/new_directory.rs46
1 files changed, 24 insertions, 22 deletions
diff --git a/src/commands/new_directory.rs b/src/commands/new_directory.rs
index f8df3b1..624aa90 100644
--- a/src/commands/new_directory.rs
+++ b/src/commands/new_directory.rs
@@ -17,22 +17,8 @@ impl NewDirectory {
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,
- view: &JoshutoView,
- ) -> Result<(), JoshutoError> {
+ fn new_directory(context: &mut JoshutoContext, view: &JoshutoView) -> Result<(), std::io::Error> {
let (term_rows, term_cols) = ui::getmaxyx();
const PROMPT: &str = ":mkdir ";
@@ -49,15 +35,31 @@ impl JoshutoRunnable for NewDirectory {
if let Some(user_input) = user_input {
let path = path::PathBuf::from(user_input);
- match std::fs::create_dir_all(&path) {
- Ok(_) => match ReloadDirList::reload(context, view) {
- Ok(_) => {}
- Err(e) => return Err(JoshutoError::IO(e)),
- },
- Err(e) => return Err(JoshutoError::IO(e)),
- };
+ std::fs::create_dir_all(&path)?;
+ ReloadDirList::reload(context, view)?;
}
ncurses::doupdate();
Ok(())
}
}
+
+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,
+ view: &JoshutoView,
+ ) -> Result<(), JoshutoError> {
+ match Self::new_directory(context, view) {
+ Ok(_) => Ok(()),
+ Err(e) => Err(JoshutoError::IO(e)),
+ }
+ }
+}