Skip to content

Commit

Permalink
git config
Browse files Browse the repository at this point in the history
  • Loading branch information
Cedric-talentnet committed Mar 9, 2021
1 parent b913a25 commit fa89146
Show file tree
Hide file tree
Showing 10 changed files with 333 additions and 4 deletions.
125 changes: 125 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ edition = "2018"
structopt = "0.3.15"
serde_yaml = "0.8.17"
serde = { version = "1.0.124", features = ["derive"] }
dirs = "3.0.1"
1 change: 1 addition & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ environment:
GITHUB_TOKEN: qwe
files:
- ~/.config/Code/User/settings.json
- ~/.config/tilix/bookmarks.json

89 changes: 89 additions & 0 deletions src/cli/arguments.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
use structopt::StructOpt;

#[derive(StructOpt)]
#[derive(Debug)]
#[structopt(about = "Backup/Restore tool")]
pub enum Cli {
#[structopt(about = "Configuration file")]
Config {
#[structopt(short = "e", long = "--path", help = "Path", default_value = "config.yaml")]
path: String,
},
#[structopt(about = "Backup configuration from local computer")]
Backup {
#[structopt(short = "e", long = "--path", help = "Path", default_value = "config.yaml")]
path: String,
},
#[structopt(about = "Restore configuration on local computer")]
Restore {
#[structopt(short = "e", long = "--path", help = "Path", default_value = "config.yaml")]
path: String,
}
}


use std::time::{SystemTime, UNIX_EPOCH};
use std::fs;
use std::os::unix::prelude::*;
use crate::settings;
use std::path::Path;

pub fn get_args() -> () {
match Cli::from_args() {
Cli::Config { path } => {
println!("{:?}", path)
},
Cli::Backup { path } => {
let duration = SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("Error occurred");
let time = duration.as_secs() * 1000 +
duration.subsec_nanos() as u64 / 1_000_000;
let backup_path = format!("/tmp/{}", time);
let config = settings::config::get_config();

// for origin in config.files {
// let file_name = Path::new(&origin).file_name().unwrap().to_str().unwrap(); // settings.json
// let file_path = &origin.replace(file_name, ""); // ~/.config/Code/User/
// let full_folder_path = format!("{}/{}", backup_path, file_path); // /tmp/1615323956137/~/.config/Code/User/
// let full_file_path = format!("{}{}", full_folder_path, file_name); // /tmp/1615323956137/~/.config/Code/User/settings.json

// let mut resolved_path: String = file_path.to_string(); // /home/username/.config/Code/User/
// if file_path.starts_with("~") {
// resolved_path.remove(0);
// resolved_path = get_home() + &resolved_path
// }
// resolved_path += file_name; // /home/username/.config/Code/User/settings.json

// fs::create_dir_all(full_folder_path).expect("Error when creating folder");
// fs::copy(resolved_path, full_file_path).expect("Error when copying file");
// }
// println!("{:?}", time);


println!("{:?}", config.git_repo);


// fs::remove_dir_all(backup_path).expect("Error when deleting folder");
// println!("{:#?}", config.files);
}
_ => (),
}
}

fn get_home() -> std::string::String {
match dirs::home_dir() {
Some(path) => return path.display().to_string(),
None => return "Impossible to get your home dir!".to_string(),
};
}


// try {
// fs.mkdirSync(DestinationFolder, { recursive: true } );
// } catch (e) {
// console.log('Cannot create folder ', e);
// }
// fs.writeFile(path.join(DestinationFolder, fileName), 'File Content Here', (err) => {
// if (err) throw err;
// });
1 change: 1 addition & 0 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod arguments;
39 changes: 39 additions & 0 deletions src/git/command.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use std::process::Command;

pub fn init() -> () {
let mut list_dir = Command::new("git")
.arg("init")
.arg("/tmp/test")
.status()
.expect("process failed to execute");
}

pub fn add() -> () {
let mut list_dir = Command::new("git")
.arg("-C")
.arg("/tmp/test")
.arg("add")
.arg(".")
.status()
.expect("process failed to execute");
}

pub fn commit() -> () {
let mut list_dir = Command::new("git")
.arg("-C")
.arg("/tmp/test")
.arg("commit")
.arg("-m")
.arg("test")
.status()
.expect("process failed to execute");
}

pub fn push() -> () {
let mut list_dir = Command::new("git")
.arg("-C")
.arg("/tmp/test")
.arg("push")
.status()
.expect("process failed to execute");
}
1 change: 1 addition & 0 deletions src/git/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod command;
9 changes: 5 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
mod arguments;
// mod config;
mod cli;
mod settings;
// mod git;

fn main() {
let args = arguments::get_args();
let args = cli::arguments::get_args();
// println!("{:?}", args);


// let config = config::get_config();
// let config = settings::config::get_config();

// println!("{:#?}", config);
// config::create_config();
Expand Down
Loading

0 comments on commit fa89146

Please sign in to comment.