Add command to clone the source repository
This commit is contained in:
parent
f46a16b4a0
commit
ae0048ef3d
@ -3,11 +3,11 @@ rule cxx
|
||||
description = CXX $out
|
||||
|
||||
rule link
|
||||
command = g++ -o $out $in
|
||||
command = g++ -o $out $in -lboost_filesystem -lboost_system
|
||||
description = LINK $out
|
||||
|
||||
build build/package.o: cxx src/package.cpp | src/package.h
|
||||
build build/command.o: cxx src/command.cpp | src/command.h build/package.o
|
||||
build build/command.o: cxx src/command.cpp | src/command.h build/package.o src/config.h
|
||||
|
||||
build build/main.o: cxx src/main.cpp
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "command.h"
|
||||
#include <cassert>
|
||||
#include "config.h"
|
||||
|
||||
namespace katja
|
||||
{
|
||||
@ -17,7 +18,33 @@ namespace katja
|
||||
void help::execute() const
|
||||
{
|
||||
std::cout << "Usage:\n"
|
||||
"\tkatja {info|help} [OPTIONS]\n\n";
|
||||
"\tkatja {list|update|help} [OPTIONS]\n\n";
|
||||
}
|
||||
|
||||
update::update()
|
||||
: git_binary(boost::process::search_path("git"))
|
||||
{
|
||||
}
|
||||
|
||||
void update::execute() const
|
||||
{
|
||||
std::filesystem::path workdir{ WORKDIR };
|
||||
std::filesystem::path repository = workdir / "sbo/repository";
|
||||
std::filesystem::file_status repository_status = std::filesystem::status(repository);
|
||||
|
||||
if (std::filesystem::exists(repository_status)
|
||||
&& !std::filesystem::is_directory(repository_status))
|
||||
{
|
||||
throw std::runtime_error("The working directory path \""
|
||||
+ repository.string() + "\" exists, but it isn't a directory.");
|
||||
}
|
||||
else if (!std::filesystem::exists(repository_status))
|
||||
{
|
||||
git("clone", std::filesystem::path(),
|
||||
"git://git.slackbuilds.org/slackbuilds.git", repository.native());
|
||||
}
|
||||
git("remote", repository.native(), "update", "--prune");
|
||||
git("reset", repository.native(), "--hard", "origin/master");
|
||||
}
|
||||
|
||||
command_exception::command_exception(const command_exception_t exception_type,
|
||||
@ -65,6 +92,10 @@ namespace katja
|
||||
{
|
||||
return std::make_unique<list>();
|
||||
}
|
||||
else if (strcmp(argv[1], "update") == 0)
|
||||
{
|
||||
return std::make_unique<update>();
|
||||
}
|
||||
else if (strcmp(argv[1], "help") == 0)
|
||||
{
|
||||
return std::make_unique<help>();
|
||||
|
@ -3,6 +3,8 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include "package.h"
|
||||
#include <boost/process.hpp>
|
||||
#include <filesystem>
|
||||
|
||||
namespace katja
|
||||
{
|
||||
@ -24,6 +26,29 @@ namespace katja
|
||||
void execute() const override;
|
||||
};
|
||||
|
||||
class update final : public command
|
||||
{
|
||||
boost::filesystem::path git_binary;
|
||||
|
||||
template<typename... Args>
|
||||
void git(const std::string& command, const std::filesystem::path& cwd, const Args&... args) const
|
||||
{
|
||||
if (cwd.empty())
|
||||
{
|
||||
boost::process::system(git_binary, command, args...);
|
||||
}
|
||||
else
|
||||
{
|
||||
boost::process::system(git_binary, "-C", cwd.native(), command, args...);
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
explicit update();
|
||||
|
||||
void execute() const override;
|
||||
};
|
||||
|
||||
enum class command_exception_t
|
||||
{
|
||||
no_command,
|
||||
|
1
src/config.h
Normal file
1
src/config.h
Normal file
@ -0,0 +1 @@
|
||||
#define WORKDIR "./var"
|
Loading…
Reference in New Issue
Block a user