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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -4,6 +4,8 @@
#include "cli/options.h" #include "cli/options.h"
#include "repository/RemoteRepository.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 writeCallback(char *in, size_t size, size_t nmemb, std::string *out){
std::size_t total_size = size * nmemb; std::size_t total_size = size * nmemb;
if (total_size){ if (total_size){

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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