aboutsummaryrefslogtreecommitdiff
path: root/src/add_repo.cc
blob: c302b94b54558eb590c0c3d4f4a90e46771d7a99 (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
#include <fstream>
#include <iostream>
#include <string>

#include "add_repo.hh"
#include "vars.hh"

void add_repo(std::string repo, std::string repo_name) {
  bool is_previous_repos = false;
  std::string rfile_line;
  std::string rfile_contents;
  if (std::filesystem::exists(repo_file)) {
    std::ifstream rfile(repo_file);
    while (getline(rfile, rfile_line)) {
      rfile_contents += rfile_line + "\n";
    }
    rfile.close();
    is_previous_repos = true;
  }

  std::string previous_repos = is_previous_repos ? rfile_contents : "";

  std::ofstream wfile;
  wfile.open(repo_file);
  wfile << previous_repos << "repos[\"" << repo_name << "\"] = \"" << repo << "\"" << std::endl;
  wfile.close();

  std::cout << print_pkgit << green << "Added " << repo_name << color_reset << std::endl;
}