77 lines
2.6 KiB
C++
77 lines
2.6 KiB
C++
/*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
*/
|
|
#include <filesystem>
|
|
#include <memory>
|
|
#include <iostream>
|
|
#include <variant>
|
|
|
|
#include <boost/program_options.hpp>
|
|
|
|
import katja.database;
|
|
import katja.repository;
|
|
import katja.sbo;
|
|
import katja.configuration;
|
|
import katja.command_line;
|
|
|
|
static void get_updates(std::shared_ptr<katja::repository> repository, katja::package_database&& installed_database)
|
|
{
|
|
const std::vector<katja::package_identifier> packages = repository->get_updates(installed_database);
|
|
|
|
for (const auto& package_identifier : packages)
|
|
{
|
|
std::cout << package_identifier.to_string() << std::endl;
|
|
}
|
|
std::cout << std::endl << "Updates " << '(' << packages.size() << ')' << std::endl;
|
|
}
|
|
|
|
static void search_names(std::shared_ptr<katja::repository> repository, const std::string& needle)
|
|
{
|
|
const std::vector<katja::package_identifier> packages = repository->search_names("x86-64", needle);
|
|
|
|
for (const auto& package_identifier : packages)
|
|
{
|
|
std::cout << package_identifier.to_string() << std::endl;
|
|
}
|
|
}
|
|
|
|
static void handle_subcommand(const katja::configuration& configuration,
|
|
const katja::subcommand& command)
|
|
{
|
|
if (std::holds_alternative<katja::updates_command>(command))
|
|
{
|
|
katja::package_database installed_database = katja::read_installed_database();
|
|
|
|
for (const auto& [repository_name, repository_configuration] : configuration)
|
|
{
|
|
std::filesystem::path slackbuild_repository{ repository_configuration.path };
|
|
auto repository = std::make_shared<katja::sbo_repository>(slackbuild_repository);
|
|
|
|
get_updates(repository, std::move(installed_database));
|
|
}
|
|
}
|
|
else if (std::holds_alternative<katja::search_command>(command))
|
|
{
|
|
for (const auto& [repository_name, repository_configuration] : configuration)
|
|
{
|
|
std::filesystem::path slackbuild_repository{ repository_configuration.path };
|
|
auto repository = std::make_shared<katja::sbo_repository>(slackbuild_repository);
|
|
|
|
search_names(repository, std::get<katja::search_command>(command).needle);
|
|
}
|
|
}
|
|
}
|
|
|
|
int main(int argc, const char **argv)
|
|
{
|
|
katja::configuration configuration = katja::read_configuration("katja.toml");
|
|
katja::command_line command_line = katja::parse_command_line(argc, argv);
|
|
katja::subcommand subcommand = katja::parse_subcommand(command_line);
|
|
|
|
handle_subcommand(configuration, subcommand);
|
|
|
|
return EXIT_SUCCESS;
|
|
}
|