summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenrique Alves <henriquelalves@gmail.com>2023-05-23 13:06:23 -0300
committerHenrique Alves <henriquelalves@gmail.com>2023-05-23 13:06:23 -0300
commitd91ae1b81bd8b076b74146c4c9a57184de87029e (patch)
tree9bf426b5fb464b76e34ca5b46ad7adc7a6d4efc5
parent1343fefb5ea5ae70307d361dac514e35ffd8bdfa (diff)
downloadglam-d91ae1b81bd8b076b74146c4c9a57184de87029e.tar.gz
glam-d91ae1b81bd8b076b74146c4c9a57184de87029e.tar.bz2
glam-d91ae1b81bd8b076b74146c4c9a57184de87029e.zip
Add addon selection when importing repository
-rw-r--r--.gitignore1
-rw-r--r--src/commands.rs46
2 files changed, 35 insertions, 12 deletions
diff --git a/.gitignore b/.gitignore
index a5e8417..5f39006 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,7 @@
# Emacs stuff
**/*~
**/#*#
+project.org
# Generated by Cargo
# will have compiled files and executables
diff --git a/src/commands.rs b/src/commands.rs
index 42909a4..65032bf 100644
--- a/src/commands.rs
+++ b/src/commands.rs
@@ -1,5 +1,4 @@
-use inquire::Select;
-use inquire::Text;
+use inquire::{Select, Text, MultiSelect};
use serde::{Deserialize, Serialize};
use std::fs;
use std::fs::write;
@@ -186,7 +185,6 @@ pub fn add_repository(root: &str, git_repo: &str, verbose: bool) {
clone_or_fetch_package(root, target_package, verbose);
install_glam_package(root, &commit, target_package, false, true, verbose);
- // Write .glam file
glam_object.packages = glam_packages;
write_glam_file(&glam_file_path, &glam_object);
}
@@ -205,6 +203,11 @@ pub fn update_repository(root: &str, verbose: bool) {
.map(|x| -> &str { &x.name })
.collect::<Vec<&str>>();
+ if options.len() == 0 {
+ utils::log_error("No repository to update!");
+ exit(1);
+ }
+
let ans = Select::new("Which addon you want to update?", options)
.prompt()
.unwrap();
@@ -312,15 +315,36 @@ fn install_glam_package(
exit(1);
}
- let addon_folder = res.unwrap().trim().to_string();
-
if package.links.is_empty() {
- package.links.push(
- Link {
- target_folder: format!("addons/{}", addon_folder),
- source_folder: format!("addons/{}", addon_folder),
+ let addon_folders = res.unwrap().trim().to_string();
+ let folders = addon_folders.split("\n").collect::<Vec<&str>>();
+
+ if folders.len() == 1 {
+ package.links.push(
+ Link {
+ target_folder: format!("addons/{}", folders[0]),
+ source_folder: format!("addons/{}", folders[0]),
+ }
+ );
+ } else {
+ let ans = MultiSelect::new("Which addons you'd like to import?", folders)
+ .prompt()
+ .unwrap();
+
+ if ans.len() == 0 {
+ utils::log_error("No addon selected!");
+ exit(0);
}
- );
+
+ for folder in ans {
+ package.links.push(
+ Link {
+ target_folder: format!("addons/{}", folder),
+ source_folder: format!("addons/{}", folder),
+ }
+ );
+ }
+ }
}
if package.commit == "latest" {
@@ -422,7 +446,6 @@ fn clone_or_fetch_package(root: &str, package: &mut GlamPackage, verbose: bool)
);
utils::assert_result(&res, "Couldn't clone repository!");
-
utils::log_check("Created package folder on .glam.d");
} else {
if package.git_repo == "" {
@@ -449,7 +472,6 @@ fn clone_or_fetch_package(root: &str, package: &mut GlamPackage, verbose: bool)
verbose,
);
utils::assert_result(&res, "Couldn't fetch package repository updates!");
-
utils::log_info("Glam package folder already exists, fetched and pulled latest changes");
}
}