Move repo into subfolder, ran clippy
This commit is contained in:
@@ -14,20 +14,20 @@ pub struct ModToml {
|
||||
}
|
||||
|
||||
pub fn parse() -> Result<ModToml, String> {
|
||||
let mut files: ModToml = toml::from_str(std::fs::read_to_string("mod.toml").unwrap().as_str())
|
||||
.map_err(|e| format!("Error while parsing files.toml:\n{}", e.to_string()))?;
|
||||
let mut files: ModToml = toml::from_str(std::fs::read_to_string("repo/mod.toml").unwrap().as_str())
|
||||
.map_err(|e| format!("Error while parsing files.toml:\n{}", e))?;
|
||||
|
||||
let home_path = std::env::var("HOME").unwrap();
|
||||
for (_, m) in files.modules.iter_mut() {
|
||||
m.content = m.content.iter().map(|(n, p)| (
|
||||
n.clone(),
|
||||
p.replace("~", home_path.as_str())
|
||||
p.replace('~', home_path.as_str())
|
||||
)).collect()
|
||||
}
|
||||
|
||||
let base = std::path::Path::new("repo");
|
||||
for (name, _path) in files.modules.iter().flat_map(|(_, m)| m.content.iter()) {
|
||||
let p = std::path::Path::new(name);
|
||||
if !p.exists() {
|
||||
if !base.join(name).exists() {
|
||||
return Err(format!("Missing module entry {}", name));
|
||||
}
|
||||
}
|
||||
|
||||
32
src/main.rs
32
src/main.rs
@@ -8,21 +8,21 @@ use strum::{EnumIter, IntoEnumIterator};
|
||||
|
||||
#[derive(Debug, Clone, EnumIter)]
|
||||
enum MainMenu {
|
||||
INSTALL,
|
||||
COLLECT,
|
||||
DIFF,
|
||||
UPLOAD,
|
||||
QUIT
|
||||
Install,
|
||||
Collect,
|
||||
Diff,
|
||||
Upload,
|
||||
Quit
|
||||
}
|
||||
|
||||
impl ToString for MainMenu {
|
||||
fn to_string(&self) -> String {
|
||||
match self {
|
||||
MainMenu::INSTALL => "Pull and install files",
|
||||
MainMenu::COLLECT => "Collect files",
|
||||
MainMenu::DIFF => "View git diff",
|
||||
MainMenu::UPLOAD => "(Commit) and push to git",
|
||||
MainMenu::QUIT => "Exit"
|
||||
MainMenu::Install => "Pull and install files",
|
||||
MainMenu::Collect => "Collect files",
|
||||
MainMenu::Diff => "View git diff",
|
||||
MainMenu::Upload => "(Commit) and push to git",
|
||||
MainMenu::Quit => "Exit"
|
||||
}.to_string()
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,7 @@ fn main() {
|
||||
}
|
||||
};
|
||||
|
||||
if !std::path::Path::new("mod.toml").exists() {
|
||||
if !std::path::Path::new("repo/mod.toml").exists() {
|
||||
println!("'mod.toml' doesn't exist!");
|
||||
return;
|
||||
}
|
||||
@@ -54,7 +54,7 @@ fn main() {
|
||||
'main_loop: loop {
|
||||
let res = prompt::select(Some("What do you want to do?"), MainMenu::iter().collect());
|
||||
match res {
|
||||
MainMenu::INSTALL => {
|
||||
MainMenu::Install => {
|
||||
if let Err(err) = repository::pull_repo(&repo) {
|
||||
println!("Failed to pull repo!");
|
||||
println!("{}", err);
|
||||
@@ -62,10 +62,10 @@ fn main() {
|
||||
}
|
||||
operations::install(&mods);
|
||||
},
|
||||
MainMenu::COLLECT => operations::collect(&mods),
|
||||
MainMenu::DIFF => { std::process::Command::new("git").arg("diff").spawn().unwrap().wait().unwrap(); },
|
||||
MainMenu::UPLOAD => operations::upload(&repo),
|
||||
MainMenu::QUIT => break 'main_loop
|
||||
MainMenu::Collect => operations::collect(&mods),
|
||||
MainMenu::Diff => { std::process::Command::new("git").arg("diff").current_dir("repo").spawn().unwrap().wait().unwrap(); },
|
||||
MainMenu::Upload => operations::upload(&repo),
|
||||
MainMenu::Quit => break 'main_loop
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ impl ToString for NamedModule {
|
||||
fn install_mod(m: NamedModule) {
|
||||
let spinner = indicatif::ProgressBar::new_spinner().with_message(format!("Installing module {}...", m.0));
|
||||
'content_iter: for entry in m.1.content {
|
||||
let src = std::path::Path::new(entry.0.as_str());
|
||||
let src = std::path::Path::new("repo").join(&entry.0);
|
||||
if src.is_file() {
|
||||
if let Err(err) = std::fs::copy(src, entry.1) {
|
||||
println!("Failed to copy {}:\n{}", entry.0, err);
|
||||
@@ -40,7 +40,7 @@ fn install_mod(m: NamedModule) {
|
||||
let _ = std::fs::remove_dir(dir);
|
||||
spinner.tick();
|
||||
}
|
||||
if let Err(err) = crate::utils::copy_dir(src, dst, &spinner) {
|
||||
if let Err(err) = crate::utils::copy_dir(&src, dst, &spinner) {
|
||||
println!("Failed to copy directory:\n{}", err);
|
||||
}
|
||||
}
|
||||
@@ -50,7 +50,7 @@ fn install_mod(m: NamedModule) {
|
||||
fn collect_mod(m: NamedModule) {
|
||||
let spinner = indicatif::ProgressBar::new_spinner().with_message(format!("Collecting module {}...", m.0));
|
||||
'content_iter: for entry in m.1.content {
|
||||
let dst = std::path::Path::new(entry.0.as_str());
|
||||
let dst = std::path::Path::new("repo").join(entry.0.as_str());
|
||||
let src = std::path::Path::new(entry.1.as_str());
|
||||
if src.is_file() {
|
||||
if let Err(err) = std::fs::copy(src, dst) {
|
||||
@@ -58,8 +58,8 @@ fn collect_mod(m: NamedModule) {
|
||||
}
|
||||
spinner.tick();
|
||||
} else {
|
||||
let _ = std::fs::remove_dir_all(dst);
|
||||
if let Err(err) = std::fs::create_dir_all(dst) {
|
||||
let _ = std::fs::remove_dir_all(&dst);
|
||||
if let Err(err) = std::fs::create_dir_all(&dst) {
|
||||
println!("Failed to create directory {}:\n{}", entry.0, err);
|
||||
continue 'content_iter;
|
||||
}
|
||||
@@ -70,7 +70,7 @@ fn collect_mod(m: NamedModule) {
|
||||
};
|
||||
|
||||
for dir in to_copy.directories {
|
||||
std::fs::create_dir_all(dst.join(&dir)).unwrap();
|
||||
std::fs::create_dir_all(dst.join(dir)).unwrap();
|
||||
spinner.tick();
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ fn generate_callbacks(use_ssh_agent: bool, pb: &mut indicatif::ProgressBar) -> g
|
||||
callbacks.credentials(|_, username, _| git2::Cred::ssh_key(
|
||||
username.unwrap(),
|
||||
None,
|
||||
Path::new(&format!("{}/.ssh/id_rsa", std::env::var("HOME").unwrap_or(String::new()))),
|
||||
Path::new(&format!("{}/.ssh/id_rsa", std::env::var("HOME").unwrap_or_default())),
|
||||
None
|
||||
));
|
||||
}
|
||||
@@ -44,7 +44,7 @@ fn _clone_repo(callbacks: git2::RemoteCallbacks) -> Result<Repository, git2::Err
|
||||
|
||||
builder.clone(
|
||||
"git@ssh.gitlab.mattv.de:root/dotfiles.git",
|
||||
Path::new(".")
|
||||
Path::new("repo")
|
||||
)
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ pub fn push_repo(repo: &Repository) -> Result<(), git2::Error> {
|
||||
}
|
||||
|
||||
pub fn open_repo() -> Result<Repository, String> {
|
||||
Repository::open(".")
|
||||
Repository::open("repo")
|
||||
.or_else(|_| clone_repo())
|
||||
.map_err(|e| e.message().to_string())
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use fs_extra::dir::DirContent;
|
||||
|
||||
pub fn get_dir_content_filtered(p: &std::path::Path, ignored: &Vec<String>) -> Result<DirContent, String> {
|
||||
pub fn get_dir_content_filtered(p: &std::path::Path, ignored: &[String]) -> Result<DirContent, String> {
|
||||
let p = p.canonicalize().map_err(|e| e.to_string())?;
|
||||
let base_path_len = p.to_str().unwrap().len() + 1;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user