Ajoute le namespace oki

This commit is contained in:
Colin FRIZOT
2022-10-10 11:06:29 +02:00
parent 73dbf64e7f
commit b9bfcc18bd
14 changed files with 176 additions and 145 deletions

View File

@@ -3,6 +3,7 @@
#include <iostream>
#include <cstring>
namespace oki{
void invalidUsage(std::ostream &os) {
std::cerr << "Invalid usage. Hint: ";
}
@@ -33,3 +34,5 @@ CliAction parseArguments(int argc, char *argv[]) {
exit(1);
}
}
}

View File

@@ -3,6 +3,7 @@
#include <string_view>
#include <variant>
namespace oki{
struct ListAction {
};
struct InstallAction {
@@ -12,3 +13,6 @@ struct InstallAction {
using CliAction = std::variant<ListAction, InstallAction>;
CliAction parseArguments(int argc, char *argv[]);
}

View File

@@ -4,6 +4,7 @@
namespace fs = std::filesystem;
namespace oki{
fs::path getDefaultLocalRepository() {
// https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
const char *xdgData = std::getenv("XDG_DATA_HOME");
@@ -12,3 +13,4 @@ fs::path getDefaultLocalRepository() {
}
return xdgData / fs::path{"oki"};
}
}

View File

@@ -2,4 +2,6 @@
#include <filesystem>
namespace oki{
std::filesystem::path getDefaultLocalRepository();
}

View File

@@ -2,6 +2,7 @@
#include <curl/curl.h>
namespace oki{
static std::size_t writeCallback(char *in, std::size_t size, std::size_t nmemb, std::string *out) {
std::size_t totalSize = size * nmemb;
if (totalSize) {
@@ -35,3 +36,4 @@ RequestException::RequestException(int code) : code{code} {}
const char *RequestException::what() const noexcept {
return curl_easy_strerror(static_cast<CURLcode>(code));
}
}

View File

@@ -2,6 +2,7 @@
#include <string>
namespace oki{
class HttpRequest {
private:
void *curl;
@@ -19,3 +20,4 @@ public:
explicit RequestException(int code);
const char *what() const noexcept override;
};
}

View File

@@ -4,6 +4,8 @@
#include "cli/options.h"
#include "repository/RemoteRepository.h"
using namespace oki;
std::size_t writeCallback(char *in, size_t size, size_t nmemb, std::string *out){
std::size_t total_size = size * nmemb;
if (total_size){

View File

@@ -1,5 +1,6 @@
#include "Package.h"
namespace oki{
Package::Package(std::string_view shortName, std::string_view longName) : shortName{shortName}, longName{longName} {}
const std::string& Package::getShortName() const {
@@ -9,3 +10,4 @@ const std::string& Package::getShortName() const {
const std::string& Package::getLongName() const {
return longName;
}
}

View File

@@ -2,6 +2,7 @@
#include <string>
namespace oki{
class Package {
private:
std::string shortName;
@@ -11,3 +12,4 @@ public:
const std::string& getShortName() const;
const std::string& getLongName() const;
};
}

View File

@@ -4,6 +4,7 @@
namespace fs = std::filesystem;
namespace oki{
LocalRepository::LocalRepository(fs::path root) : root{std::move(root)} {}
void LocalRepository::createIfNotExists() {
@@ -21,3 +22,4 @@ std::vector<Package> LocalRepository::listPackages() {
void LocalRepository::download(std::string_view packageName, const fs::path& destination) {
std::cerr << "TODO : downloading " << packageName << "\n";
}
}

View File

@@ -2,6 +2,7 @@
#include "Repository.h"
namespace oki{
class LocalRepository : public Repository {
private:
std::filesystem::path root;
@@ -11,3 +12,4 @@ public:
std::vector<Package> listPackages() override;
void download(std::string_view packageName, const std::filesystem::path& destination) override;
};
}

View File

@@ -5,6 +5,7 @@
using json = nlohmann::json;
namespace oki{
RemoteRepository::RemoteRepository(std::string_view apiUrl) : apiUrl{apiUrl} {}
std::vector<Package> RemoteRepository::listPackages() {
@@ -20,3 +21,4 @@ std::vector<Package> RemoteRepository::listPackages() {
void RemoteRepository::download(std::string_view packageName, const std::filesystem::path &destination) {
}
}

View File

@@ -2,6 +2,7 @@
#include "Repository.h"
namespace oki{
class RemoteRepository : public Repository {
private:
std::string apiUrl;
@@ -10,3 +11,4 @@ public:
std::vector<Package> listPackages() override;
void download(std::string_view packageName, const std::filesystem::path& destination) override;
};
}

View File

@@ -6,9 +6,11 @@
#include "../package/Package.h"
namespace oki{
class Repository {
public:
virtual std::vector<Package> listPackages() = 0;
virtual void download(std::string_view packageName, const std::filesystem::path& destination) = 0;
virtual ~Repository() = default;
};
}