diff --git a/src/cmd_args.rs b/src/cmd_args.rs index d1bbaaf..80c031d 100644 --- a/src/cmd_args.rs +++ b/src/cmd_args.rs @@ -45,7 +45,10 @@ pub(crate) enum Commands { Path {}, /// Sync with git repo. - Sync {}, + Sync { + /// Remote name to sync. + remote_name: Option, + }, /// Check config files. Check {}, diff --git a/src/cmd_sync.rs b/src/cmd_sync.rs new file mode 100644 index 0000000..eb477ca --- /dev/null +++ b/src/cmd_sync.rs @@ -0,0 +1,22 @@ +use std::path::PathBuf; + +use anyhow::{anyhow, Result}; +use git2::Repository; + +pub(crate) fn cmd_sync(config_dir: &PathBuf, remote_name: Option) -> Result<()> { + warn!("Experimental"); + let repo = Repository::open(config_dir)?; + let remote_name = match remote_name { + Some(remote_name) => remote_name, + None => { + let remotes = repo.remotes()?; + if remotes.len() != 1 { + return Err(anyhow!("Please specify remote name")); + } + remotes.get(0).unwrap().to_string() + } + }; + let mut remote = repo.find_remote(&remote_name)?; + remote.push(&[] as &[&str], None)?; + Ok(()) +} diff --git a/src/main.rs b/src/main.rs index 303f66d..7309716 100644 --- a/src/main.rs +++ b/src/main.rs @@ -33,6 +33,7 @@ use devices::{Device, DEVICESFILE, *}; mod cmd_args; mod cmd_init; mod cmd_storage; +mod cmd_sync; mod devices; mod inquire_filepath_completer; mod storages; @@ -91,9 +92,7 @@ fn main() -> Result<()> { Commands::Path {} => { println!("{}", &config_dir.display()); } - Commands::Sync {} => { - unimplemented!("Sync is not implemented") - } + Commands::Sync { remote_name } => cmd_sync::cmd_sync(&config_dir, remote_name)?, Commands::Check {} => { println!("Config dir: {}", &config_dir.display()); let _storages = Storages::read(&config_dir)?;