aboutsummaryrefslogtreecommitdiff
path: root/src/create_pkg.cc
blob: a6b78e94175af448e1232781538d0bb0acd045ca (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
#include <iostream>
#include <string>
#include <filesystem>

#include "create_pkg.hh"
#include "name_from_url.hh"
#include "vars.hh"

Pkg create_pkg(std::string arg) {
  Pkg pkg;
  bool is_in_repos = false;

  for (auto repo : 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.name = name_from_url(std::filesystem::current_path().string());
  } else if (is_in_repos) {
    pkg.url = repos[arg];
    pkg.name = arg;
  } else {
    std::cout << print_error << "'" << arg << "'" << " is not a valid package" << std::endl;
    exit(1);
  }

  pkg.ver = "HEAD";

  pkg.src = install_directories["pkgblds"] + "/" + pkg.name + "/" + pkg.ver;

  return pkg;
}