Add support aliases
This commit is contained in:
parent
bb0480c102
commit
321344a4c9
|
@ -75,7 +75,11 @@ Clippy::TargetPtr Clippy::GetScriptTarget(
|
||||||
}
|
}
|
||||||
|
|
||||||
auto cfg = p->GetConfig();
|
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() {
|
void Clippy::LoadProjects() {
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
|
|
||||||
class Clippy {
|
class Clippy {
|
||||||
public:
|
public:
|
||||||
|
Clippy(bool enable_aliases = true) : enable_aliases_(enable_aliases) {}
|
||||||
|
|
||||||
void Run(const std::vector<std::string>& args);
|
void Run(const std::vector<std::string>& args);
|
||||||
|
|
||||||
using TargetPtr = std::unique_ptr<clippy::targets::Target>;
|
using TargetPtr = std::unique_ptr<clippy::targets::Target>;
|
||||||
|
@ -18,5 +20,6 @@ class Clippy {
|
||||||
|
|
||||||
void LoadProjects();
|
void LoadProjects();
|
||||||
|
|
||||||
|
bool enable_aliases_;
|
||||||
std::optional<ProjectList> projects_;
|
std::optional<ProjectList> projects_;
|
||||||
};
|
};
|
||||||
|
|
|
@ -17,7 +17,7 @@ std::string Strip(std::string s) {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<clippy::targets::Target> Config::GetTarget(
|
std::unique_ptr<clippy::targets::RunShellScript> Config::GetTarget(
|
||||||
const std::string& target) {
|
const std::string& target) {
|
||||||
std::ifstream in(path_);
|
std::ifstream in(path_);
|
||||||
|
|
||||||
|
@ -48,6 +48,5 @@ std::unique_ptr<clippy::targets::Target> Config::GetTarget(
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::make_unique<clippy::targets::RunShellScript>(
|
return std::make_unique<clippy::targets::RunShellScript>(target_commands);
|
||||||
std::move(target_commands));
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
namespace clippy::targets {
|
namespace clippy::targets {
|
||||||
class Target;
|
class Target;
|
||||||
|
class RunShellScript;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Config {
|
class Config {
|
||||||
|
@ -16,7 +17,7 @@ class Config {
|
||||||
|
|
||||||
void Edit() { utils::OpenEditor(path_); }
|
void Edit() { utils::OpenEditor(path_); }
|
||||||
|
|
||||||
std::unique_ptr<clippy::targets::Target> GetTarget(const std::string& target);
|
std::unique_ptr<clippy::targets::RunShellScript> GetTarget(const std::string& target);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string path_;
|
std::string path_;
|
||||||
|
|
|
@ -6,9 +6,7 @@
|
||||||
#include <utils/editor.hpp>
|
#include <utils/editor.hpp>
|
||||||
#include <utils/config_path.hpp>
|
#include <utils/config_path.hpp>
|
||||||
|
|
||||||
#define SIGPIPE_ALWAYS_IGNORE
|
|
||||||
#include <cppshell/shell.hpp>
|
#include <cppshell/shell.hpp>
|
||||||
#undef SIGPIPE_ALWAYS_IGNORE
|
|
||||||
|
|
||||||
#include <rang.hpp>
|
#include <rang.hpp>
|
||||||
|
|
||||||
|
@ -59,8 +57,16 @@ class CreateProjectConfig : public Target {
|
||||||
|
|
||||||
class RunShellScript : public Target {
|
class RunShellScript : public Target {
|
||||||
public:
|
public:
|
||||||
RunShellScript(std::vector<std::string> commands)
|
template <template <typename, typename...> class C, typename... Params>
|
||||||
: commands_(std::move(commands)) {}
|
RunShellScript(const C<std::string, Params...>& commands) : commands_(commands.begin(), commands.end()) {}
|
||||||
|
|
||||||
|
void PushBack(const std::string& command) {
|
||||||
|
commands_.push_back(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PushFront(const std::string& command) {
|
||||||
|
commands_.push_front(command);
|
||||||
|
}
|
||||||
|
|
||||||
void Execute() override {
|
void Execute() override {
|
||||||
cppshell::Shell s;
|
cppshell::Shell s;
|
||||||
|
@ -92,6 +98,6 @@ class RunShellScript : public Target {
|
||||||
~RunShellScript() override {}
|
~RunShellScript() override {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<std::string> commands_;
|
std::deque<std::string> commands_;
|
||||||
};
|
};
|
||||||
} // namespace clippy::targets
|
} // namespace clippy::targets
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
#include <utils/editor.hpp>
|
#include <utils/editor.hpp>
|
||||||
|
|
||||||
#define SIGPIPE_ALWAYS_IGNORE
|
|
||||||
#include <cppshell/shell.hpp>
|
#include <cppshell/shell.hpp>
|
||||||
#undef SIGPIPE_ALWAYS_IGNORE
|
|
||||||
|
|
||||||
namespace utils {
|
namespace utils {
|
||||||
void OpenEditor(const std::string& file) {
|
void OpenEditor(const std::string& file) {
|
||||||
|
|
Loading…
Reference in a new issue