diff options
| author | Arne Dußin | 2021-01-27 14:01:50 +0100 |
|---|---|---|
| committer | Arne Dußin | 2021-02-02 22:16:15 +0100 |
| commit | f92e9f6f07b1e3834c2ca58ce3510734819d08e4 (patch) | |
| tree | 20e3d3afce342a56ae98f6c20491482ccd2b5c6b /src/cli/cmd/write.rs | |
| parent | c60a6d07efb120724b308e29e8e70f27c87c952d (diff) | |
| download | graf_karto-f92e9f6f07b1e3834c2ca58ce3510734819d08e4.tar.gz graf_karto-f92e9f6f07b1e3834c2ca58ce3510734819d08e4.zip | |
Rework graf karto to fit the client/server structure
Diffstat (limited to 'src/cli/cmd/write.rs')
| -rw-r--r-- | src/cli/cmd/write.rs | 42 |
1 files changed, 0 insertions, 42 deletions
diff --git a/src/cli/cmd/write.rs b/src/cli/cmd/write.rs deleted file mode 100644 index 399045c..0000000 --- a/src/cli/cmd/write.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 Write { - destination: PathBuf, -} - -impl FromArgs for Write { - fn from_args(args: &[&str]) -> Result<Self, CmdParseError> { - 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<String, String> { - 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 - )), - } - } -} |
