aboutsummaryrefslogtreecommitdiffstats
path: root/eval
diff options
context:
space:
mode:
authorHåvard Pettersen <havardpe@oath.com>2021-09-02 13:53:18 +0000
committerHåvard Pettersen <havardpe@oath.com>2021-09-02 13:53:18 +0000
commitd69c10f5c2b8254d3fdfa135fc14538913599b8f (patch)
tree94bae2b88e618f3136bb46296a54b8c4c65ee0d8 /eval
parent25931432f58e53fb90068c143f61ee638dc54d69 (diff)
added help and list commands to interactive mode
Diffstat (limited to 'eval')
-rw-r--r--eval/src/apps/eval_expr/eval_expr.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/eval/src/apps/eval_expr/eval_expr.cpp b/eval/src/apps/eval_expr/eval_expr.cpp
index 60040a175c7..19e7369414e 100644
--- a/eval/src/apps/eval_expr/eval_expr.cpp
+++ b/eval/src/apps/eval_expr/eval_expr.cpp
@@ -48,6 +48,8 @@ int usage(const char *self) {
fprintf(stderr, "advanced usage: %s interactive\n", self);
fprintf(stderr, " This runs the progam in interactive mode. possible commands (line based):\n");
fprintf(stderr, " 'exit' -> exit the program\n");
+ fprintf(stderr, " 'help' -> print available commands\n");
+ fprintf(stderr, " 'list' -> list named values\n");
fprintf(stderr, " 'verbose (true|false)' -> enable or disable verbose output\n");
fprintf(stderr, " 'def <name> <expr>' -> evaluate expression, bind result to a name\n");
fprintf(stderr, " '<expr>' -> evaluate expression\n");
@@ -99,6 +101,10 @@ public:
void verbose(bool value) { _verbose = value; }
bool verbose() const { return _verbose; }
+ size_t size() const { return _param_names.size(); }
+ const vespalib::string &name(size_t idx) const { return _param_names[idx]; }
+ const ValueType &type(size_t idx) const { return _param_types[idx]; }
+
Value::UP eval(const vespalib::string &expr) {
clear_state();
SimpleObjectParams params(_param_refs);
@@ -254,6 +260,8 @@ EditLineWrapper::~EditLineWrapper()
vespalib::string EditLineWrapper::prompt("> ");
const vespalib::string exit_cmd("exit");
+const vespalib::string help_cmd("help");
+const vespalib::string list_cmd("list");
const vespalib::string verbose_cmd("verbose ");
const vespalib::string def_cmd("def ");
@@ -264,6 +272,21 @@ int interactive_mode(Context &ctx) {
if (line == exit_cmd) {
return 0;
}
+ if (line == help_cmd) {
+ fprintf(stdout, " 'exit' -> exit the program\n");
+ fprintf(stdout, " 'help' -> print available commands\n");
+ fprintf(stdout, " 'list' -> list named values\n");
+ fprintf(stdout, " 'verbose (true|false)' -> enable or disable verbose output\n");
+ fprintf(stdout, " 'def <name> <expr>' -> evaluate expression, bind result to a name\n");
+ fprintf(stdout, " '<expr>' -> evaluate expression\n");
+ continue;
+ }
+ if (line == list_cmd) {
+ for (size_t i = 0; i < ctx.size(); ++i) {
+ fprintf(stdout, " %s: %s\n", ctx.name(i).c_str(), ctx.type(i).to_spec().c_str());
+ }
+ continue;
+ }
if (line.find(verbose_cmd) == 0) {
auto flag_str = line.substr(verbose_cmd.size());
bool flag = (flag_str == "true");