From 60327dd3ef85a263173e6275cb122c9191c030fe Mon Sep 17 00:00:00 2001 From: Arne Dußin Date: Fri, 8 Jan 2021 15:57:52 +0100 Subject: Rename save to write for vim mnemonics compatibility --- src/cli/cmd/mod.rs | 6 +++--- src/cli/cmd/save.rs | 42 ------------------------------------------ src/cli/cmd/write.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 45 deletions(-) delete mode 100644 src/cli/cmd/save.rs create mode 100644 src/cli/cmd/write.rs (limited to 'src') diff --git a/src/cli/cmd/mod.rs b/src/cli/cmd/mod.rs index 42e865a..e00b895 100644 --- a/src/cli/cmd/mod.rs +++ b/src/cli/cmd/mod.rs @@ -2,11 +2,11 @@ pub mod edit; pub mod read; -pub mod save; +pub mod write; pub use edit::*; pub use read::*; -pub use save::*; +pub use write::*; use crate::Editor; use std::ops::RangeInclusive; @@ -35,7 +35,7 @@ pub fn parse_command(string: &str) -> Result, CmdParseError> { let parts: Vec<&str> = string.split_whitespace().collect(); match parts[0] { - "w" => Ok(Box::new(Save::from_args(&parts[1..])?)), + "w" => Ok(Box::new(Write::from_args(&parts[1..])?)), "e" => Ok(Box::new(Edit::from_args(&parts[1..])?)), "r" => Ok(Box::new(Read::from_args(&parts[1..])?)), other => Err(CmdParseError::NoSuchCmd(other.to_owned())), diff --git a/src/cli/cmd/save.rs b/src/cli/cmd/save.rs deleted file mode 100644 index 2c022cf..0000000 --- a/src/cli/cmd/save.rs +++ /dev/null @@ -1,42 +0,0 @@ -//! Save the contents of the map to disk - -use super::Command; -use super::{CmdParseError, FromArgs}; -use crate::map::MapData; -use crate::Editor; -use std::path::PathBuf; - -/// The save command can take any destination in the filesystem the user can write to. Processing -/// will then save the map contents to that destination, overwriting anything that may be there. -pub struct Save { - destination: PathBuf, -} - -impl FromArgs for Save { - fn from_args(args: &[&str]) -> Result { - if args.len() != 1 { - return Err(CmdParseError::WrongNumberOfArgs(args.len(), 1..=1)); - } - - Ok(Self { - destination: PathBuf::from(args[0]), - }) - } -} - -impl Command for Save { - fn process(&self, editor: &mut Editor) -> Result { - let data = MapData::extract_data(editor.map()); - - match data.write_to_file(&self.destination) { - Ok(_) => Ok(format!( - "Successfully wrote contents to `{:?}`", - &self.destination - )), - Err(e) => Err(format!( - "Unable to write to `{:?}`. Error: {:?}", - &self.destination, e - )), - } - } -} diff --git a/src/cli/cmd/write.rs b/src/cli/cmd/write.rs new file mode 100644 index 0000000..399045c --- /dev/null +++ b/src/cli/cmd/write.rs @@ -0,0 +1,42 @@ +//! Save the contents of the map to disk + +use super::Command; +use super::{CmdParseError, FromArgs}; +use crate::map::MapData; +use crate::Editor; +use std::path::PathBuf; + +/// The save command can take any destination in the filesystem the user can write to. Processing +/// will then save the map contents to that destination, overwriting anything that may be there. +pub struct Write { + destination: PathBuf, +} + +impl FromArgs for Write { + fn from_args(args: &[&str]) -> Result { + if args.len() != 1 { + return Err(CmdParseError::WrongNumberOfArgs(args.len(), 1..=1)); + } + + Ok(Self { + destination: PathBuf::from(args[0]), + }) + } +} + +impl Command for Write { + fn process(&self, editor: &mut Editor) -> Result { + let data = MapData::extract_data(editor.map()); + + match data.write_to_file(&self.destination) { + Ok(_) => Ok(format!( + "Successfully wrote contents to `{:?}`", + &self.destination + )), + Err(e) => Err(format!( + "Unable to write to `{:?}`. Error: {:?}", + &self.destination, e + )), + } + } +} -- cgit v1.2.3-70-g09d2