diff options
Diffstat (limited to 'src/cli/cmd/edit.rs')
| -rw-r--r-- | src/cli/cmd/edit.rs | 41 |
1 files changed, 0 insertions, 41 deletions
diff --git a/src/cli/cmd/edit.rs b/src/cli/cmd/edit.rs deleted file mode 100644 index b164332..0000000 --- a/src/cli/cmd/edit.rs +++ /dev/null @@ -1,41 +0,0 @@ -//! Replace the contents of the currently edited map with contents from a file. - -use super::Command; -use super::{CmdParseError, FromArgs}; -use crate::map::MapData; -use crate::Editor; -use std::path::PathBuf; - -/// Command to load a file from the disk and replace the current editor contents with it's info. -pub struct Edit { - file: PathBuf, -} - -impl FromArgs for Edit { - fn from_args(args: &[&str]) -> Result<Self, CmdParseError> { - if args.len() != 1 { - return Err(CmdParseError::WrongNumberOfArgs(args.len(), 1..=1)); - } - - Ok(Self { - file: PathBuf::from(args[0]), - }) - } -} - -impl Command for Edit { - fn process(&self, editor: &mut Editor) -> Result<String, String> { - let data = match MapData::load_from_file(&self.file) { - Ok(data) => data, - Err(err) => { - return Err(format!( - "Unable to read file: {:?}, reason: {:?}", - &self.file, err - )) - } - }; - - editor.map_mut().set_data(data); - Ok(format!("Map data from {:?} loaded.", &self.file)) - } -} |
