1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
/*
* 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;
}
|