Add colored, run scripts
This commit is contained in:
parent
51188e9f8e
commit
6decd7bc4b
|
@ -8,7 +8,7 @@ file(GLOB_RECURSE SOURCES_FILES src/*)
|
||||||
|
|
||||||
add_executable(clippy_terminal ${SOURCES_FILES})
|
add_executable(clippy_terminal ${SOURCES_FILES})
|
||||||
target_include_directories(clippy_terminal PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
target_include_directories(clippy_terminal PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
||||||
target_link_libraries(clippy_terminal cppshell)
|
target_link_libraries(clippy_terminal cppshell rang)
|
||||||
|
|
||||||
install(TARGETS clippy_terminal DESTINATION bin)
|
install(TARGETS clippy_terminal DESTINATION bin)
|
||||||
|
|
||||||
|
@ -19,3 +19,10 @@ FetchContent_Declare(
|
||||||
GIT_TAG origin/main
|
GIT_TAG origin/main
|
||||||
)
|
)
|
||||||
FetchContent_MakeAvailable(cppshell)
|
FetchContent_MakeAvailable(cppshell)
|
||||||
|
|
||||||
|
FetchContent_Declare(
|
||||||
|
rang
|
||||||
|
GIT_REPOSITORY https://github.com/agauniyal/rang.git
|
||||||
|
GIT_TAG origin/master
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(rang)
|
||||||
|
|
|
@ -23,6 +23,7 @@ std::unique_ptr<clippy::targets::Target> Config::GetTarget(
|
||||||
|
|
||||||
std::string current;
|
std::string current;
|
||||||
std::vector<std::string> target_commands;
|
std::vector<std::string> target_commands;
|
||||||
|
target_commands.emplace_back("cd " + initial_directory_);
|
||||||
|
|
||||||
bool target_begin = false;
|
bool target_begin = false;
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,8 @@ class Target;
|
||||||
|
|
||||||
class Config {
|
class Config {
|
||||||
public:
|
public:
|
||||||
Config(std::string path) : path_(std::move(path)) {}
|
Config(std::string path, std::string initial_directory)
|
||||||
|
: path_(std::move(path)), initial_directory_(initial_directory) {}
|
||||||
|
|
||||||
void Edit() { utils::OpenEditor(path_); }
|
void Edit() { utils::OpenEditor(path_); }
|
||||||
|
|
||||||
|
@ -19,4 +20,5 @@ class Config {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string path_;
|
std::string path_;
|
||||||
|
std::string initial_directory_;
|
||||||
};
|
};
|
||||||
|
|
|
@ -59,7 +59,7 @@ Config ProjectList::GetNewConfig(
|
||||||
|
|
||||||
projects_.emplace_back(std::filesystem::current_path(), path_to_config);
|
projects_.emplace_back(std::filesystem::current_path(), path_to_config);
|
||||||
|
|
||||||
return {path_to_config};
|
return {path_to_config, std::filesystem::current_path()};
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectList::Load() {
|
void ProjectList::Load() {
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
struct Project {
|
struct Project {
|
||||||
std::strong_ordering operator<=>(const Project&) const = default;
|
std::strong_ordering operator<=>(const Project&) const = default;
|
||||||
|
|
||||||
Config GetConfig() { return Config{configuration_file}; }
|
Config GetConfig() { return Config{configuration_file, root_project}; }
|
||||||
|
|
||||||
std::filesystem::path root_project;
|
std::filesystem::path root_project;
|
||||||
std::filesystem::path configuration_file;
|
std::filesystem::path configuration_file;
|
||||||
|
|
|
@ -1,37 +0,0 @@
|
||||||
namespace clippy::targets {
|
|
||||||
class Target {
|
|
||||||
public:
|
|
||||||
virtual void Execute() = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
class EmptyTarget : public Target {
|
|
||||||
public:
|
|
||||||
void Execute() override {}
|
|
||||||
};
|
|
||||||
|
|
||||||
class OpenProjectConfig : public Target {
|
|
||||||
public:
|
|
||||||
OpenProjectConfig(Config config) : config_(config) {}
|
|
||||||
|
|
||||||
void Execute() override { config_.Edit(); }
|
|
||||||
|
|
||||||
private:
|
|
||||||
Config config_;
|
|
||||||
};
|
|
||||||
|
|
||||||
class CreateProjectConfig : public Target {
|
|
||||||
public:
|
|
||||||
CreateProjectConfig(ProjectList& projects) : projects_(projects) {}
|
|
||||||
|
|
||||||
void Execute() override {
|
|
||||||
auto scripts_path = utils::GetProjectDirectory() / "scripts";
|
|
||||||
std::filesystem::create_directories(scripts_path);
|
|
||||||
|
|
||||||
auto config = projects_.GetNewConfig(scripts_path);
|
|
||||||
config.Edit();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
ProjectList& projects_;
|
|
||||||
};
|
|
||||||
} // namespace clippy::targets
|
|
|
@ -10,7 +10,10 @@
|
||||||
#include <cppshell/shell.hpp>
|
#include <cppshell/shell.hpp>
|
||||||
#undef SIGPIPE_ALWAYS_IGNORE
|
#undef SIGPIPE_ALWAYS_IGNORE
|
||||||
|
|
||||||
|
#include <rang.hpp>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <ranges>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
namespace clippy::targets {
|
namespace clippy::targets {
|
||||||
|
@ -58,11 +61,26 @@ class RunShellScript : public Target {
|
||||||
void Execute() override {
|
void Execute() override {
|
||||||
cppshell::Shell s;
|
cppshell::Shell s;
|
||||||
|
|
||||||
for (auto& i : commands_) {
|
for (auto& command : commands_) {
|
||||||
std::cout << "-> " << i << std::endl;
|
std::cout << rang::fg::green << rang::style::bold << "-> "
|
||||||
s.Execute(i);
|
<< rang::fg::reset << command << rang::style::reset
|
||||||
|
<< std::endl;
|
||||||
|
s.Execute(command);
|
||||||
if (int err = s.GetExitCodeLastCommand(); err != 0) {
|
if (int err = s.GetExitCodeLastCommand(); err != 0) {
|
||||||
std::cout << "ERROR" << std::endl;
|
std::cout << rang::fg::red << rang::style::bold
|
||||||
|
<< "Command exit with code " << err << rang::fg::reset
|
||||||
|
<< rang::style::reset << std::endl;
|
||||||
|
std::cout << rang::fg::blue << rang::style::bold
|
||||||
|
<< "Continue execution? [Y/n] " << rang::fg::reset
|
||||||
|
<< rang::style::reset;
|
||||||
|
|
||||||
|
std::string result;
|
||||||
|
std::getline(std::cin, result);
|
||||||
|
if (result == "" || result == "y") {
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue