]> git.r.bdr.sh - rbdr/blog/blob - src/command/add_remote.rs
ad7be83db4b4c41ef0109f25256cf4d2708534e7
[rbdr/blog] / src / command / add_remote.rs
1 use std::fs::{create_dir_all, write};
2 use std::io::Result;
3 use crate::configuration::Configuration;
4
5 pub struct AddRemote;
6
7 impl AddRemote {
8 pub fn new() -> Self {
9 AddRemote
10 }
11 }
12
13 impl super::Command for AddRemote {
14 fn before_dependencies(&self) -> Vec<Box<dyn super::Command>> {
15 vec![]
16 }
17
18 fn execute(&self, input: Option<&String>, configuration: &Configuration, _: &String) -> Result<()> {
19 create_dir_all(&configuration.config_directory)?;
20 let input = input.expect("You must provide a location for the remote.");
21 write(&configuration.remote_config, input)?;
22 return Ok(())
23 }
24
25 fn after_dependencies(&self) -> Vec<Box<dyn super::Command>> {
26 vec![]
27 }
28
29 fn command(&self) -> &'static str {
30 "add-remote"
31 }
32
33 fn help(&self) -> &'static str {
34 "<git_url>\t\tAdds or updates a git remote to sync with"
35 }
36 }