blob: 58e077f1e99de6c6499828ff14b9d7c5b725eecb (
plain)
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
|
#include <iostream>
#include <string>
#include <filesystem>
#include "create_pkg.hh"
#include "lua_state.hh"
#include "name_from_url.hh"
#include "vars.hh"
Pkg create_pkg(std::string arg, const char* target) {
Pkg pkg;
pkg.target = target;
pkg.ver = "HEAD";
bool is_in_repos = false;
bool is_local = false;
init_lua_state();
cache_repos();
for (auto repo : cached_repos) {
if (arg == repo.first) { is_in_repos = true; }
}
if (arg.rfind("http", 0) == 0) {
pkg.url = arg;
pkg.name = name_from_url(arg);
} else if (arg == ".") {
pkg.url = "";
pkg.src = std::filesystem::current_path().string();
pkg.name = name_from_url(std::filesystem::current_path().string());
is_local = true;
} else if (is_in_repos) {
pkg.url = cached_repos[arg].source.value;
pkg.name = arg;
} else {
std::cout << print_error << "'" << arg << "'" << " is not a valid package" << std::endl;
exit(1);
}
cache_install_directories();
if (!is_local) {
pkg.src = install_directories["src"] + "/" + pkg.name + "/" + pkg.ver;
}
return pkg;
}
|