]> git.r.bdr.sh - rbdr/blog/commitdiff
Add remote management
authorRuben Beltran del Rio <redacted>
Fri, 8 Mar 2024 23:48:11 +0000 (00:48 +0100)
committerRuben Beltran del Rio <redacted>
Fri, 8 Mar 2024 23:48:11 +0000 (00:48 +0100)
src/command/add_remote.rs
src/command/remove_remote.rs

index c98330fbf7d94fdeae7c64abb841b56c1d5f4c13..ad7be83db4b4c41ef0109f25256cf4d2708534e7 100644 (file)
@@ -1,3 +1,4 @@
+use std::fs::{create_dir_all, write};
 use std::io::Result;
 use crate::configuration::Configuration;
 
@@ -14,8 +15,10 @@ impl super::Command for AddRemote {
         vec![]
     }
 
-    fn execute(&self, input: Option<&String>, _: &Configuration, _: &String) -> Result<()> {
-        println!("Add Remote: {:?}!", input);
+    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(())
     }
 
index 8188beb5c7991391c85cea7a4cf3430ac234938c..b2f554cc2a7e0427adc53f1e8d9c656d540734a0 100644 (file)
@@ -1,3 +1,4 @@
+use std::fs::remove_file;
 use std::io::Result;
 use crate::configuration::Configuration;
 
@@ -14,8 +15,10 @@ impl super::Command for RemoveRemote {
         vec![]
     }
 
-    fn execute(&self, input: Option<&String>, _: &Configuration, _: &String) -> Result<()> {
-        println!("Remove Remote: {:?}!", input);
+    fn execute(&self, _: Option<&String>, configuration: &Configuration, _: &String) -> Result<()> {
+        if configuration.remote_config.exists() {
+            remove_file(&configuration.remote_config)?;
+        }
         return Ok(())
     }