diff --git a/.idea/vcs.xml b/.idea/vcs.xml
index 35eb1dd..8d5a1b2 100644
--- a/.idea/vcs.xml
+++ b/.idea/vcs.xml
@@ -2,5 +2,6 @@
+
\ No newline at end of file
diff --git a/Cargo.lock b/Cargo.lock
index 492b6da..197acc2 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -55,7 +55,7 @@ dependencies = [
]
[[package]]
-name = "dotfiles_loader"
+name = "dotfiles_installer"
version = "0.1.0"
dependencies = [
"dialoguer",
diff --git a/rustfmt.toml b/rustfmt.toml
new file mode 100644
index 0000000..762dd70
--- /dev/null
+++ b/rustfmt.toml
@@ -0,0 +1,76 @@
+max_width = 120
+hard_tabs = false
+tab_spaces = 4
+newline_style = "Unix"
+indent_style = "Block"
+use_small_heuristics = "Default"
+fn_call_width = 60
+attr_fn_like_width = 70
+struct_lit_width = 18
+struct_variant_width = 35
+array_width = 60
+chain_width = 100
+single_line_if_else_max_width = 50
+wrap_comments = false
+format_code_in_doc_comments = false
+doc_comment_code_block_width = 100
+comment_width = 80
+normalize_comments = false
+normalize_doc_attributes = false
+format_strings = false
+format_macro_matchers = false
+format_macro_bodies = true
+hex_literal_case = "Preserve"
+empty_item_single_line = true
+struct_lit_single_line = true
+fn_single_line = true
+where_single_line = true
+imports_indent = "Block"
+imports_layout = "HorizontalVertical"
+imports_granularity = "Crate"
+group_imports = "StdExternalCrate"
+reorder_imports = true
+reorder_modules = true
+reorder_impl_items = true
+type_punctuation_density = "Wide"
+space_before_colon = false
+space_after_colon = true
+spaces_around_ranges = false
+binop_separator = "Front"
+remove_nested_parens = true
+combine_control_expr = true
+short_array_element_width_threshold = 10
+overflow_delimited_expr = true
+struct_field_align_threshold = 0
+enum_discrim_align_threshold = 0
+match_arm_blocks = false
+match_arm_leading_pipes = "Never"
+force_multiline_blocks = false
+fn_args_layout = "Tall"
+brace_style = "PreferSameLine"
+control_brace_style = "AlwaysSameLine"
+trailing_semicolon = true
+trailing_comma = "Never"
+match_block_trailing_comma = false
+blank_lines_upper_bound = 1
+blank_lines_lower_bound = 0
+edition = "2021"
+version = "Two"
+inline_attribute_width = 0
+format_generated_files = true
+merge_derives = true
+use_try_shorthand = true
+use_field_init_shorthand = true
+force_explicit_abi = true
+condense_wildcard_suffixes = false
+color = "Auto"
+required_version = "1.5.1"
+unstable_features = false
+disable_all_formatting = false
+skip_children = false
+hide_parse_errors = false
+error_on_line_overflow = false
+error_on_unformatted = false
+ignore = []
+emit_mode = "Files"
+make_backup = false
diff --git a/src/config.rs b/src/config.rs
index 690467d..f2f3254 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -14,20 +14,20 @@ pub struct ModToml {
}
pub fn parse() -> Result {
- 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));
}
}
diff --git a/src/main.rs b/src/main.rs
index caed001..8939a4e 100644
--- a/src/main.rs
+++ b/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
}
}
}
diff --git a/src/operations.rs b/src/operations.rs
index 9defd38..6a46ac9 100644
--- a/src/operations.rs
+++ b/src/operations.rs
@@ -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();
}
diff --git a/src/repository.rs b/src/repository.rs
index fdc159b..444407a 100644
--- a/src/repository.rs
+++ b/src/repository.rs
@@ -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 Result<(), git2::Error> {
}
pub fn open_repo() -> Result {
- Repository::open(".")
+ Repository::open("repo")
.or_else(|_| clone_repo())
.map_err(|e| e.message().to_string())
}
diff --git a/src/utils.rs b/src/utils.rs
index 594b360..aab82ac 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -1,6 +1,6 @@
use fs_extra::dir::DirContent;
-pub fn get_dir_content_filtered(p: &std::path::Path, ignored: &Vec) -> Result {
+pub fn get_dir_content_filtered(p: &std::path::Path, ignored: &[String]) -> Result {
let p = p.canonicalize().map_err(|e| e.to_string())?;
let base_path_len = p.to_str().unwrap().len() + 1;