aboutsummaryrefslogtreecommitdiff
path: root/src/command
diff options
context:
space:
mode:
Diffstat (limited to 'src/command')
-rw-r--r--src/command/add_remote.rs6
-rw-r--r--src/command/remove_remote.rs7
-rw-r--r--src/command/sync_down.rs16
-rw-r--r--src/command/sync_up.rs6
4 files changed, 12 insertions, 23 deletions
diff --git a/src/command/add_remote.rs b/src/command/add_remote.rs
index ad7be83..040e572 100644
--- a/src/command/add_remote.rs
+++ b/src/command/add_remote.rs
@@ -1,6 +1,6 @@
-use std::fs::{create_dir_all, write};
use std::io::Result;
use crate::configuration::Configuration;
+use crate::remote::add;
pub struct AddRemote;
@@ -16,10 +16,8 @@ impl super::Command for AddRemote {
}
fn execute(&self, input: Option<&String>, configuration: &Configuration, _: &String) -> Result<()> {
- create_dir_all(&configuration.config_directory)?;
let input = input.expect("You must provide a location for the remote.");
- write(&configuration.remote_config, input)?;
- return Ok(())
+ add(&configuration.config_directory, &configuration.remote_config, input)
}
fn after_dependencies(&self) -> Vec<Box<dyn super::Command>> {
diff --git a/src/command/remove_remote.rs b/src/command/remove_remote.rs
index b2f554c..7590487 100644
--- a/src/command/remove_remote.rs
+++ b/src/command/remove_remote.rs
@@ -1,6 +1,6 @@
-use std::fs::remove_file;
use std::io::Result;
use crate::configuration::Configuration;
+use crate::remote::remove;
pub struct RemoveRemote;
@@ -16,10 +16,7 @@ impl super::Command for RemoveRemote {
}
fn execute(&self, _: Option<&String>, configuration: &Configuration, _: &String) -> Result<()> {
- if configuration.remote_config.exists() {
- remove_file(&configuration.remote_config)?;
- }
- return Ok(())
+ remove(&configuration.remote_config)
}
fn after_dependencies(&self) -> Vec<Box<dyn super::Command>> {
diff --git a/src/command/sync_down.rs b/src/command/sync_down.rs
index dc4114e..bba34b2 100644
--- a/src/command/sync_down.rs
+++ b/src/command/sync_down.rs
@@ -1,6 +1,6 @@
-use std::fs::create_dir_all;
-use std::io::{Result, Error};
+use std::io::{Result};
use crate::configuration::Configuration;
+use crate::remote::sync_down;
pub struct SyncDown;
@@ -16,16 +16,10 @@ impl super::Command for SyncDown {
}
fn execute(&self, _: Option<&String>, configuration: &Configuration, command: &String) -> Result<()> {
- match create_dir_all(&configuration.data_directory) {
- Ok(_) => {
- // We only care to show these warnings if this is the primary command.
- if command == self.command() {
- println!("WARNING: Sync Down Not yet implemented");
- }
- return Ok(())
- },
- Err(e) => Err(Error::new(e.kind(), format!("Could not create data directory")))
+ if command == self.command() {
+ return sync_down(&configuration.data_directory, &configuration.remote_config);
}
+ return Ok(())
}
fn after_dependencies(&self) -> Vec<Box<dyn super::Command>> {
diff --git a/src/command/sync_up.rs b/src/command/sync_up.rs
index 635de10..a5d2a4c 100644
--- a/src/command/sync_up.rs
+++ b/src/command/sync_up.rs
@@ -1,5 +1,6 @@
use std::io::Result;
use crate::configuration::Configuration;
+use crate::remote::sync_up;
pub struct SyncUp;
@@ -14,9 +15,8 @@ impl super::Command for SyncUp {
vec![]
}
- fn execute(&self, input: Option<&String>, _: &Configuration, _: &String) -> Result<()> {
- println!("Sync Up: {:?}!", input);
- return Ok(())
+ fn execute(&self, _: Option<&String>, configuration: &Configuration, _: &String) -> Result<()> {
+ sync_up(&configuration.data_directory, &configuration.remote_config)
}
fn after_dependencies(&self) -> Vec<Box<dyn super::Command>> {