From a9fccb588b3c12307530378a278a9dd13ab5f58c Mon Sep 17 00:00:00 2001 From: Timofey Date: Wed, 10 Aug 2022 10:45:35 +0300 Subject: [PATCH 01/25] Parse input parametres --- src/main.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 6b81f84..dcd5518 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,24 @@ #include +#include +#include -int main() { - std::cout << "Hello I'm clippy" << std::endl; +std::vector ParseInputParameters(int argc, char* argv[]) { + std::vector result; + result.reserve(argc); + + for (size_t i = 0; i < argc; ++i) { + result.emplace_back(argv[i]); + } + + return result; +} + +int main(int argc, char* argv[]) { + auto params = ParseInputParameters(argc, argv); + std::cout << "Hello I'm clippy" << std::endl; + std::cout << "Parametres: { "; + for (size_t i = 0; i < params.size(); ++i) { + std::cout << params[i] << (i + 1 == params.size() ? "" : ",") << " "; + } + std::cout << "}" << std::endl; } From 6cc47ac5430bcff710d6ece3e39b35cdd6b3dbe1 Mon Sep 17 00:00:00 2001 From: Timofey Date: Wed, 10 Aug 2022 10:53:23 +0300 Subject: [PATCH 02/25] Add clippy --- src/clippy/clippy.cpp | 13 +++++++++++++ src/clippy/clippy.hpp | 11 +++++++++++ src/main.cpp | 12 +++++------- 3 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 src/clippy/clippy.cpp create mode 100644 src/clippy/clippy.hpp diff --git a/src/clippy/clippy.cpp b/src/clippy/clippy.cpp new file mode 100644 index 0000000..4dba76b --- /dev/null +++ b/src/clippy/clippy.cpp @@ -0,0 +1,13 @@ +#include + +#include +#include + +void Clippy::Run(const std::vector& args) { + std::cout << "Hello I'm clippy" << std::endl; + std::cout << "Parametres: { "; + for (size_t i = 0; i < args.size(); ++i) { + std::cout << args[i] << (i + 1 == args.size() ? "" : ",") << " "; + } + std::cout << "}" << std::endl; +} diff --git a/src/clippy/clippy.hpp b/src/clippy/clippy.hpp new file mode 100644 index 0000000..d67abe1 --- /dev/null +++ b/src/clippy/clippy.hpp @@ -0,0 +1,11 @@ +#pragma once + +#include +#include + +class Clippy { + public: + void Run(const std::vector& args); + + private: +}; diff --git a/src/main.cpp b/src/main.cpp index dcd5518..8b36b82 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,5 @@ -#include +#include + #include #include @@ -15,10 +16,7 @@ std::vector ParseInputParameters(int argc, char* argv[]) { int main(int argc, char* argv[]) { auto params = ParseInputParameters(argc, argv); - std::cout << "Hello I'm clippy" << std::endl; - std::cout << "Parametres: { "; - for (size_t i = 0; i < params.size(); ++i) { - std::cout << params[i] << (i + 1 == params.size() ? "" : ",") << " "; - } - std::cout << "}" << std::endl; + + Clippy clippy; + clippy.Run(params); } From b9d951ec9a748f81e99dfe7a44b9a7e66365bff1 Mon Sep 17 00:00:00 2001 From: Timofey Date: Wed, 10 Aug 2022 11:04:37 +0300 Subject: [PATCH 03/25] Add help option --- src/clippy/clippy.cpp | 20 ++++++++++++++------ src/clippy/clippy.hpp | 1 + 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/clippy/clippy.cpp b/src/clippy/clippy.cpp index 4dba76b..f84acdc 100644 --- a/src/clippy/clippy.cpp +++ b/src/clippy/clippy.cpp @@ -4,10 +4,18 @@ #include void Clippy::Run(const std::vector& args) { - std::cout << "Hello I'm clippy" << std::endl; - std::cout << "Parametres: { "; - for (size_t i = 0; i < args.size(); ++i) { - std::cout << args[i] << (i + 1 == args.size() ? "" : ",") << " "; - } - std::cout << "}" << std::endl; + TryExecuteClippyCommand(args); +} + +bool Clippy::TryExecuteClippyCommand(const std::vector& args) { + if (args.size() >= 2 && (args[1] == "help" || args[1] == "hello")) { + std::cout << "Hello I'm clippy" << std::endl; + std::cout << "Parametres: { "; + for (size_t i = 0; i < args.size(); ++i) { + std::cout << args[i] << (i + 1 == args.size() ? "" : ",") << " "; + } + std::cout << "}" << std::endl; + } + + return false; } diff --git a/src/clippy/clippy.hpp b/src/clippy/clippy.hpp index d67abe1..a074c29 100644 --- a/src/clippy/clippy.hpp +++ b/src/clippy/clippy.hpp @@ -8,4 +8,5 @@ class Clippy { void Run(const std::vector& args); private: + bool TryExecuteClippyCommand(const std::vector& args); }; From c2d0033f789847308c31b625dd9cdfea18bda67b Mon Sep 17 00:00:00 2001 From: Timofey Date: Wed, 10 Aug 2022 12:02:25 +0300 Subject: [PATCH 04/25] Reformat --- src/clippy/clippy.cpp | 6 +++- src/main.cpp | 13 ++------ src/utils/parametres.cpp | 14 +++++++++ src/utils/parametres.hpp | 66 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 12 deletions(-) create mode 100644 src/utils/parametres.cpp create mode 100644 src/utils/parametres.hpp diff --git a/src/clippy/clippy.cpp b/src/clippy/clippy.cpp index f84acdc..c17e7d4 100644 --- a/src/clippy/clippy.cpp +++ b/src/clippy/clippy.cpp @@ -1,5 +1,7 @@ #include +#include + #include #include @@ -8,7 +10,9 @@ void Clippy::Run(const std::vector& args) { } bool Clippy::TryExecuteClippyCommand(const std::vector& args) { - if (args.size() >= 2 && (args[1] == "help" || args[1] == "hello")) { + using namespace utils::parametres; + if (CheckPatternParametres(args, Parameter::Skip, "help", + Parameter::Anything)) { std::cout << "Hello I'm clippy" << std::endl; std::cout << "Parametres: { "; for (size_t i = 0; i < args.size(); ++i) { diff --git a/src/main.cpp b/src/main.cpp index 8b36b82..0e68cf5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,20 +1,11 @@ #include +#include #include #include -std::vector ParseInputParameters(int argc, char* argv[]) { - std::vector result; - result.reserve(argc); - - for (size_t i = 0; i < argc; ++i) { - result.emplace_back(argv[i]); - } - - return result; -} - int main(int argc, char* argv[]) { + using namespace utils::parametres; auto params = ParseInputParameters(argc, argv); Clippy clippy; diff --git a/src/utils/parametres.cpp b/src/utils/parametres.cpp new file mode 100644 index 0000000..552ad1a --- /dev/null +++ b/src/utils/parametres.cpp @@ -0,0 +1,14 @@ +#include + +namespace utils::parametres { +std::vector ParseInputParameters(int argc, char* argv[]) { + std::vector result; + result.reserve(argc); + + for (size_t i = 0; i < argc; ++i) { + result.emplace_back(argv[i]); + } + + return result; +} +} // namespace utils diff --git a/src/utils/parametres.hpp b/src/utils/parametres.hpp new file mode 100644 index 0000000..edbcdd5 --- /dev/null +++ b/src/utils/parametres.hpp @@ -0,0 +1,66 @@ +#pragma once +#include +#include +#include + +namespace utils::parametres { +enum class Parameter { Skip, Nothing, Anything }; + +namespace detail { +template +bool CheckPatternParametresImpl(const std::vector& args, + Parameter t) { + if (t == Parameter::Nothing) { + return index == args.size(); + } else if (t == Parameter::Anything) { + return true; + } + return false; +} + +template , bool>> +bool CheckPatternParametresImpl(const std::vector& args, T&& head, + Args&&... pattern); + +template , bool> = true> +bool CheckPatternParametresImpl(const std::vector& args, T&& p, + Args&&... pattern) { + if (index >= args.size()) { + return false; + } + + if (p != Parameter::Skip) { + throw std::logic_error("Unsupported parameter"); + } + + return CheckPatternParametresImpl( + args, std::forward(pattern)...); +} + +template , bool> = true> +bool CheckPatternParametresImpl(const std::vector& args, T&& head, + Args&&... pattern) { + if (index >= args.size()) { + return false; + } + if (args[index] != head) { + return false; + } + return CheckPatternParametresImpl( + args, std::forward(pattern)...); +} +} // namespace detail + +std::vector ParseInputParameters(int argc, char* argv[]); + +template +bool CheckPatternParametres(const std::vector& args, + Args&&... pattern) { + return detail::CheckPatternParametresImpl<0, Args...>( + args, std::forward(pattern)...); +} + +} // namespace utils From 4aa3194e005574b01389ca759915fc9a0337d3b1 Mon Sep 17 00:00:00 2001 From: Timofey Date: Wed, 10 Aug 2022 21:49:37 +0300 Subject: [PATCH 05/25] Add lock file --- src/utils/lock_file.cpp | 18 ++++++++++++++++++ src/utils/lock_file.hpp | 19 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 src/utils/lock_file.cpp create mode 100644 src/utils/lock_file.hpp diff --git a/src/utils/lock_file.cpp b/src/utils/lock_file.cpp new file mode 100644 index 0000000..9f740c0 --- /dev/null +++ b/src/utils/lock_file.cpp @@ -0,0 +1,18 @@ +#include + +#include +#include + +namespace utils::filesystem { +void LockFile::Lock() { + fd_ = open(path_.data(), O_RDWR | O_CREAT, 0666); + while (flock(fd_, LOCK_EX) != 0) { + } +} + +void LockFile::Unlock() { + while (flock(fd_, LOCK_UN) != 0) { + } + close(fd_); +} +} // namespace utils::filesystem diff --git a/src/utils/lock_file.hpp b/src/utils/lock_file.hpp new file mode 100644 index 0000000..d5f99c3 --- /dev/null +++ b/src/utils/lock_file.hpp @@ -0,0 +1,19 @@ +#pragma once +#include + +namespace utils::filesystem { +class LockFile { + public: + LockFile(std::string path) : path_(std::move(path) + ".lock") {} + + void Lock(); + void lock() { Lock(); } + + void Unlock(); + void unlock() { Unlock(); } + + private: + std::string path_; + int fd_ = -1; +}; +} // namespace utils::filesystem From 709a264c88c23303649ed439567f68e336a01860 Mon Sep 17 00:00:00 2001 From: Timofey Date: Wed, 10 Aug 2022 21:50:14 +0300 Subject: [PATCH 06/25] Add interface editor --- src/utils/editor.cpp | 9 +++++++++ src/utils/editor.hpp | 7 +++++++ 2 files changed, 16 insertions(+) create mode 100644 src/utils/editor.cpp create mode 100644 src/utils/editor.hpp diff --git a/src/utils/editor.cpp b/src/utils/editor.cpp new file mode 100644 index 0000000..aff39ef --- /dev/null +++ b/src/utils/editor.cpp @@ -0,0 +1,9 @@ +#include + +#include + +namespace utils { +void OpenEditor(const std::string& file) { + std::cout << "Open file " << file << " TODO" << std::endl; +} +} diff --git a/src/utils/editor.hpp b/src/utils/editor.hpp new file mode 100644 index 0000000..da5d800 --- /dev/null +++ b/src/utils/editor.hpp @@ -0,0 +1,7 @@ +#pragma once + +#include + +namespace utils { +void OpenEditor(const std::string& file); +} From 487f6d05d2d8faf8d4d5604e965ba1380eb04939 Mon Sep 17 00:00:00 2001 From: Timofey Date: Wed, 10 Aug 2022 21:50:50 +0300 Subject: [PATCH 07/25] Add targets clippy --- src/clippy/target.hpp | 45 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/clippy/target.hpp diff --git a/src/clippy/target.hpp b/src/clippy/target.hpp new file mode 100644 index 0000000..75676f5 --- /dev/null +++ b/src/clippy/target.hpp @@ -0,0 +1,45 @@ +#pragma once + +#include + +#include + +#include +#include + +namespace clippy::targets { +class Target { + public: + virtual void Execute() = 0; +}; + +class EmptyTarget : public Target { + public: + void Execute() override {} +}; + +class OpenProjectConfig : public Target { + public: + OpenProjectConfig(std::string config_path) : config_path_(config_path) {} + + void Execute() override { + utils::OpenEditor(config_path_); + std::cout << "Open editor TODO" << std::endl; + } + + private: + std::string config_path_; +}; + +class CreateProjectConfig : public Target { + public: + CreateProjectConfig(ProjectList& projects) : projects_(projects) {} + + void Execute() override { + std::cout << "Make new project config and open editor TODO" << std::endl; + } + + private: + ProjectList& projects_; +}; +} // namespace clippy::targets From bd4c842b85f5378e9d38f9caa444ea795a52302f Mon Sep 17 00:00:00 2001 From: Timofey Date: Wed, 10 Aug 2022 21:51:16 +0300 Subject: [PATCH 08/25] Add interface config --- src/clippy/config.hpp | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 src/clippy/config.hpp diff --git a/src/clippy/config.hpp b/src/clippy/config.hpp new file mode 100644 index 0000000..21b4bf9 --- /dev/null +++ b/src/clippy/config.hpp @@ -0,0 +1,5 @@ +#pragma once + +class Config { + +}; From fe9e88706164562daa57223ddd49a3a868e86f53 Mon Sep 17 00:00:00 2001 From: Timofey Date: Wed, 10 Aug 2022 21:51:42 +0300 Subject: [PATCH 09/25] Update standart --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 952f8b9..9fec854 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.14) project(clippy_terminal) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) file(GLOB_RECURSE SOURCES_FILES src/*) From a4229edd6fdba03785f9b7542f731498a2680dc1 Mon Sep 17 00:00:00 2001 From: Timofey Date: Wed, 10 Aug 2022 21:52:07 +0300 Subject: [PATCH 10/25] Add read project lists --- src/clippy/clippy.cpp | 29 +++++++++++++++++-- src/clippy/clippy.hpp | 9 +++++- src/clippy/project_list.cpp | 57 +++++++++++++++++++++++++++++++++++++ src/clippy/project_list.hpp | 27 ++++++++++++++++++ 4 files changed, 118 insertions(+), 4 deletions(-) create mode 100644 src/clippy/project_list.cpp create mode 100644 src/clippy/project_list.hpp diff --git a/src/clippy/clippy.cpp b/src/clippy/clippy.cpp index c17e7d4..6854848 100644 --- a/src/clippy/clippy.cpp +++ b/src/clippy/clippy.cpp @@ -1,16 +1,25 @@ #include +#include #include #include +#include #include +#include void Clippy::Run(const std::vector& args) { - TryExecuteClippyCommand(args); + auto result = TryExecuteClippyCommand(args); + if (result) { + result->Execute(); + return; + } } -bool Clippy::TryExecuteClippyCommand(const std::vector& args) { +Clippy::TargetPtr Clippy::TryExecuteClippyCommand( + const std::vector& args) { using namespace utils::parametres; + using namespace clippy::targets; if (CheckPatternParametres(args, Parameter::Skip, "help", Parameter::Anything)) { std::cout << "Hello I'm clippy" << std::endl; @@ -19,7 +28,21 @@ bool Clippy::TryExecuteClippyCommand(const std::vector& args) { std::cout << args[i] << (i + 1 == args.size() ? "" : ",") << " "; } std::cout << "}" << std::endl; + + return std::make_unique(); } - return false; + if (CheckPatternParametres(args, Parameter::Skip, "cfg", + Parameter::Anything)) { + projects_.LoadFrom("test"); + auto p = projects_.GetCurrentProject(); + + if (p.has_value()) { + return std::make_unique(p.value().configuration_file); + } else { + return std::make_unique(projects_); + } + } + + return nullptr; } diff --git a/src/clippy/clippy.hpp b/src/clippy/clippy.hpp index a074c29..a944267 100644 --- a/src/clippy/clippy.hpp +++ b/src/clippy/clippy.hpp @@ -1,12 +1,19 @@ #pragma once +#include +#include + #include #include +#include class Clippy { public: void Run(const std::vector& args); + using TargetPtr = std::unique_ptr; private: - bool TryExecuteClippyCommand(const std::vector& args); + TargetPtr TryExecuteClippyCommand(const std::vector& args); + + ProjectList projects_; }; diff --git a/src/clippy/project_list.cpp b/src/clippy/project_list.cpp new file mode 100644 index 0000000..7b29f75 --- /dev/null +++ b/src/clippy/project_list.cpp @@ -0,0 +1,57 @@ +#include +#include +#include + +#include +#include + + + + + + +#include + +void ProjectList::LoadFrom(const std::string& path) { + utils::filesystem::LockFile lock(path); + std::lock_guard guard(lock); + + std::ifstream in(path); + + Project current; + + while (in >> current.root_project >> current.configuration_file) { + projects_.push_back(current); + } +} + +std::optional ProjectList::GetCurrentProject() { + auto current_path = std::filesystem::current_path(); + + std::optional result; + auto UpdateResult = [&result](Project p) { + if (!result.has_value()) { + result = p; + } else { + result = std::max(p, result.value()); + } + }; + + for (auto& project : projects_) { + auto prefix_current_path = current_path; + + if (project.root_project == "/") { + UpdateResult(project); + continue; + } + + while (prefix_current_path != "/") { + if (prefix_current_path == project.root_project) { + UpdateResult(project); + } + prefix_current_path = prefix_current_path.parent_path(); + } + } + + return result; +} diff --git a/src/clippy/project_list.hpp b/src/clippy/project_list.hpp new file mode 100644 index 0000000..be5d369 --- /dev/null +++ b/src/clippy/project_list.hpp @@ -0,0 +1,27 @@ +#pragma once +#include + +#include +#include +#include + +struct Project { + std::strong_ordering operator<=>(const Project&) const = default; + + std::filesystem::path root_project; + std::filesystem::path configuration_file; +}; + +class ProjectList { + public: + ProjectList() {} + + void LoadFrom(const std::string& path); + + const std::vector& GetProjects() const { return projects_; } + + std::optional GetCurrentProject(); + + private: + std::vector projects_; +}; From 7e7d2aa575e86d6105b4a687761963b1b299c48a Mon Sep 17 00:00:00 2001 From: Timofey Date: Wed, 10 Aug 2022 21:53:34 +0300 Subject: [PATCH 11/25] Delete empty strings --- src/clippy/project_list.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/clippy/project_list.cpp b/src/clippy/project_list.cpp index 7b29f75..0225ef3 100644 --- a/src/clippy/project_list.cpp +++ b/src/clippy/project_list.cpp @@ -5,11 +5,6 @@ #include #include - - - - - #include void ProjectList::LoadFrom(const std::string& path) { From c6d62059ae7fb314db52f1b25b931e0a8657c500 Mon Sep 17 00:00:00 2001 From: Timofey Date: Wed, 10 Aug 2022 22:01:53 +0300 Subject: [PATCH 12/25] Add cppshell lib --- CMakeLists.txt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9fec854..1f095a1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,5 +8,14 @@ file(GLOB_RECURSE SOURCES_FILES src/*) add_executable(clippy_terminal ${SOURCES_FILES}) target_include_directories(clippy_terminal PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src) +target_link_libraries(clippy_terminal cppshell) install(TARGETS clippy_terminal DESTINATION bin) + +include(FetchContent) +FetchContent_Declare( + cppshell + GIT_REPOSITORY https://gitlab.com/Onyad/cppshell + GIT_TAG origin/main +) +FetchContent_MakeAvailable(cppshell) From 82cc4d0f6f2a877f140e8ac9fda6fa6b24862bef Mon Sep 17 00:00:00 2001 From: Timofey Date: Wed, 10 Aug 2022 22:02:05 +0300 Subject: [PATCH 13/25] Ignore sigpipe --- src/main.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 0e68cf5..267527e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,7 +4,11 @@ #include #include +#include + int main(int argc, char* argv[]) { + std::signal(SIGPIPE, SIG_IGN); + using namespace utils::parametres; auto params = ParseInputParameters(argc, argv); From 7487bab9ae12fb7e0586a88684ce43b5392aa0f1 Mon Sep 17 00:00:00 2001 From: Timofey Date: Wed, 10 Aug 2022 22:02:39 +0300 Subject: [PATCH 14/25] Add realization open editor --- src/utils/editor.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/utils/editor.cpp b/src/utils/editor.cpp index aff39ef..01731ed 100644 --- a/src/utils/editor.cpp +++ b/src/utils/editor.cpp @@ -1,9 +1,22 @@ #include +#define SIGPIPE_ALWAYS_IGNORE +#include +#undef SIGPIPE_ALWAYS_IGNORE + #include namespace utils { void OpenEditor(const std::string& file) { - std::cout << "Open file " << file << " TODO" << std::endl; -} + std::string editors[] = {"nvim", "vim", "vi"}; + + cppshell::Shell shell; + + for (auto& editor : editors) { + shell.Execute(editor + " " + file); + if (shell.GetExitCodeLastCommand() == 0) { + break; + } + } } +} // namespace utils From 77a2ee99896cea1362ab809bff036ebc9a2436fa Mon Sep 17 00:00:00 2001 From: Timofey Date: Wed, 10 Aug 2022 22:03:53 +0300 Subject: [PATCH 15/25] Delete unnecessary include --- src/utils/editor.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/utils/editor.cpp b/src/utils/editor.cpp index 01731ed..8c54de6 100644 --- a/src/utils/editor.cpp +++ b/src/utils/editor.cpp @@ -4,8 +4,6 @@ #include #undef SIGPIPE_ALWAYS_IGNORE -#include - namespace utils { void OpenEditor(const std::string& file) { std::string editors[] = {"nvim", "vim", "vi"}; From 51188e9f8e0838addee07aa59707cf970e6b59cd Mon Sep 17 00:00:00 2001 From: Timofey Date: Thu, 11 Aug 2022 16:43:53 +0300 Subject: [PATCH 16/25] Add change config file and run config file --- src/clippy/clippy.cpp | 35 +++++++++++++++---- src/clippy/clippy.hpp | 5 ++- src/clippy/config.cpp | 52 ++++++++++++++++++++++++++++ src/clippy/config.hpp | 19 ++++++++++- src/clippy/project_list.cpp | 68 ++++++++++++++++++++++++++++++++++--- src/clippy/project_list.hpp | 17 ++++++++-- src/clippy/target.cpp | 37 ++++++++++++++++++++ src/clippy/target.hpp | 42 +++++++++++++++++++---- src/utils/config_path.hpp | 20 +++++++++++ 9 files changed, 273 insertions(+), 22 deletions(-) create mode 100644 src/clippy/config.cpp create mode 100644 src/clippy/target.cpp create mode 100644 src/utils/config_path.hpp diff --git a/src/clippy/clippy.cpp b/src/clippy/clippy.cpp index 6854848..f5042ce 100644 --- a/src/clippy/clippy.cpp +++ b/src/clippy/clippy.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -9,8 +10,11 @@ #include void Clippy::Run(const std::vector& args) { - auto result = TryExecuteClippyCommand(args); - if (result) { + if (auto result = TryExecuteClippyCommand(args); result) { + result->Execute(); + return; + } + if (auto result = GetScriptTarget(args); result) { result->Execute(); return; } @@ -34,15 +38,34 @@ Clippy::TargetPtr Clippy::TryExecuteClippyCommand( if (CheckPatternParametres(args, Parameter::Skip, "cfg", Parameter::Anything)) { - projects_.LoadFrom("test"); - auto p = projects_.GetCurrentProject(); + LoadProjects(); + auto p = projects_->GetCurrentProject(); if (p.has_value()) { - return std::make_unique(p.value().configuration_file); + return std::make_unique(p->GetConfig()); } else { - return std::make_unique(projects_); + return std::make_unique(projects_.value()); } } return nullptr; } + +Clippy::TargetPtr Clippy::GetScriptTarget( + const std::vector& args) { + LoadProjects(); + auto p = projects_->GetCurrentProject(); + + if (!p.has_value() || args.size() < 2) { + return nullptr; + } + + auto cfg = p->GetConfig(); + return cfg.GetTarget(args[1]); +} + +void Clippy::LoadProjects() { + if (!projects_.has_value()) { + projects_.emplace(utils::GetProjectDirectory() / "projects"); + } +} diff --git a/src/clippy/clippy.hpp b/src/clippy/clippy.hpp index a944267..42c1d3e 100644 --- a/src/clippy/clippy.hpp +++ b/src/clippy/clippy.hpp @@ -14,6 +14,9 @@ class Clippy { using TargetPtr = std::unique_ptr; private: TargetPtr TryExecuteClippyCommand(const std::vector& args); + TargetPtr GetScriptTarget(const std::vector& args); - ProjectList projects_; + void LoadProjects(); + + std::optional projects_; }; diff --git a/src/clippy/config.cpp b/src/clippy/config.cpp new file mode 100644 index 0000000..a966c97 --- /dev/null +++ b/src/clippy/config.cpp @@ -0,0 +1,52 @@ +#include +#include + +#include +#include + +std::string Strip(std::string s) { + while (!s.empty() && std::isspace(s.back())) { + s.pop_back(); + } + std::reverse(s.begin(), s.end()); + while (!s.empty() && std::isspace(s.back())) { + s.pop_back(); + } + std::reverse(s.begin(), s.end()); + + return s; +} + +std::unique_ptr Config::GetTarget( + const std::string& target) { + std::ifstream in(path_); + + std::string current; + std::vector target_commands; + + bool target_begin = false; + + while (std::getline(in, current)) { + if (current == target + ":") { + target_begin = true; + continue; + } + if (current.empty()) { + continue; + } + if (!std::isspace(current[0]) && target_begin) { + break; + } + + if (target_begin) { + target_commands.emplace_back(Strip(std::move(current))); + } + } + + if (!target_begin) { + return nullptr; + } + + return std::make_unique( + std::move(target_commands)); +} diff --git a/src/clippy/config.hpp b/src/clippy/config.hpp index 21b4bf9..e9927a5 100644 --- a/src/clippy/config.hpp +++ b/src/clippy/config.hpp @@ -1,5 +1,22 @@ #pragma once -class Config { +#include +#include +#include + +namespace clippy::targets { +class Target; +} + +class Config { + public: + Config(std::string path) : path_(std::move(path)) {} + + void Edit() { utils::OpenEditor(path_); } + + std::unique_ptr GetTarget(const std::string& target); + + private: + std::string path_; }; diff --git a/src/clippy/project_list.cpp b/src/clippy/project_list.cpp index 0225ef3..b4ed2a9 100644 --- a/src/clippy/project_list.cpp +++ b/src/clippy/project_list.cpp @@ -4,14 +4,72 @@ #include #include +#include +#include -#include +Config ProjectList::GetNewConfig( + const std::filesystem::path& config_directory) { + std::lock_guard guard(lock_file_); -void ProjectList::LoadFrom(const std::string& path) { - utils::filesystem::LockFile lock(path); - std::lock_guard guard(lock); + LoadWithouLock(); - std::ifstream in(path); + std::mt19937 rnd(std::chrono::system_clock::now().time_since_epoch().count()); + + auto RandomSymbol = [&rnd]() { + int n = rnd() % (26 + 26 + 10); + if (n < 26) { + return 'a' + n; + } else if (n < 26 + 26) { + return 'A' + n - 26; + } else { + return '0' + n - 26 - 26; + } + }; + + auto GenerateFilename = [&rnd, &RandomSymbol]() { + std::string filename; + for (size_t i = 0; i < 6; ++i) { + filename += RandomSymbol(); + } + + return filename; + }; + + auto filename = GenerateFilename(); + while (true) { + bool exist_config = false; + for (auto& project : projects_) { + if (filename == project.configuration_file.filename()) { + exist_config = true; + break; + } + } + if (!exist_config) { + break; + } + + filename = GenerateFilename(); + } + + auto path_to_config = config_directory / filename; + + std::ofstream out(path_, std::ios::ate); + out << std::filesystem::current_path() << " " << path_to_config << std::endl; + out.close(); + + projects_.emplace_back(std::filesystem::current_path(), path_to_config); + + return {path_to_config}; +} + +void ProjectList::Load() { + std::lock_guard guard(lock_file_); + + LoadWithouLock(); +} + +void ProjectList::LoadWithouLock() { + std::ifstream in(path_); Project current; diff --git a/src/clippy/project_list.hpp b/src/clippy/project_list.hpp index be5d369..2a49462 100644 --- a/src/clippy/project_list.hpp +++ b/src/clippy/project_list.hpp @@ -1,6 +1,8 @@ #pragma once #include +#include + #include #include #include @@ -8,20 +10,31 @@ struct Project { std::strong_ordering operator<=>(const Project&) const = default; + Config GetConfig() { return Config{configuration_file}; } + std::filesystem::path root_project; std::filesystem::path configuration_file; }; class ProjectList { public: - ProjectList() {} + ProjectList(std::filesystem::path path) : path_(std::move(path)), lock_file_(path_) { + Load(); + } - void LoadFrom(const std::string& path); + Config GetNewConfig(const std::filesystem::path& config_directory); const std::vector& GetProjects() const { return projects_; } std::optional GetCurrentProject(); private: + void Load(); + void LoadWithouLock(); + + private: + std::filesystem::path path_; + utils::filesystem::LockFile lock_file_; + std::vector projects_; }; diff --git a/src/clippy/target.cpp b/src/clippy/target.cpp new file mode 100644 index 0000000..8fe34e3 --- /dev/null +++ b/src/clippy/target.cpp @@ -0,0 +1,37 @@ +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 diff --git a/src/clippy/target.hpp b/src/clippy/target.hpp index 75676f5..8ac2308 100644 --- a/src/clippy/target.hpp +++ b/src/clippy/target.hpp @@ -1,8 +1,14 @@ #pragma once #include +#include #include +#include + +#define SIGPIPE_ALWAYS_IGNORE +#include +#undef SIGPIPE_ALWAYS_IGNORE #include #include @@ -20,15 +26,12 @@ class EmptyTarget : public Target { class OpenProjectConfig : public Target { public: - OpenProjectConfig(std::string config_path) : config_path_(config_path) {} + OpenProjectConfig(Config config) : config_(config) {} - void Execute() override { - utils::OpenEditor(config_path_); - std::cout << "Open editor TODO" << std::endl; - } + void Execute() override { config_.Edit(); } private: - std::string config_path_; + Config config_; }; class CreateProjectConfig : public Target { @@ -36,10 +39,35 @@ class CreateProjectConfig : public Target { CreateProjectConfig(ProjectList& projects) : projects_(projects) {} void Execute() override { - std::cout << "Make new project config and open editor TODO" << std::endl; + auto scripts_path = utils::GetProjectDirectory() / "scripts"; + std::filesystem::create_directories(scripts_path); + + auto config = projects_.GetNewConfig(scripts_path); + config.Edit(); } private: ProjectList& projects_; }; + +class RunShellScript : public Target { + public: + RunShellScript(std::vector commands) + : commands_(std::move(commands)) {} + + void Execute() override { + cppshell::Shell s; + + for (auto& i : commands_) { + std::cout << "-> " << i << std::endl; + s.Execute(i); + if (int err = s.GetExitCodeLastCommand(); err != 0) { + std::cout << "ERROR" << std::endl; + } + } + } + + private: + std::vector commands_; +}; } // namespace clippy::targets diff --git a/src/utils/config_path.hpp b/src/utils/config_path.hpp new file mode 100644 index 0000000..b901253 --- /dev/null +++ b/src/utils/config_path.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include +#include +#include +#include + +namespace utils { +inline std::filesystem::path GetProjectDirectory() { + namespace fs = std::filesystem; + using std::filesystem::path; + + path config_path = + std::string(std::getenv("HOME")) + "/.local/share/clippy-terminal/"; + + fs::create_directories(config_path); + + return config_path; +} +} // namespace utils From 6decd7bc4b643065b038bd32bab5169861b9b042 Mon Sep 17 00:00:00 2001 From: Timofey Khoruzhii Date: Thu, 11 Aug 2022 21:42:53 +0300 Subject: [PATCH 17/25] Add colored, run scripts --- CMakeLists.txt | 9 ++++++++- src/clippy/config.cpp | 1 + src/clippy/config.hpp | 4 +++- src/clippy/project_list.cpp | 2 +- src/clippy/project_list.hpp | 2 +- src/clippy/target.cpp | 37 ------------------------------------- src/clippy/target.hpp | 26 ++++++++++++++++++++++---- 7 files changed, 36 insertions(+), 45 deletions(-) delete mode 100644 src/clippy/target.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 1f095a1..ae92603 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ file(GLOB_RECURSE SOURCES_FILES src/*) add_executable(clippy_terminal ${SOURCES_FILES}) 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) @@ -19,3 +19,10 @@ FetchContent_Declare( GIT_TAG origin/main ) FetchContent_MakeAvailable(cppshell) + +FetchContent_Declare( + rang + GIT_REPOSITORY https://github.com/agauniyal/rang.git + GIT_TAG origin/master +) +FetchContent_MakeAvailable(rang) diff --git a/src/clippy/config.cpp b/src/clippy/config.cpp index a966c97..ce58288 100644 --- a/src/clippy/config.cpp +++ b/src/clippy/config.cpp @@ -23,6 +23,7 @@ std::unique_ptr Config::GetTarget( std::string current; std::vector target_commands; + target_commands.emplace_back("cd " + initial_directory_); bool target_begin = false; diff --git a/src/clippy/config.hpp b/src/clippy/config.hpp index e9927a5..e522bee 100644 --- a/src/clippy/config.hpp +++ b/src/clippy/config.hpp @@ -11,7 +11,8 @@ class Target; class Config { 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_); } @@ -19,4 +20,5 @@ class Config { private: std::string path_; + std::string initial_directory_; }; diff --git a/src/clippy/project_list.cpp b/src/clippy/project_list.cpp index b4ed2a9..2e20ec7 100644 --- a/src/clippy/project_list.cpp +++ b/src/clippy/project_list.cpp @@ -59,7 +59,7 @@ Config ProjectList::GetNewConfig( 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() { diff --git a/src/clippy/project_list.hpp b/src/clippy/project_list.hpp index 2a49462..203cbfc 100644 --- a/src/clippy/project_list.hpp +++ b/src/clippy/project_list.hpp @@ -10,7 +10,7 @@ struct Project { 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 configuration_file; diff --git a/src/clippy/target.cpp b/src/clippy/target.cpp deleted file mode 100644 index 8fe34e3..0000000 --- a/src/clippy/target.cpp +++ /dev/null @@ -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 diff --git a/src/clippy/target.hpp b/src/clippy/target.hpp index 8ac2308..3aa9933 100644 --- a/src/clippy/target.hpp +++ b/src/clippy/target.hpp @@ -10,7 +10,10 @@ #include #undef SIGPIPE_ALWAYS_IGNORE +#include + #include +#include #include namespace clippy::targets { @@ -58,11 +61,26 @@ class RunShellScript : public Target { void Execute() override { cppshell::Shell s; - for (auto& i : commands_) { - std::cout << "-> " << i << std::endl; - s.Execute(i); + for (auto& command : commands_) { + std::cout << rang::fg::green << rang::style::bold << "-> " + << rang::fg::reset << command << rang::style::reset + << std::endl; + s.Execute(command); 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; + } } } } From c308f38cea30a77a7cadf8f4353193c794e826c9 Mon Sep 17 00:00:00 2001 From: Timofey Khoruzhii Date: Thu, 11 Aug 2022 21:50:43 +0300 Subject: [PATCH 18/25] Fix replace new config in file --- src/clippy/project_list.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/clippy/project_list.cpp b/src/clippy/project_list.cpp index 2e20ec7..e2ad9f3 100644 --- a/src/clippy/project_list.cpp +++ b/src/clippy/project_list.cpp @@ -53,7 +53,7 @@ Config ProjectList::GetNewConfig( auto path_to_config = config_directory / filename; - std::ofstream out(path_, std::ios::ate); + std::ofstream out(path_, std::ios::app); out << std::filesystem::current_path() << " " << path_to_config << std::endl; out.close(); From 80ca6ad02d298b43787d21b33303d289d7d13280 Mon Sep 17 00:00:00 2001 From: Timofey Khoruzhii Date: Thu, 11 Aug 2022 21:51:04 +0300 Subject: [PATCH 19/25] Create function create new project --- src/clippy/clippy.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/clippy/clippy.cpp b/src/clippy/clippy.cpp index f5042ce..9f838e5 100644 --- a/src/clippy/clippy.cpp +++ b/src/clippy/clippy.cpp @@ -48,6 +48,12 @@ Clippy::TargetPtr Clippy::TryExecuteClippyCommand( } } + if (CheckPatternParametres(args, Parameter::Skip, "crt", + Parameter::Anything)) { + LoadProjects(); + return std::make_unique(projects_.value()); + } + return nullptr; } From dd95598c2a938ef31e5b25ff728f19b1702cfe2a Mon Sep 17 00:00:00 2001 From: Timofey Khoruzhii Date: Fri, 28 Oct 2022 23:49:52 +0300 Subject: [PATCH 20/25] Fix not virtual destructor --- src/clippy/target.hpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/clippy/target.hpp b/src/clippy/target.hpp index 3aa9933..f20f505 100644 --- a/src/clippy/target.hpp +++ b/src/clippy/target.hpp @@ -20,11 +20,13 @@ namespace clippy::targets { class Target { public: virtual void Execute() = 0; + virtual ~Target() = 0; }; class EmptyTarget : public Target { public: void Execute() override {} + ~EmptyTarget() override {} }; class OpenProjectConfig : public Target { @@ -32,6 +34,7 @@ class OpenProjectConfig : public Target { OpenProjectConfig(Config config) : config_(config) {} void Execute() override { config_.Edit(); } + ~OpenProjectConfig() override {} private: Config config_; @@ -48,6 +51,7 @@ class CreateProjectConfig : public Target { auto config = projects_.GetNewConfig(scripts_path); config.Edit(); } + ~CreateProjectConfig() override {} private: ProjectList& projects_; @@ -85,6 +89,8 @@ class RunShellScript : public Target { } } + ~RunShellScript() override {} + private: std::vector commands_; }; From d441213c58707262e0342665739d73b919e5d08c Mon Sep 17 00:00:00 2001 From: Timofey Khoruzhii Date: Fri, 28 Oct 2022 23:59:47 +0300 Subject: [PATCH 21/25] Fix compile errors --- src/clippy/project_list.hpp | 5 +++++ src/clippy/target.hpp | 2 +- src/utils/parametres.hpp | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/clippy/project_list.hpp b/src/clippy/project_list.hpp index 203cbfc..5cefefe 100644 --- a/src/clippy/project_list.hpp +++ b/src/clippy/project_list.hpp @@ -8,6 +8,11 @@ #include struct Project { + Project() {} + + Project(std::filesystem::path root_project, std::filesystem::path configuration_file) + : root_project(root_project), configuration_file(configuration_file) {} + std::strong_ordering operator<=>(const Project&) const = default; Config GetConfig() { return Config{configuration_file, root_project}; } diff --git a/src/clippy/target.hpp b/src/clippy/target.hpp index f20f505..2184833 100644 --- a/src/clippy/target.hpp +++ b/src/clippy/target.hpp @@ -20,7 +20,7 @@ namespace clippy::targets { class Target { public: virtual void Execute() = 0; - virtual ~Target() = 0; + virtual ~Target() = default; }; class EmptyTarget : public Target { diff --git a/src/utils/parametres.hpp b/src/utils/parametres.hpp index edbcdd5..0e64edd 100644 --- a/src/utils/parametres.hpp +++ b/src/utils/parametres.hpp @@ -19,7 +19,7 @@ bool CheckPatternParametresImpl(const std::vector& args, } template , bool>> + std::enable_if_t, bool> = true> bool CheckPatternParametresImpl(const std::vector& args, T&& head, Args&&... pattern); @@ -40,7 +40,7 @@ bool CheckPatternParametresImpl(const std::vector& args, T&& p, } template , bool> = true> + std::enable_if_t, bool>> bool CheckPatternParametresImpl(const std::vector& args, T&& head, Args&&... pattern) { if (index >= args.size()) { From bb0480c1020b3b6b50c8e678ae37ed75c88eaca3 Mon Sep 17 00:00:00 2001 From: Timofey Khoruzhii Date: Sat, 29 Oct 2022 00:07:18 +0300 Subject: [PATCH 22/25] Add error output if unsupported parameters --- src/clippy/clippy.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/clippy/clippy.cpp b/src/clippy/clippy.cpp index 9f838e5..c5a4317 100644 --- a/src/clippy/clippy.cpp +++ b/src/clippy/clippy.cpp @@ -9,6 +9,8 @@ #include #include +#include + void Clippy::Run(const std::vector& args) { if (auto result = TryExecuteClippyCommand(args); result) { result->Execute(); @@ -18,6 +20,12 @@ void Clippy::Run(const std::vector& args) { result->Execute(); return; } + + std::cout << rang::bg::red << rang::style::bold << "Unsupported parameters { "; + for (size_t i = 1; i < args.size(); ++i) { + std::cout << args[i] << (i + 1 == args.size() ? "" : ",") << " "; + } + std::cout << "}" << std::endl << rang::bg::reset << rang::style::reset; } Clippy::TargetPtr Clippy::TryExecuteClippyCommand( From 321344a4c911c2ede60680161ec0c9eafc6f2ce3 Mon Sep 17 00:00:00 2001 From: Timofey Khoruzhii Date: Sat, 29 Oct 2022 09:38:26 +0300 Subject: [PATCH 23/25] Add support aliases --- src/clippy/clippy.cpp | 6 +++++- src/clippy/clippy.hpp | 3 +++ src/clippy/config.cpp | 5 ++--- src/clippy/config.hpp | 3 ++- src/clippy/target.hpp | 16 +++++++++++----- src/utils/editor.cpp | 2 -- 6 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/clippy/clippy.cpp b/src/clippy/clippy.cpp index c5a4317..b961ccd 100644 --- a/src/clippy/clippy.cpp +++ b/src/clippy/clippy.cpp @@ -75,7 +75,11 @@ Clippy::TargetPtr Clippy::GetScriptTarget( } auto cfg = p->GetConfig(); - return cfg.GetTarget(args[1]); + auto result = cfg.GetTarget(args[1]); + if (enable_aliases_) { + result->PushFront("shopt -s expand_aliases"); + } + return result; } void Clippy::LoadProjects() { diff --git a/src/clippy/clippy.hpp b/src/clippy/clippy.hpp index 42c1d3e..7dc83f0 100644 --- a/src/clippy/clippy.hpp +++ b/src/clippy/clippy.hpp @@ -9,6 +9,8 @@ class Clippy { public: + Clippy(bool enable_aliases = true) : enable_aliases_(enable_aliases) {} + void Run(const std::vector& args); using TargetPtr = std::unique_ptr; @@ -18,5 +20,6 @@ class Clippy { void LoadProjects(); + bool enable_aliases_; std::optional projects_; }; diff --git a/src/clippy/config.cpp b/src/clippy/config.cpp index ce58288..c0becba 100644 --- a/src/clippy/config.cpp +++ b/src/clippy/config.cpp @@ -17,7 +17,7 @@ std::string Strip(std::string s) { return s; } -std::unique_ptr Config::GetTarget( +std::unique_ptr Config::GetTarget( const std::string& target) { std::ifstream in(path_); @@ -48,6 +48,5 @@ std::unique_ptr Config::GetTarget( return nullptr; } - return std::make_unique( - std::move(target_commands)); + return std::make_unique(target_commands); } diff --git a/src/clippy/config.hpp b/src/clippy/config.hpp index e522bee..01f9b27 100644 --- a/src/clippy/config.hpp +++ b/src/clippy/config.hpp @@ -7,6 +7,7 @@ namespace clippy::targets { class Target; +class RunShellScript; } class Config { @@ -16,7 +17,7 @@ class Config { void Edit() { utils::OpenEditor(path_); } - std::unique_ptr GetTarget(const std::string& target); + std::unique_ptr GetTarget(const std::string& target); private: std::string path_; diff --git a/src/clippy/target.hpp b/src/clippy/target.hpp index 2184833..5ed303b 100644 --- a/src/clippy/target.hpp +++ b/src/clippy/target.hpp @@ -6,9 +6,7 @@ #include #include -#define SIGPIPE_ALWAYS_IGNORE #include -#undef SIGPIPE_ALWAYS_IGNORE #include @@ -59,8 +57,16 @@ class CreateProjectConfig : public Target { class RunShellScript : public Target { public: - RunShellScript(std::vector commands) - : commands_(std::move(commands)) {} + template