diff options
author | Henrique Alves <henriquelalves@gmail.com> | 2023-04-20 13:45:18 -0300 |
---|---|---|
committer | Henrique Alves <henriquelalves@gmail.com> | 2023-04-20 13:45:18 -0300 |
commit | 620f3ac10b368f9ffe255cfe420ab0c4f6b91a58 (patch) | |
tree | 09de9ddf4fae4280fefabad3dc9c5fee5c308091 /src | |
parent | efc547719531d90b32867dda47da506441178d6e (diff) | |
download | glam-620f3ac10b368f9ffe255cfe420ab0c4f6b91a58.tar.gz glam-620f3ac10b368f9ffe255cfe420ab0c4f6b91a58.tar.bz2 glam-620f3ac10b368f9ffe255cfe420ab0c4f6b91a58.zip |
update commands
Diffstat (limited to 'src')
-rw-r--r-- | src/commands.rs | 87 | ||||
-rw-r--r-- | src/main.rs | 73 |
2 files changed, 76 insertions, 84 deletions
diff --git a/src/commands.rs b/src/commands.rs index a796762..59db30b 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -1,4 +1,5 @@ use inquire::Text; +use inquire::Select; use serde::{Deserialize, Serialize}; use std::fs; use std::fs::write; @@ -94,7 +95,7 @@ pub fn check_initialization(root: &str) -> bool { return ret; } -pub fn install_repositories(root: &str, verbose: bool, copy_files: bool) { +pub fn install_repositories(root: &str, verbose: bool) { let glam_file_path = format!("{}/.glam", root); // Find glam object or create one with default configuration @@ -105,7 +106,7 @@ pub fn install_repositories(root: &str, verbose: bool, copy_files: bool) { utils::log_info(&format!("Installing {}...", package.name)); clone_or_fetch_package(root, package, verbose); let commit = package.commit.to_string(); - install_glam_package(root, &commit, package, false, copy_files, verbose); + install_glam_package(root, &commit, package, false, true, verbose); } // Write .glam file @@ -119,31 +120,39 @@ pub fn add_repository(root: &str, git_repo: &str, verbose: bool) { let mut glam_object = read_glam_file(&glam_file_path); let mut glam_packages = glam_object.packages; - if find_package_by_repository(&glam_packages, &git_repo).is_some() { - utils::log_error("Repository already exists!"); - exit(1); - } + if find_package_by_repository(&glam_packages, &git_repo).is_some() { + utils::log_error("Repository already exists!"); + exit(1); + } let default_name: String = utils::get_repo_name(git_repo); - let inquire_name = "Name of the repository:"; - let name = Text::new(inquire_name).with_default(&default_name).with_placeholder(&default_name).prompt().unwrap(); + let inquire_name = "Name of the addon:"; + let name = Text::new(inquire_name) + .with_default(&default_name) + .with_placeholder(&default_name) + .prompt() + .unwrap(); - if find_package_by_name(&glam_packages, &name).is_some() { - utils::log_error("Repository name exists!"); - exit(1); - } + if find_package_by_name(&glam_packages, &name).is_some() { + utils::log_error("Addon name exists!"); + exit(1); + } let default_commit = "latest"; let inquire_commit = "Commit hash of the repository:"; - let commit = Text::new(inquire_commit).with_default(&default_commit).with_placeholder(&default_commit).prompt().unwrap(); + let commit = Text::new(inquire_commit) + .with_default(&default_commit) + .with_placeholder(&default_commit) + .prompt() + .unwrap(); - glam_packages.push(GlamPackage { - name: name.to_string(), - git_repo: git_repo.to_string(), - commit: commit.to_string(), - target_folder: "".to_string(), - source_folder: "".to_string(), - }); + glam_packages.push(GlamPackage { + name: name.to_string(), + git_repo: git_repo.to_string(), + commit: commit.to_string(), + target_folder: "".to_string(), + source_folder: "".to_string(), + }); let target_package = glam_packages.last_mut().unwrap(); @@ -155,19 +164,29 @@ pub fn add_repository(root: &str, git_repo: &str, verbose: bool) { write_glam_file(&glam_file_path, &glam_object); } -pub fn update_repositories(root: &str, verbose: bool, copy_files: bool) { +pub fn update_repository(root: &str, verbose: bool) { let glam_file_path = format!("{}/.glam", root); - - // Find glam object or create one with default configuration let mut glam_object = read_glam_file(&glam_file_path); let mut glam_packages = glam_object.packages; - for package in glam_packages.iter_mut() { - utils::log_info(&format!("Updating {}...", package.name)); - clone_or_fetch_package(root, package, verbose); - install_glam_package(root, "", package, true, copy_files, verbose); + if glam_packages.is_empty() { + utils::log_error("No addons to update!") } + let options = glam_packages + .iter() + .map(|x| -> &str { &x.name }) + .collect::<Vec<&str>>(); + + let ans = Select::new("Which addon you want to update?", options).prompt().unwrap(); + + let package_index = find_package_by_name(&glam_packages, ans).unwrap(); + let target_package = &mut glam_packages[package_index]; + + utils::log_info(&format!("Updating {}...", target_package.name)); + clone_or_fetch_package(root, target_package, verbose); + install_glam_package(root, "", target_package, true, true, verbose); + glam_object.packages = glam_packages; write_glam_file(&glam_file_path, &glam_object); } @@ -199,7 +218,8 @@ pub fn update_package(root: &str, package_name: &str, verbose: bool, copy_files: } // TODO: just "apply" don't apply changes to all repositories -pub fn apply_changes(root: &str, package_name: &str, create_from_addon: &str, verbose: bool) { +pub fn apply_changes(root: &str, verbose: bool) { + /* let glam_file_path = format!("{}/.glam", root); // Find package to update @@ -209,13 +229,15 @@ pub fn apply_changes(root: &str, package_name: &str, create_from_addon: &str, ve let mut package_index = find_package_by_name(&glam_packages, package_name); - if package_index.is_none() && create_from_addon == "" { + if package_index.is_none() { utils::log_error("Package not found!"); exit(1); - } else if package_index.is_some() && create_from_addon != "" { + } else if package_index.is_some() { utils::log_error("Package already exists!"); exit(1); - } else if create_from_addon != "" { + } + + else if create_from_addon != "" { create_new_package_from_addon( root, &mut glam_packages, @@ -236,6 +258,7 @@ pub fn apply_changes(root: &str, package_name: &str, create_from_addon: &str, ve glam_object.packages = glam_packages; write_glam_file(&glam_file_path, &glam_object); } + */ } fn find_package_by_name(packages: &Vec<GlamPackage>, name: &str) -> Option<usize> { @@ -543,4 +566,4 @@ pub fn search_project_root() -> String { let root = dir.to_str().unwrap().to_string(); utils::log_check(&format!("Found root project in: {}", root)); return root; -}
\ No newline at end of file +} diff --git a/src/main.rs b/src/main.rs index cad56d5..8119315 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,10 +11,6 @@ struct Cli { verbose: bool, } -// TODO: COMMANDS BROKE -// TODO: ADD https://github.com/termapps/enquirer https://docs.rs/dialoguer/latest/dialoguer/ -// TODO: ADD MULTIPLE TARGET / SOURCE FOLDERS PER REPOSITORY - #[derive(Subcommand)] enum Commands { /// Initialize Godot project for GLAM @@ -26,30 +22,13 @@ enum Commands { git_repo: String, }, - /// Install all packages on .glam file - Install { - /// Don't copy to target folder - #[clap(short, long, required = false, takes_value = false)] - no_copy: bool, - }, - - /// Update a single repository. If no repository name is provided, update all repositories - Update { - /// Name of the package to update (default is all packages) - package_name: String, - /// Don't copy to target folder - #[clap(short, long, required = false, takes_value = false)] - no_copy: bool, - }, + /// Update a repository + Update {}, - /// Apply changes to a repository - Apply { - /// 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, - }, + /// Install all addons on glam file + Install {}, + // Apply changes to a repository + //Apply {}, } fn main() { @@ -62,42 +41,32 @@ fn main() { commands::initialize(&root); } - Commands::Add { - git_repo, - } => { + Commands::Add { git_repo } => { let root = commands::search_project_root(); if commands::check_initialization(&root) { commands::add_repository(&root, git_repo, cli.verbose); } } - Commands::Install { no_copy } => { + Commands::Update {} => { let root = commands::search_project_root(); if commands::check_initialization(&root) { - commands::install_repositories(&root, cli.verbose, !*no_copy); + commands::update_repository(&root, cli.verbose); } - } - - Commands::Update { - no_copy, - package_name, - } => { + } + + Commands::Install {} => { let root = commands::search_project_root(); if commands::check_initialization(&root) { - commands::update_repositories(&root, cli.verbose, !*no_copy); + commands::install_repositories(&root, cli.verbose); } - } - - Commands::Apply { - package_names, - create_from_addon, - } => { - let root = commands::search_project_root(); - if commands::check_initialization(&root) { - for package_name in package_names { - commands::apply_changes(&root, &package_name, &create_from_addon, cli.verbose); - } - } - } + } + + /*Commands::Apply {} => { + let root = commands::search_project_root(); + if commands::check_initialization(&root) { + commands::apply_changes(&root, cli.verbose); + } + }*/ } } |