Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/BurntRanch/TabAUR into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
BurntRanch committed Mar 10, 2024
2 parents 92a0c8d + 8e9e795 commit c4e181f
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ OBJ = $(SRC:.cpp=.o)
LIBS ?= -lgit2 -lcpr
LDFLAGS = ${LIBS}
TARGET = taur
CPPFLAGS = -isystem include
CPPFLAGS = -isystem include -std=c++17

all: $(TARGET)

Expand Down
25 changes: 25 additions & 0 deletions PKGBUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
pkgname="TabAUR-git"
pkgver=0.0.1
pkgrel=1
pkgdesc="A lightweight AUR helper, designed to be simple but powerful."
arch=('x86_64' 'aarch64')
url="https://example.com/"
license=('GPL3')
depends=('pacman' 'tar')
makedepends=('libgit2' 'cpr')
optdepends=(
'sudo: privilege elevation'
'doas: privilege elevation'
)
#sha256sums=(SKIP)

build() {
echo $PWD
cd "$srcdir/.." && make -j $(nproc)
}

package() {
echo $PWD
cd "$srcdir/.." && install -Dm755 "taur" "${pkgdir}/usr/local/bin/taur"
#install -Dm644 "LICENSE" "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}
26 changes: 16 additions & 10 deletions include/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define CONFIG_HPP

#include <string>
#include <util.hpp>
#define TOML_HEADER_ONLY 1
#include <toml.hpp>

Expand All @@ -21,14 +22,18 @@ class Config {
string getCacheDir();
string getHomeConfigDir();
string getConfigDir();

//stupid c++ that wants template functions in header
void loadConfigFile(string filename);

// stupid c++ that wants template functions in header
template<typename T>
T getConfigValue(string value, T fallback) {
// .value<T>().value(), nice.
return this->tbl.at_path(value).value<T>() ? this->tbl.at_path(value).value<T>().value() : fallback;
}
void loadConfigFile(string filename);
optional<T> ret = this->tbl.at_path(value).value<T>();
if constexpr (is_string<T>::value) // if we get a value that's a string
return ret ? expandHome(ret.value()) : expandHome(fallback);
else
return ret ? ret.value() : fallback;
}

private:
toml::table tbl;
};
Expand All @@ -44,15 +49,16 @@ inline const std::string defConfig = R"#([general]
# If you use sudo or doas
#sudo = "sudo"
# if false (default), it'll allow you to operate on system packages as well as AUR.
# If false (default), it'll allow you to operate on system packages as well as AUR.
# this option can be overrided by the --aur-only long option or running "-Ra" instead of "-R".
#aurOnly = false
[bin]
#makepkgBin = "makepkg"
[bins]
#makepkgBin = "makepkg"
[storage]
#cacheDir = ""
# Where we are gonna download the AUR packages (default $XDG_CACHE_HOME, else ~/.cache/TabAUR)
#cacheDir = "~/.cache/TabAUR"
)#";

#endif
6 changes: 6 additions & 0 deletions include/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@ enum log_level {
LOG_INFO
};

template<typename T>
struct is_string {
static constexpr bool value = std::is_same_v<T, std::string> || std::is_convertible_v<T, std::string>;
};

// https://stackoverflow.com/questions/874134/find-out-if-string-ends-with-another-string-in-c#874160
bool hasEnding(std::string const& fullString, std::string const& ending);
bool hasStart(std::string const& fullString, std::string const& start);
void log_printf(int log, std::string fmt, ...);
std::string expandHome(std::string& str);
std::vector<std::string> split(std::string text, char delim);

#endif
19 changes: 17 additions & 2 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <util.hpp>

// credits to pacman package manager
// original on src/pacman/util.c
// original on https://gitlab.archlinux.org/pacman/pacman/-/blob/master/src/pacman/conf.c#L45
#define NOCOLOR "\033[0m"

#define BOLD "\033[0;1m"
Expand Down Expand Up @@ -44,7 +44,7 @@ void log_printf(int log, std::string fmt, ...){
va_start(args, fmt);
switch(log){
case LOG_ERROR:
std::cerr << BOLDRED << "====[ ERROR ]==== " << '\n' << NOCOLOR << BOLD; break;
std::cerr << BOLDRED << "====[ ERROR ]==== " << std::endl << NOCOLOR << BOLD; break;
case LOG_WARN:
std::cout << BOLDYELLOW << "Warning: " << NOCOLOR << BOLD; break;
case LOG_INFO:
Expand All @@ -55,6 +55,21 @@ void log_printf(int log, std::string fmt, ...){
std::cout << NOCOLOR;
}

std::string expandHome(std::string& str) {
std::string ret = str;
size_t found = ret.find("~");
if (found != std::string::npos) {
const char* homeDir = getenv("HOME");
if (homeDir != nullptr)
ret.replace(found, 1, homeDir);
else {
log_printf(LOG_ERROR, _("HOME environment variable is not set.\n"));
exit(-1);
}
}
return ret;
}

std::vector<std::string> split(std::string text, char delim) {
std::string line;
std::vector<std::string> vec;
Expand Down

0 comments on commit c4e181f

Please sign in to comment.