Added section to README.md and minor fixes

This commit is contained in:
David Allen 2023-07-02 08:39:10 -06:00
parent 6141a24473
commit 37b65c0939
7 changed files with 83 additions and 40 deletions

View file

@ -20,6 +20,7 @@ GDPM is an attempt to make a simple, front-end, command-line, package manager de
- [Linking and Cloning](#linking-and-cloning) - [Linking and Cloning](#linking-and-cloning)
- [Cleaning Temporary Files](#cleaning-temporary-files) - [Cleaning Temporary Files](#cleaning-temporary-files)
- [Managing Remote Sources](#managing-remote-sources) - [Managing Remote Sources](#managing-remote-sources)
- [Managing Configuration Properties](#managing-configuration-properties)
- [Planned Features](#planned-features) - [Planned Features](#planned-features)
- [Known Issues](#known-issues) - [Known Issues](#known-issues)
- [License](#license) - [License](#license)
@ -308,6 +309,18 @@ ln -s path/to/build/gdpm path/to/bin/gdpm
export PATH=$PATH:path/to/bin/gdpm export PATH=$PATH:path/to/bin/gdpm
``` ```
### Managing Configuration Properties
Configuration properties can be viewed and set using the `gdpm config` command.
```bash
gdpm config get # shows all config properties
gdpm config get --style=table # shows all config properties in table
gdpm config get skip-prompt jobs # shows config properties listed
gdpm config set timeout 30 # set config property value
gdpm config set username towk
```
## Planned Features ## Planned Features
* [ ] Godot 4 Asset Library compatibility. * [ ] Godot 4 Asset Library compatibility.

View file

@ -48,7 +48,7 @@ namespace gdpm::config{
error load(std::filesystem::path path, context& config); error load(std::filesystem::path path, context& config);
error save(std::filesystem::path path, const context& config); error save(std::filesystem::path path, const context& config);
error handle_config(config::context& config, const args_t& args, const var_opts& opts); error handle_config(config::context& config, const args_t& args, const var_opts& opts);
error set_property(config::context& config, const string& property, const any& value); error set_property(config::context& config, const string& property, const string& value);
template <typename T = any> template <typename T = any>
T& get_property(const config::context& config, const string& property); T& get_property(const config::context& config, const string& property);
context make_context(const string& username = GDPM_CONFIG_USERNAME, const string& password = GDPM_CONFIG_PASSWORD, const string& path = GDPM_CONFIG_PATH, const string& token = GDPM_CONFIG_TOKEN, const string& godot_version = GDPM_CONFIG_GODOT_VERSION, const string& packages_dir = GDPM_CONFIG_LOCAL_PACKAGES_DIR, const string& tmp_dir = GDPM_CONFIG_LOCAL_TMP_DIR, const string_map& remote_sources = {GDPM_CONFIG_REMOTE_SOURCES}, int jobs = GDPM_CONFIG_THREADS, int timeout = 0, bool enable_sync = GDPM_CONFIG_ENABLE_SYNC, bool enable_file_logging = GDPM_CONFIG_ENABLE_FILE_LOGGING, int verbose = GDPM_CONFIG_VERBOSE); context make_context(const string& username = GDPM_CONFIG_USERNAME, const string& password = GDPM_CONFIG_PASSWORD, const string& path = GDPM_CONFIG_PATH, const string& token = GDPM_CONFIG_TOKEN, const string& godot_version = GDPM_CONFIG_GODOT_VERSION, const string& packages_dir = GDPM_CONFIG_LOCAL_PACKAGES_DIR, const string& tmp_dir = GDPM_CONFIG_LOCAL_TMP_DIR, const string_map& remote_sources = {GDPM_CONFIG_REMOTE_SOURCES}, int jobs = GDPM_CONFIG_THREADS, int timeout = 0, bool enable_sync = GDPM_CONFIG_ENABLE_SYNC, bool enable_file_logging = GDPM_CONFIG_ENABLE_FILE_LOGGING, int verbose = GDPM_CONFIG_VERBOSE);

View file

@ -1,6 +1,5 @@
#pragma once #pragma once
#include "clipp.h"
#include <tuple> #include <tuple>
#include <functional> #include <functional>
#include <type_traits> #include <type_traits>
@ -77,6 +76,7 @@ namespace gdpm{
return sl; return sl;
} }
inline opts_t unwrap(const var_opts& opts){ inline opts_t unwrap(const var_opts& opts){
opts_t o; opts_t o;
std::for_each(opts.begin(), opts.end(), [&o](const var_opt& opt){ std::for_each(opts.begin(), opts.end(), [&o](const var_opt& opt){

View file

@ -72,6 +72,7 @@ namespace gdpm::utils {
from.erase(part); from.erase(part);
} }
bool to_bool(const std::string& s);
std::vector<std::string> split_lines(const std::string& contents); std::vector<std::string> split_lines(const std::string& contents);
std::string readfile(const std::string& path); std::string readfile(const std::string& path);
std::string to_lower(const std::string& s); std::string to_lower(const std::string& s);

View file

@ -232,32 +232,33 @@ namespace gdpm::config{
return error(); return error();
} }
error set_property( error set_property(
config::context& config, config::context& config,
const string& property, const string& property,
const any& value const string& value
){ ){
log::println("config::set_property() called"); if(property == "username") config.username = value;
if(property == "username") config.username = std::any_cast<string>(value); else if(property == "password") config.password = value;
else if(property == "password") config.password = std::any_cast<string>(value); else if(property == "path") config.path = value;
else if(property == "path") config.path = std::any_cast<string>(value); else if(property == "token") config.token = value;
else if(property == "token") config.token = std::any_cast<string>(value); else if(property == "packages-dir") config.packages_dir = value;
else if(property == "packages_dir") config.packages_dir = std::any_cast<string>(value); else if(property == "tmp-dir") config.tmp_dir = value;
else if(property == "tmp_dir") config.tmp_dir = std::any_cast<string>(value); else if(property == "remote-sources") log::println("use 'gpdm remote' to manage remotes");
else if(property == "remote_sources") config.remote_sources = std::any_cast<string_map>(value); else if(property == "jobs") config.jobs = std::stoi(value);
else if(property == "jobs") config.jobs = std::any_cast<int>(value); else if(property == "timeout") config.timeout = std::stoi(value);
else if(property == "timeout") config.timeout = std::any_cast<int>(value); else if(property == "enable-sync") config.enable_sync = utils::to_bool(value);
else if(property == "enable_sync") config.enable_sync = std::any_cast<bool>(value); else if(property == "enable-cache") config.enable_cache = utils::to_bool(value);
else if(property == "enable_cache") config.enable_cache = std::any_cast<bool>(value); else if(property == "skip-prompt") config.skip_prompt = utils::to_bool(value);
else if(property == "skip_prompt") config.skip_prompt = std::any_cast<bool>(value); else if(property == "enable-file-logging") config.enable_file_logging = utils::to_bool(value);
else if(property == "enable_file_logging") config.enable_file_logging = std::any_cast<bool>(value); else if(property == "clean-temporary") config.clean_temporary = utils::to_bool(value);
else if(property == "clean_temporary") config.clean_temporary = std::any_cast<bool>(value);
else{ else{
return log::error_rc(error( return log::error_rc(error(
constants::error::INVALID_CONFIG, constants::error::INVALID_CONFIG,
"Could not find property" "Could not find property"
)); ));
} }
return error();
} }
template <typename T> template <typename T>
@ -342,14 +343,14 @@ namespace gdpm::config{
else if(property == "password") log::println("password: {}", config.password); else if(property == "password") log::println("password: {}", config.password);
else if(property == "path") log::println("path: {}", config.path); else if(property == "path") log::println("path: {}", config.path);
else if(property == "token") log::println("token: {}", config.token); else if(property == "token") log::println("token: {}", config.token);
else if(property == "packages_dir") log::println("package directory: {}", config.packages_dir); else if(property == "packages-dir") log::println("package directory: {}", config.packages_dir);
else if(property == "tmp_dir") log::println("temporary directory: {}", config.tmp_dir); else if(property == "tmp-dir") log::println("temporary directory: {}", config.tmp_dir);
else if(property == "remote_sources") log::println("remote sources: \n{}", utils::join(config.remote_sources, "\t", "\n")); else if(property == "remote-sources") log::println("remote sources: \n{}", utils::join(config.remote_sources, "\t", "\n"));
else if(property == "jobs") log::println("parallel jobs: {}", config.jobs); else if(property == "jobs") log::println("parallel jobs: {}", config.jobs);
else if(property == "timeout") log::println("timeout: {}", config.timeout); else if(property == "timeout") log::println("timeout: {}", config.timeout);
else if(property == "sync") log::println("enable sync: {}", config.enable_sync); else if(property == "sync") log::println("enable sync: {}", config.enable_sync);
else if(property == "cache") log::println("enable cache: {}", config.enable_cache); else if(property == "cache") log::println("enable cache: {}", config.enable_cache);
else if(property == "prompt") log::println("skip prompt: {}", config.skip_prompt); else if(property == "skip-prompt") log::println("skip prompt: {}", config.skip_prompt);
else if(property == "logging") log::println("enable file logging: {}", config.enable_file_logging); else if(property == "logging") log::println("enable file logging: {}", config.enable_file_logging);
else if(property == "clean") log::println("clean temporary files: {}", config.clean_temporary); else if(property == "clean") log::println("clean temporary files: {}", config.clean_temporary);
else if(property == "verbose") log::println("verbose: {}", config.verbose); else if(property == "verbose") log::println("verbose: {}", config.verbose);
@ -366,14 +367,14 @@ namespace gdpm::config{
else if(property == "password") table.add_row({"Password", config.password}); else if(property == "password") table.add_row({"Password", config.password});
else if(property == "path") table.add_row({"Path", config.path}); else if(property == "path") table.add_row({"Path", config.path});
else if(property == "token") table.add_row({"Token", config.token}); else if(property == "token") table.add_row({"Token", config.token});
else if(property == "packages_dir") table.add_row({"Package Directory", config.packages_dir}); else if(property == "packages-dir") table.add_row({"Package Directory", config.packages_dir});
else if(property == "tmp_dir") table.add_row({"Temp Directory", config.tmp_dir}); else if(property == "tmp-dir") table.add_row({"Temp Directory", config.tmp_dir});
else if(property == "remote_sources") table.add_row({"Remotes", utils::join(config.remote_sources, "\t", "\n")}); else if(property == "remote-sources") table.add_row({"Remotes", utils::join(config.remote_sources, "\t", "\n")});
else if(property == "jobs") table.add_row({"Threads", std::to_string(config.jobs)}); else if(property == "jobs") table.add_row({"Threads", std::to_string(config.jobs)});
else if(property == "timeout") table.add_row({"Timeout", std::to_string(config.timeout)}); else if(property == "timeout") table.add_row({"Timeout", std::to_string(config.timeout)});
else if(property == "sync") table.add_row({"Fetch Assets", std::to_string(config.enable_sync)}); else if(property == "sync") table.add_row({"Fetch Assets", std::to_string(config.enable_sync)});
else if(property == "cache") table.add_row({"Cache", std::to_string(config.enable_cache)}); else if(property == "cache") table.add_row({"Cache", std::to_string(config.enable_cache)});
else if(property == "prompt") table.add_row({"Skip Prompt", std::to_string(config.skip_prompt)}); else if(property == "skip-prompt") table.add_row({"Skip Prompt", std::to_string(config.skip_prompt)});
else if(property == "logging") table.add_row({"File Logging", std::to_string(config.enable_file_logging)}); else if(property == "logging") table.add_row({"File Logging", std::to_string(config.enable_file_logging)});
else if(property == "clean") table.add_row({"Clean Temporary", std::to_string(config.clean_temporary)}); else if(property == "clean") table.add_row({"Clean Temporary", std::to_string(config.clean_temporary)});
else if(property == "verbose") table.add_row({"Verbosity", std::to_string(config.verbose)}); else if(property == "verbose") table.add_row({"Verbosity", std::to_string(config.verbose)});
@ -391,9 +392,9 @@ namespace gdpm::config{
_print_property(config, "password"); _print_property(config, "password");
_print_property(config, "path"); _print_property(config, "path");
_print_property(config, "token"); _print_property(config, "token");
_print_property(config, "packages_dir"); _print_property(config, "packages-dir");
_print_property(config, "tmp_dir"); _print_property(config, "tmp-dir");
_print_property(config, "remote_sources"); _print_property(config, "remote-sources");
_print_property(config, "jobs"); _print_property(config, "jobs");
_print_property(config, "timeout"); _print_property(config, "timeout");
_print_property(config, "sync"); _print_property(config, "sync");
@ -415,8 +416,8 @@ namespace gdpm::config{
} }
else if(config.style == config::print_style::table){ else if(config.style == config::print_style::table){
Table table; Table table;
table.add_row({"Property", "Value"});
if(properties.empty()){ if(properties.empty()){
table.add_row({"Property", "Value"});
table.add_row({"Username", config.username}); table.add_row({"Username", config.username});
table.add_row({"Password", config.password}); table.add_row({"Password", config.password});
table.add_row({"Path", config.path}); table.add_row({"Path", config.path});

View file

@ -93,7 +93,7 @@ namespace gdpm::package_manager{
} }
}; };
string_list get_packages_from_parser( string_list get_values_from_parser(
const argparse::ArgumentParser& cmd, const argparse::ArgumentParser& cmd,
const std::string& arg = "packages" const std::string& arg = "packages"
){ ){
@ -313,10 +313,17 @@ namespace gdpm::package_manager{
.help("remote to fetch") .help("remote to fetch")
.nargs(nargs_pattern::any); .nargs(nargs_pattern::any);
config_get.add_description("get config properties");
config_get.add_argument("properties") config_get.add_argument("properties")
.help("get config properties") .help("get config properties")
.nargs(nargs_pattern::any); .nargs(nargs_pattern::any);
config_get.add_description("get config properties"); config_get.add_argument("--style")
.help("set how to print output")
.nargs(1)
.default_value("list");
config_set.add_description("set config property");
config_set.add_argument("property") config_set.add_argument("property")
.help("property name") .help("property name")
.required() .required()
@ -325,11 +332,14 @@ namespace gdpm::package_manager{
.help("property value") .help("property value")
.required() .required()
.nargs(1); .nargs(1);
config_set.add_description("set config property");
config_command.add_description("manage config properties"); config_command.add_description("manage config properties");
config_command.add_subparser(config_get); config_command.add_subparser(config_get);
config_command.add_subparser(config_set); config_command.add_subparser(config_set);
config_command.add_argument("--style")
.help("set how to print output")
.nargs(1)
.default_value("list");
remote_add.add_argument("name") remote_add.add_argument("name")
.help("remote name") .help("remote name")
@ -394,7 +404,7 @@ namespace gdpm::package_manager{
} }
else if(program.is_subcommand_used(add_command)){ else if(program.is_subcommand_used(add_command)){
action = action_e::add; action = action_e::add;
package_titles = get_packages_from_parser(add_command); package_titles = get_values_from_parser(add_command);
set_if_used(add_command, params.remote_source, "remote"); set_if_used(add_command, params.remote_source, "remote");
set_if_used(add_command, config.jobs, "jobs"); set_if_used(add_command, config.jobs, "jobs");
set_if_used(add_command, config.skip_prompt, "skip-prompt"); set_if_used(add_command, config.skip_prompt, "skip-prompt");
@ -402,21 +412,21 @@ namespace gdpm::package_manager{
} }
else if(program.is_subcommand_used(remove_command)){ else if(program.is_subcommand_used(remove_command)){
action = action_e::remove; action = action_e::remove;
package_titles = get_packages_from_parser(remove_command); package_titles = get_values_from_parser(remove_command);
set_if_used(remove_command, config.clean_temporary, "clean"); set_if_used(remove_command, config.clean_temporary, "clean");
set_if_used(remove_command, config.skip_prompt, "skip-prompt"); set_if_used(remove_command, config.skip_prompt, "skip-prompt");
set_if_used(remove_command, params.input_files, "file"); set_if_used(remove_command, params.input_files, "file");
} }
else if(program.is_subcommand_used(update_command)){ else if(program.is_subcommand_used(update_command)){
action = action_e::update; action = action_e::update;
package_titles = get_packages_from_parser(update_command); package_titles = get_values_from_parser(update_command);
set_if_used(update_command, config.clean_temporary, "clean"); set_if_used(update_command, config.clean_temporary, "clean");
set_if_used(update_command, params.remote_source, "remote"); set_if_used(update_command, params.remote_source, "remote");
set_if_used(update_command, params.input_files, "file"); set_if_used(update_command, params.input_files, "file");
} }
else if(program.is_subcommand_used(search_command)){ else if(program.is_subcommand_used(search_command)){
action = action_e::search; action = action_e::search;
package_titles = get_packages_from_parser(search_command); package_titles = get_values_from_parser(search_command);
set_if_used(search_command, config.rest_api_params.godot_version, "godot-version"); set_if_used(search_command, config.rest_api_params.godot_version, "godot-version");
set_if_used(search_command, params.remote_source, "remote"); set_if_used(search_command, params.remote_source, "remote");
set_if_used(search_command, params.input_files, "file"); set_if_used(search_command, params.input_files, "file");
@ -439,7 +449,7 @@ namespace gdpm::package_manager{
} }
else if(program.is_subcommand_used(link_command)){ else if(program.is_subcommand_used(link_command)){
action = action_e::link; action = action_e::link;
package_titles = get_packages_from_parser(link_command); package_titles = get_values_from_parser(link_command);
set_if_used(link_command, params.paths, "path"); set_if_used(link_command, params.paths, "path");
if(link_command.is_used("file")){ if(link_command.is_used("file")){
params.input_files = link_command.get<string_list>("file"); params.input_files = link_command.get<string_list>("file");
@ -450,7 +460,7 @@ namespace gdpm::package_manager{
} }
else if(program.is_subcommand_used(clone_command)){ else if(program.is_subcommand_used(clone_command)){
action = action_e::clone; action = action_e::clone;
package_titles = get_packages_from_parser(clone_command); package_titles = get_values_from_parser(clone_command);
set_if_used(clone_command, params.paths, "path"); set_if_used(clone_command, params.paths, "path");
if(clone_command.is_used("file")){ if(clone_command.is_used("file")){
params.input_files = clone_command.get<string_list>("file"); params.input_files = clone_command.get<string_list>("file");
@ -461,13 +471,27 @@ namespace gdpm::package_manager{
} }
else if(program.is_subcommand_used(clean_command)){ else if(program.is_subcommand_used(clean_command)){
action = action_e::clean; action = action_e::clean;
package_titles = get_packages_from_parser(clean_command); package_titles = get_values_from_parser(clean_command);
} }
else if(program.is_subcommand_used(config_command)){ else if(program.is_subcommand_used(config_command)){
if(config_command.is_used("style")){
string style = config_command.get<string>("style");
if(!style.compare("list"))
config.style = config::print_style::list;
else if(!style.compare("table"))
config.style = config::print_style::table;
}
if(config_command.is_subcommand_used(config_get)){ if(config_command.is_subcommand_used(config_get)){
action = action_e::config_get; action = action_e::config_get;
if(config_get.is_used("properties")) if(config_get.is_used("properties"))
params.args = config_get.get<string_list>("properties"); params.args = config_get.get<string_list>("properties");
if(config_get.is_used("style")){
string style = config_get.get<string>("style");
if(!style.compare("list"))
config.style = config::print_style::list;
else if(!style.compare("table"))
config.style = config::print_style::table;
}
} }
else if(config_command.is_subcommand_used(config_set)){ else if(config_command.is_subcommand_used(config_set)){
action = action_e::config_set; action = action_e::config_set;

View file

@ -57,6 +57,10 @@ namespace gdpm::utils{
option::FontStyles{std::vector<FontStyle>{FontStyle::bold}}, option::FontStyles{std::vector<FontStyle>{FontStyle::bold}},
}; };
bool to_bool(const std::string& s){
return to_lower(s) == "true";
}
std::vector<std::string> split_lines(const std::string& contents){ std::vector<std::string> split_lines(const std::string& contents){
using namespace csv2; using namespace csv2;
csv2::Reader< csv2::Reader<