Fixed installing issue with no set remote

- Added default remote repo
- Fixed adding and removing remote repos
This commit is contained in:
David Allen 2023-05-27 13:47:52 -06:00
parent 8b1f1374d8
commit 996c47466e
6 changed files with 46 additions and 29 deletions

View file

@ -11,14 +11,6 @@ namespace gdpm::remote{
const args_t& args,
const opts_t& opts
){
log::println("_handle_remote");
for(const auto& arg : args){
log::println("arg: {}", arg);
}
for(const auto& opt : opts){
log::println("opt: {}:{}", opt.first, utils::join(opt.second));
}
/* Check if enough arguments are supplied */
size_t argc = args.size();
if (argc < 1){
@ -28,19 +20,30 @@ namespace gdpm::remote{
/* Check which subcommand is supplied */
string sub_command = args.front();
args_t argv(args.begin()+1, args.end());
if(argv.size() < 2){
error error(
constants::error::INVALID_ARGS,
"Invalid number of args"
);
log::error(error);
return error;
if(sub_command == "add"){
if(args.size() < 3 || args.empty()){
error error(
constants::error::INVALID_ARG_COUNT,
"Invalid number of args."
);
log::error(error);
return error;
}
string name = args[1];
string url = args[2];
add_repositories(config, {{name, url}});
}
else if (sub_command == "remove") {
if(args.size() < 2 || args.empty()){
error error(
constants::error::INVALID_ARG_COUNT,
"Invalid number of args."
);
log::error(error);
return error;
}
remove_respositories(config, {args.begin()+1, args.end()});
}
string name = argv[1];
string url = argv[2];
if(sub_command == "add") add_repositories(config, {{name, url}});
else if (sub_command == "remove") remove_respositories(config, argv);
// else if (sub_command == "set") set_repositories(config::context &context, const repository_map &repos)
else if (sub_command == "list") print_repositories(config);
else{
@ -79,9 +82,12 @@ namespace gdpm::remote{
config::context& config,
const repo_names& names
){
std::for_each(names.end(), names.begin(), [&config](const string& repo){
config.remote_sources.erase(repo);
});
for(auto it = names.begin(); it != names.end();){
if(config.remote_sources.contains(*it)){
config.remote_sources.erase(*it);
}
it++;
}
}
@ -94,10 +100,9 @@ namespace gdpm::remote{
}
void print_repositories(const config::context& config){
log::println("Remote sources:");
const auto &rs = config.remote_sources;
std::for_each(rs.begin(), rs.end(), [](const string_pair& p){
log::println("\t{}: {}", p.first, p.second);
log::println("{}: {}", p.first, p.second);
});
}
}