aboutsummaryrefslogtreecommitdiff
path: root/src/command/add_remote.rs
blob: e5ca591147650c1a463d99eb39cba8b0ce8e0b4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use crate::configuration::Configuration;
use crate::remote::add;
use std::io::{Error, ErrorKind::Other, Result};

pub struct AddRemote;

impl AddRemote {
    pub fn new() -> Self {
        AddRemote
    }
}

impl super::Command for AddRemote {
    fn before_dependencies(&self) -> Vec<Box<dyn super::Command>> {
        vec![]
    }

    fn execute(
        &self,
        input: Option<&String>,
        configuration: &Configuration,
        _: &str,
    ) -> Result<()> {
        let input = input
            .ok_or_else(|| Error::new(Other, "You must provide a location for the remote."))?;
        add(
            &configuration.config_directory,
            &configuration.remote_config,
            input,
        )
    }

    fn after_dependencies(&self) -> Vec<Box<dyn super::Command>> {
        vec![]
    }

    fn command(&self) -> &'static str {
        "add-remote"
    }

    fn help(&self) -> &'static str {
        "<git_url>\t\tAdds or updates a git remote to sync with"
    }
}