summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenrique Alves <henriquelalves@gmail.com>2022-08-16 21:52:11 -0300
committerHenrique Alves <henriquelalves@gmail.com>2022-08-16 21:52:11 -0300
commit7dff0dcc148362117a4b4e6110421cd26880440c (patch)
tree3a891e4b1ba48aac2499a20786d189abb94a5a14
parent0f75eec7337012dacfa627952fe3785cf0589151 (diff)
downloadglam-7dff0dcc148362117a4b4e6110421cd26880440c.tar.gz
glam-7dff0dcc148362117a4b4e6110421cd26880440c.tar.bz2
glam-7dff0dcc148362117a4b4e6110421cd26880440c.zip
Fix addon with different name than gitrepo (only allowing one addon per glam package for now)
-rw-r--r--src/commands.rs38
-rw-r--r--src/main.rs11
2 files changed, 38 insertions, 11 deletions
diff --git a/src/commands.rs b/src/commands.rs
index 3777c7a..9b7a9aa 100644
--- a/src/commands.rs
+++ b/src/commands.rs
@@ -92,8 +92,6 @@ pub fn install_package(root : &str, git_repo : &str, commit : &str, copy_files :
let mut glam_packages = glam_object.packages;
let name = utils::get_repo_name(git_repo);
- let source_folder = format!("addons/{}", name);
- let target_folder = format!("addons/{}", name);
let mut package_index = find_package(&glam_packages, &name);
match package_index {
@@ -102,8 +100,8 @@ pub fn install_package(root : &str, git_repo : &str, commit : &str, copy_files :
name,
git_repo : git_repo.to_string(),
commit: "".to_string(),
- target_folder,
- source_folder
+ target_folder: "".to_string(),
+ source_folder: "".to_string()
});
package_index = Some(glam_packages.len() - 1);
@@ -115,7 +113,6 @@ pub fn install_package(root : &str, git_repo : &str, commit : &str, copy_files :
let package_index = package_index.unwrap();
let target_package = &mut glam_packages[package_index];
-
clone_or_fetch_package(root, target_package, verbose);
// Update package folder to commit hash
@@ -259,12 +256,25 @@ fn install_glam_package(root : &str, commit : &str, package : &mut GlamPackage,
package.commit = commit.to_string();
}
+ // TODO Get all folders on addon
+ let res = utils::run_shell_command(
+ &format!("ls .glam.d/{}/addons", package.name),
+ &root,
+ verbose);
+
+ if res.is_err() {
+ utils::log_error("Couldn't get addon name.");
+ exit(1);
+ }
+
+ let addon_folder = res.unwrap().trim().to_string();
+
if package.source_folder == "" {
- package.source_folder = format!("addons/{}", package.name);
+ package.source_folder = format!("addons/{}", addon_folder);
}
if package.target_folder == "" {
- package.target_folder = format!("addons/{}", package.name);
+ package.target_folder = format!("addons/{}", addon_folder);
}
if package.commit == "" {
@@ -354,6 +364,20 @@ fn create_new_package_from_addon(root : &str, packages : &mut Vec<GlamPackage>,
}
fn apply_glam_package_files(root : &str, package : &GlamPackage, verbose : bool) {
+
+ // Overwrite source folder with target folder
+ let res = utils::run_shell_command(
+ &format!("for f in $(ls .glam.d/{}/{}); do rm -rf .glam.d/{}/{}/$f; done",
+ package.name,
+ package.source_folder,
+ package.name,
+ package.source_folder),
+ &root,
+ verbose
+ );
+
+ utils::assert_res(&res, "Couldn't remove source folder files!");
+
// Copy addon repository content to target folder
let res = utils::run_shell_command(
&format!("for f in $(ls ./{}); do cp -rf ./{}/$f ./.glam.d/{}/{}/$f; done",
diff --git a/src/main.rs b/src/main.rs
index cb399d9..0412f52 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -60,8 +60,8 @@ enum Commands {
/// Apply changes to a package
Apply {
- /// Name of the package to apply changes to
- package_name: String,
+ /// Names of the package to apply changes to
+ package_names: Vec<String>,
/// Create new package from the specified addon folder (will create a git repo)
#[clap(short, long, required = false, default_value = "")]
create_from_addon: String,
@@ -113,11 +113,14 @@ fn main() {
commands::remove_package(&root, &package_name, cli.verbose);
},
- Commands::Apply {package_name, create_from_addon} => {
+ Commands::Apply {package_names, create_from_addon} => {
let root = commands::search_project_root();
commands::check_ignores(&root);
commands::initialize_glam_files(&root);
- commands::apply_changes(&root, &package_name, &create_from_addon, cli.verbose);
+ for package_name in package_names {
+ commands::apply_changes(&root, &package_name, &create_from_addon, cli.verbose);
+ }
+
},
}
}