Skip to content
Snippets Groups Projects
Commit bccdc777 authored by nfontrod's avatar nfontrod
Browse files

initial code commit

parent 27e8f568
Branches
No related tags found
No related merge requests found
use std::path::PathBuf;
use std::process::{exit, Command};
/// Function used to get git folder
pub fn get_borg_folder() -> (PathBuf, PathBuf) {
let output = Command::new("git")
.arg("rev-parse")
.arg("--show-cdup")
.output()
.unwrap();
match output.status.code().unwrap() {
128 => {
eprintln!("Not a git repository !");
exit(128);
}
127 => {
eprintln!("Git not found !");
exit(127);
}
0 => (),
num => {
eprintln!("{}", String::from_utf8(output.stderr).unwrap());
exit(num)
}
}
let mut string_path = String::from_utf8(output.stdout).unwrap();
if string_path.ends_with('\n') {
string_path.pop();
}
let mut p = PathBuf::from(&string_path);
let mut results = p.clone();
p.push(".borg");
results.push("results");
(p, results)
}
/// Creation of a borg repository in the same directory as the .git repository
pub fn init_repository() {
let (borg_path, results) = get_borg_folder();
if !results.is_dir() {
eprintln!("{} not found !", results.to_str().unwrap());
exit(1);
}
let output = Command::new("borg")
.arg("init")
.arg("--encryption=none")
.arg(&borg_path)
.output()
.unwrap();
match output.status.code().unwrap() {
128 => {
eprintln!("borg not found !");
exit(128)
}
0 => {
println!(
"borg repository initialised at {}",
borg_path.to_str().unwrap()
);
}
num => {
eprintln!("{}", String::from_utf8(output.stderr).unwrap());
exit(num);
}
}
}
use clap::{Parser, Subcommand};
mod init;
#[derive(Debug, Parser)]
#[clap(name = "gbl")]
/// A tool used to link borg and git together
///
/// This tool was created to link borg and git together and ease the management of developpment artifact versionning using git
struct Cli {
#[clap(subcommand)]
commands: Commands,
}
#[derive(Debug, Subcommand)]
enum Commands {
/// Initialize a borg repository inside a git project
Init,
}
fn main() {
let args = Cli::parse();
match args.commands {
Commands::Init => {
init::init_repository();
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment