summaryrefslogtreecommitdiffstats
path: root/src/command_executor.hh
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-07 04:48:35 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-07 04:48:35 +0000
commit207df6fc406e81bfeebdff7f404bd242ff3f099f (patch)
treea1a796b056909dd0a04ffec163db9363a8757808 /src/command_executor.hh
parentReleasing progress-linux version 0.11.2-1~progress7.99u1. (diff)
downloadlnav-207df6fc406e81bfeebdff7f404bd242ff3f099f.tar.xz
lnav-207df6fc406e81bfeebdff7f404bd242ff3f099f.zip
Merging upstream version 0.12.2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/command_executor.hh')
-rw-r--r--src/command_executor.hh128
1 files changed, 114 insertions, 14 deletions
diff --git a/src/command_executor.hh b/src/command_executor.hh
index 4461d55..ea29451 100644
--- a/src/command_executor.hh
+++ b/src/command_executor.hh
@@ -38,7 +38,7 @@
#include "base/auto_fd.hh"
#include "base/lnav.console.hh"
-#include "bookmarks.hh"
+#include "db_sub_source.hh"
#include "fmt/format.h"
#include "ghc/filesystem.hpp"
#include "help_text.hh"
@@ -72,15 +72,9 @@ struct exec_context {
sql_callback_t sql_callback = ::sql_callback,
pipe_callback_t pipe_callback = nullptr);
- bool is_read_write() const
- {
- return this->ec_perms == perm_t::READ_WRITE;
- }
+ bool is_read_write() const { return this->ec_perms == perm_t::READ_WRITE; }
- bool is_read_only() const
- {
- return this->ec_perms == perm_t::READ_ONLY;
- }
+ bool is_read_only() const { return this->ec_perms == perm_t::READ_ONLY; }
exec_context& with_perms(perm_t perms)
{
@@ -91,15 +85,22 @@ struct exec_context {
void add_error_context(lnav::console::user_message& um);
template<typename... Args>
- Result<std::string, lnav::console::user_message> make_error(
- fmt::string_view format_str, const Args&... args)
+ lnav::console::user_message make_error_msg(fmt::string_view format_str,
+ const Args&... args)
{
auto retval = lnav::console::user_message::error(
fmt::vformat(format_str, fmt::make_format_args(args...)));
this->add_error_context(retval);
- return Err(retval);
+ return retval;
+ }
+
+ template<typename... Args>
+ Result<std::string, lnav::console::user_message> make_error(
+ fmt::string_view format_str, const Args&... args)
+ {
+ return Err(this->make_error_msg(format_str, args...));
}
nonstd::optional<FILE*> get_output()
@@ -120,6 +121,45 @@ struct exec_context {
void clear_output();
+ struct mouse_input {};
+ struct user {};
+ struct file_open {
+ std::string fo_name;
+ };
+
+ using provenance_t = mapbox::util::variant<user, mouse_input, file_open>;
+
+ struct provenance_guard {
+ explicit provenance_guard(exec_context* context, provenance_t prov)
+ : pg_context(context)
+ {
+ this->pg_context->ec_provenance.push_back(prov);
+ }
+
+ provenance_guard(const provenance_guard&) = delete;
+ provenance_guard(provenance_guard&& other)
+ : pg_context(other.pg_context)
+ {
+ other.pg_context = nullptr;
+ }
+
+ ~provenance_guard()
+ {
+ if (this->pg_context != nullptr) {
+ this->pg_context->ec_provenance.pop_back();
+ }
+ }
+
+ exec_context* operator->() { return this->pg_context; }
+
+ exec_context* pg_context;
+ };
+
+ provenance_guard with_provenance(provenance_t prov)
+ {
+ return provenance_guard{this, prov};
+ }
+
struct source_guard {
source_guard(exec_context* context) : sg_context(context) {}
@@ -155,6 +195,33 @@ struct exec_context {
int line_number,
const std::string& content);
+ struct db_source_guard {
+ db_source_guard(exec_context* context) : dsg_context(context) {}
+
+ db_source_guard(const source_guard&) = delete;
+
+ db_source_guard(source_guard&& other) : dsg_context(other.sg_context)
+ {
+ other.sg_context = nullptr;
+ }
+
+ ~db_source_guard()
+ {
+ if (this->dsg_context != nullptr) {
+ this->dsg_context->ec_label_source_stack.pop_back();
+ }
+ }
+
+ exec_context* dsg_context;
+ };
+
+ db_source_guard enter_db_source(db_label_source* dls)
+ {
+ this->ec_label_source_stack.push_back(dls);
+
+ return db_source_guard{this};
+ }
+
struct error_cb_guard {
error_cb_guard(exec_context* context) : sg_context(context) {}
@@ -214,13 +281,25 @@ struct exec_context {
this->ec_local_vars.pop();
}
+ template<typename T>
+ nonstd::optional<T> get_provenance() const
+ {
+ for (const auto& elem : this->ec_provenance) {
+ if (elem.is<T>()) {
+ return elem.get<T>();
+ }
+ }
+
+ return nonstd::nullopt;
+ }
+
vis_line_t ec_top_line{0_vl};
bool ec_dry_run{false};
perm_t ec_perms{perm_t::READ_WRITE};
- std::map<std::string, std::string> ec_override;
logline_value_vector* ec_line_values;
std::stack<std::map<std::string, scoped_value_t>> ec_local_vars;
+ std::vector<provenance_t> ec_provenance;
std::map<std::string, scoped_value_t> ec_global_vars;
std::vector<ghc::filesystem::path> ec_path_stack;
std::vector<lnav::console::snippet> ec_source;
@@ -234,6 +313,7 @@ struct exec_context {
sql_callback_t ec_sql_callback;
pipe_callback_t ec_pipe_callback;
std::vector<error_callback_t> ec_error_callback_stack;
+ std::vector<db_label_source*> ec_label_source_stack;
};
Result<std::string, lnav::console::user_message> execute_command(
@@ -241,8 +321,28 @@ Result<std::string, lnav::console::user_message> execute_command(
Result<std::string, lnav::console::user_message> execute_sql(
exec_context& ec, const std::string& sql, std::string& alt_msg);
+
+class multiline_executor {
+public:
+ exec_context& me_exec_context;
+ std::string me_source;
+ nonstd::optional<std::string> me_cmdline;
+ int me_line_number{0};
+ int me_starting_line_number{0};
+ std::string me_last_result;
+
+ multiline_executor(exec_context& ec, std::string src)
+ : me_exec_context(ec), me_source(src)
+ {
+ }
+
+ Result<void, lnav::console::user_message> push_back(string_fragment line);
+
+ Result<std::string, lnav::console::user_message> final();
+};
+
Result<std::string, lnav::console::user_message> execute_file(
- exec_context& ec, const std::string& path_and_args, bool multiline = true);
+ exec_context& ec, const std::string& path_and_args);
Result<std::string, lnav::console::user_message> execute_any(
exec_context& ec, const std::string& cmdline);
void execute_init_commands(