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