Skip to content
Snippets Groups Projects
Verified Commit 9beee746 authored by nfontrod's avatar nfontrod
Browse files

add clone module

parent ab140d7d
Branches
No related tags found
No related merge requests found
use std::path::PathBuf;
use std::process::exit;
use colored::Colorize;
use crate::configt;
use crate::init;
use crate::push;
fn check_remote_dir(url: &PathBuf, adress: &str) {
if !push::check_dir_exist(url, adress) {
eprintln!("{}: {} no such directory", "error".red(), url.display());
exit(1);
}
let v = vec!["data", "config", "archive_list"];
for file in v {
let mut path = url.clone();
path.push(file);
let exists = match file {
"data" => push::check_dir_exist(&path, adress),
_ => push::check_file_exist(&path, adress),
};
if !exists {
let kind = if file == "data" { "folder" } else { "file" };
eprintln!(
"{}: no {} {} inside {} directory",
"error".red(),
file,
kind,
url.display()
);
exit(1);
}
}
}
/// Create a push the tar achive on the selected remote path
/// # Arguments
/// - `remote`: The name of a remote
pub fn clone(path: &str) -> () {
let (adress, url) = push::split_path(path);
let (borg_path, _) = init::get_borg_folder();
if borg_path.is_dir() {
eprintln!("{}: {} already exits.", "error".red(), &borg_path.display());
exit(1);
}
let borg_folder = borg_path.canonicalize().unwrap();
check_remote_dir(&url, &adress);
push::copy_file(&borg_folder, &url, &adress, "pull");
let name = url.file_name().unwrap().to_str().unwrap();
configt::create_named_local_config(name);
let gitignore = init::get_gitignore_file();
init::update_gitignore(&gitignore);
}
...@@ -6,6 +6,7 @@ use colored::Colorize; ...@@ -6,6 +6,7 @@ use colored::Colorize;
use configt::PartialPrune; use configt::PartialPrune;
mod checkout; mod checkout;
mod clean; mod clean;
mod clone;
mod commit; mod commit;
mod compact; mod compact;
mod config_structure; mod config_structure;
...@@ -123,6 +124,8 @@ enum Commands { ...@@ -123,6 +124,8 @@ enum Commands {
/// The purpose of this command is to be used if a pull command fails after /// The purpose of this command is to be used if a pull command fails after
/// removing content inside the .borg folder /// removing content inside the .borg folder
Restore, Restore,
/// Clones a repository given a destination
Clone(Clone),
} }
#[derive(Debug, Args)] #[derive(Debug, Args)]
...@@ -329,6 +332,12 @@ struct Pull { ...@@ -329,6 +332,12 @@ struct Pull {
key: String, key: String,
} }
#[derive(Debug, Args)]
struct Clone {
/// The path pointing to a borg folder
path: String,
}
fn main() { fn main() {
let args = Cli::parse(); let args = Cli::parse();
...@@ -421,5 +430,8 @@ fn main() { ...@@ -421,5 +430,8 @@ fn main() {
Commands::Restore => { Commands::Restore => {
restore::restore(); restore::restore();
} }
Commands::Clone(c) => {
clone::clone(&c.path);
}
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment