From fa22c1d452726bfdefca501a7d06bc59743bf5d6 Mon Sep 17 00:00:00 2001 From: "David J. Allen" Date: Sat, 1 Jul 2023 23:23:14 -0600 Subject: [PATCH] Fixed minor issues and typos --- README.md | 14 ++++---- include/package.hpp | 2 +- src/package.cpp | 63 ++++++++++++++-------------------- src/package_manager.cpp | 75 +++++++++++++++++++++++++++++++---------- 4 files changed, 90 insertions(+), 64 deletions(-) diff --git a/README.md b/README.md index bec3c62..dea2e2b 100644 --- a/README.md +++ b/README.md @@ -198,13 +198,13 @@ Installation behavior can be adjusted using other flags like `--disable-sync`, ` ```bash gdpm install "Flappy Godot" "GodotNetworking" -y -gdpm install -f packages.txt --config config.json --no-sync --skip-prompt --verbose +gdpm install -f packages.txt --config config.json --disable-sync --skip-prompt --verbose gdpm export path/to/packages.txt gdpm install -f path/to/packages.txt --disable-sync --skip-prompt # Future work for multithreading support... -# gdpm install -f path/to/packages.txt -j$(nproc) --no-sync --skip-prompt --verbose +# gdpm install -f path/to/packages.txt -j$(nproc) --disable-sync --skip-prompt --verbose ``` Packages can be removed similiarly to installing. @@ -238,13 +238,12 @@ Search for available packages using the `search` command. The results can be twe Use the `search` command to find a list of available packages. (Note: This currently will only search remotely for package information! This will be changed later to only search the local metadata instead.) ```bash -gdpm search "GodotNetworking" \ +gdpm --verbose search "GodotNetworking" \ --sort updated \ --type project \ --max-results 50 \ --godot-version 3.4 \ - --verbose \ - --user towk \ + --author godot \ --support official ``` @@ -253,9 +252,8 @@ gdpm search "GodotNetworking" \ Link an installed package using the `link` command or make copy of it using `clone`. ```bash -gdpm link "GodotNetworking" tests/test-godot-project -gdpm link -f packages.txt tests/test-godot-project -gdpm clone -f packages.txt tests/tests-godot-project/addons +gdpm link GodotNetworking tests/test-godot-project +gdpm clone GodotNetworking tests/tests-godot-project/addons # Future work # gdpm link --all # links all installed packages to current directory diff --git a/include/package.hpp b/include/package.hpp index d3c2033..0d97f36 100644 --- a/include/package.hpp +++ b/include/package.hpp @@ -121,7 +121,7 @@ namespace gdpm::package { GDPM_DLL_EXPORT result_t get_package_titles(const info_list& packages); GDPM_DLL_EXPORT void clean_temporary(const config::context& config, const title_list& package_titles); GDPM_DLL_EXPORT params make_params(const var_args& args, const var_opts& opts); - + GDPM_DLL_EXPORT void read_file(title_list& package_titles, const path_list& paths); /* Dependency Management API */ GDPM_DLL_EXPORT result_t synchronize_database(const config::context& config, const title_list& package_titles); GDPM_DLL_EXPORT result_t resolve_dependencies(const config::context& config, const title_list& package_titles); diff --git a/src/package.cpp b/src/package.cpp index f52b9ad..acdc476 100644 --- a/src/package.cpp +++ b/src/package.cpp @@ -40,18 +40,8 @@ namespace gdpm::package{ */ /* Append files from --file option */ - // if(!params.input_files.empty()){ - for(const auto& filepath : params.input_files){ - string contents = utils::readfile(filepath); - log::print("contents: {}", contents); - string_list input_titles = utils::split_lines(contents); - package_titles.insert( - std::end(package_titles), - std::begin(input_titles), - std::end(input_titles) - ); - } - // } + read_file(package_titles, params.input_files); + result_t result = cache::get_package_info_by_title(package_titles); package::info_list p_found = {}; package::info_list p_cache = result.unwrap_unsafe(); @@ -250,17 +240,7 @@ namespace gdpm::package{ /* Append package titles from --file option */ - if(!params.input_files.empty()){ - for(const auto& filepath : params.input_files){ - string contents = utils::readfile(filepath); - string_list _package_titles = utils::split_lines(contents); - package_titles.insert( - std::end(package_titles), - std::begin(_package_titles), - std::end(_package_titles) - ); - } - } + read_file(package_titles, params.input_files); /* Find the packages to remove if they're is_installed and show them to the user */ result_t result = cache::get_package_info_by_title(package_titles); @@ -563,19 +543,17 @@ namespace gdpm::package{ } if(p_found.empty()){ - error error( + return log::error_rc(error( constants::error::NO_PACKAGE_FOUND, "No packages found to link." - ); - log::error(error); - return error; + )); } /* Get the storage paths for all packages to create symlinks */ const path package_dir{config.packages_dir}; for(const auto& p : p_found){ for(const auto& path : params.paths){ - log::info_n("link: \"{}\" -> '{}'...", p.title, path + "/" + p.title); + log::println("link: \"{}\" -> '{}'...", p.title, path + "/" + p.title); // std::filesystem::path target{config.packages_dir + "/" + p.title}; std::filesystem::path target = {current_path().string() + "/" + config.packages_dir + "/" + p.title}; std::filesystem::path symlink_path{path + "/" + p.title}; @@ -584,13 +562,11 @@ namespace gdpm::package{ std::error_code ec; std::filesystem::create_directory_symlink(target, symlink_path, ec); if(ec){ - error error( + log::error(error( constants::error::STD_ERR, std::format("Could not create symlink: {}", ec.message()) - ); - log::error(error); + )); } - log::println("Done."); } } return error(); @@ -645,15 +621,13 @@ namespace gdpm::package{ } /* Get the storage paths for all packages to create clones */ - path_refs paths = path_refs{params.args.back()}; // path_list paths = path_list({params.args.back()}); const path package_dir{config.packages_dir}; for(const auto& p : p_found){ - for(const auto& path : paths){ - const string _path = string(path); - log::info("clone: \"{}\" -> {}", p.title, _path + "/" + p.title); + for(const auto& path : params.paths){ + log::println("clone: \"{}\" -> {}", p.title, path + "/" + p.title); std::filesystem::path from{config.packages_dir + "/" + p.title}; - std::filesystem::path to{_path + "/" + p.title}; + std::filesystem::path to{path + "/" + p.title}; if(!std::filesystem::exists(to.string())) std::filesystem::create_directories(to); /* This should only occur if using a --force flag */ @@ -898,6 +872,21 @@ namespace gdpm::package{ return result_t(p_deps, error()); } + void read_file( + title_list& package_titles, + const path_list& paths + ){ + for(const auto& filepath : paths){ + string contents = utils::readfile(filepath); + title_list input_titles = utils::split_lines(contents); + package_titles.insert( + std::end(package_titles), + std::begin(input_titles), + std::end(input_titles) + ); + } + } + string to_json( const info& info, bool pretty_pretty diff --git a/src/package_manager.cpp b/src/package_manager.cpp index 4c83e8a..020d3aa 100644 --- a/src/package_manager.cpp +++ b/src/package_manager.cpp @@ -148,7 +148,7 @@ namespace gdpm::package_manager{ install_command.add_description("install package(s)"); install_command.add_argument("packages") .required() - .nargs(nargs_pattern::at_least_one) + .nargs(nargs_pattern::any) .help("packages to install"); install_command.add_argument("--godot-version") .help("set Godot version for request"); @@ -205,7 +205,8 @@ namespace gdpm::package_manager{ .nargs(nargs_pattern::at_least_one); remove_command.add_description("remove package(s)"); - remove_command.add_argument("packages").nargs(nargs_pattern::at_least_one); + remove_command.add_argument("packages") + .nargs(nargs_pattern::any); remove_command.add_argument("--clean"); remove_command.add_argument("-y", "--skip-prompt"); remove_command.add_argument("-f", "--file") @@ -214,7 +215,8 @@ namespace gdpm::package_manager{ .nargs(nargs_pattern::at_least_one); update_command.add_description("update package(s)"); - update_command.add_argument("packages").nargs(nargs_pattern::at_least_one); + update_command.add_argument("packages") + .nargs(nargs_pattern::any); update_command.add_argument("--clean"); update_command.add_argument("--remote"); update_command.add_argument("-f", "--file") @@ -223,9 +225,30 @@ namespace gdpm::package_manager{ .nargs(nargs_pattern::at_least_one); search_command.add_description("search for package(s)"); - search_command.add_argument("packages").nargs(nargs_pattern::at_least_one); - search_command.add_argument("--godot-version"); - search_command.add_argument("--remote"); + search_command.add_argument("packages") + .nargs(nargs_pattern::any); + search_command.add_argument("--godot-version") + .help("set Godot version") + .nargs(1); + search_command.add_argument("--remote") + .help("set remote to use") + .nargs(1); + search_command.add_argument("--sort") + .help("sort the results") + .nargs(1); + search_command.add_argument("--type") + .help("set the asset type") + .nargs(1); + search_command.add_argument("--max-results") + .help("limit the results") + .nargs(1); + search_command.add_argument("--author") + .help("set the asset author") + .nargs(1); + search_command.add_argument("--support") + .help("set the support level") + .nargs(1); + search_command.add_argument("-f", "--file") .help("set the file(s) to read as input") .append() @@ -254,21 +277,29 @@ namespace gdpm::package_manager{ link_command.add_description("link package(s) to path"); link_command.add_argument("packages") .help("package(s) to link") - .required() .nargs(1); link_command.add_argument("path") .help("path to link") - .required() + .nargs(1); + link_command.add_argument("-f", "--file") + .help("files to link") + .nargs(nargs_pattern::at_least_one); + link_command.add_argument("-p", "--path") + .help("set path to link") .nargs(1); clone_command.add_description("clone package(s) to path"); clone_command.add_argument("packages") .help("package(s) to clone") - .required() .nargs(1);; clone_command.add_argument("path") .help("path to clone") - .required() + .nargs(1); + clone_command.add_argument("-f", "--file") + .help("file") + .nargs(nargs_pattern::at_least_one); + clone_command.add_argument("-p", "--path") + .help("set path to clone") .nargs(1); clean_command.add_description("clean package(s) temporary files"); @@ -280,8 +311,7 @@ namespace gdpm::package_manager{ fetch_command.add_description("fetch and sync asset data"); fetch_command.add_argument("remote") .help("remote to fetch") - .required() - .nargs(1); + .nargs(nargs_pattern::any); config_get.add_argument("properties") .help("get config properties") @@ -379,7 +409,7 @@ namespace gdpm::package_manager{ } else if(program.is_subcommand_used(update_command)){ action = action_e::update; - package_titles = get_packages_from_parser(program); + package_titles = get_packages_from_parser(update_command); set_if_used(update_command, config.clean_temporary, "clean"); set_if_used(update_command, params.remote_source, "remote"); set_if_used(update_command, params.input_files, "file"); @@ -397,7 +427,6 @@ namespace gdpm::package_manager{ } else if(program.is_subcommand_used(list_command)){ action = action_e::list; - // auto list = get_parser(program, "list"); if(list_command.is_used("show")) params.args = list_command.get("show"); if(list_command.is_used("style")){ @@ -412,11 +441,23 @@ namespace gdpm::package_manager{ action = action_e::link; package_titles = get_packages_from_parser(link_command); set_if_used(link_command, params.paths, "path"); + if(link_command.is_used("file")){ + params.input_files = link_command.get("file"); + } + if(link_command.is_used("path")){ + params.paths = link_command.get("path"); + } } else if(program.is_subcommand_used(clone_command)){ action = action_e::clone; package_titles = get_packages_from_parser(clone_command); set_if_used(clone_command, params.paths, "path"); + if(clone_command.is_used("file")){ + params.input_files = clone_command.get("file"); + } + if(clone_command.is_used("path")){ + params.paths = clone_command.get("path"); + } } else if(program.is_subcommand_used(clean_command)){ action = action_e::clean; @@ -435,13 +476,11 @@ namespace gdpm::package_manager{ if(config_set.is_used("value")) params.args.emplace_back(config_set.get("value")); } - // else{ - // action = action_e::config_get; - // } } else if(program.is_subcommand_used(fetch_command)){ action = action_e::fetch; - params.remote_source = fetch_command.get("remote"); + if(fetch_command.is_used("remote")) + params.remote_source = fetch_command.get("remote"); } else if(program.is_subcommand_used(version_command)){ action = action_e::version;