Skip to content
Snippets Groups Projects
Commit 430f6486 authored by Ondřej Štorc's avatar Ondřej Štorc
Browse files

cli: Use REPL in cli

parent f0c6441d
No related branches found
No related tags found
1 merge request!256Parser replacement with ANTLR
......@@ -39,6 +39,7 @@ std::istream& operator>>(std::istream& in, std::pair<T, U>& value)
 
#include <common/ResultInterpret.h>
 
#include "REPL.h"
#include "aql.h"
 
namespace TCLAP {
......@@ -66,7 +67,6 @@ class InteractiveVisitor : public TCLAP::Visitor {
public:
void visit() override
{
Prompt::getPrompt().appendCharSequence(ReadlineLineInterface(true));
}
};
 
......@@ -93,6 +93,7 @@ class QueriesVisitor : public MultiArgVisitor {
public:
void visit() override
{
std::istringstream iss{m_arg->getValue().back()};
Prompt::getPrompt().appendCharSequence(cli::StringLineInterface(m_arg->getValue().back()));
}
};
......@@ -174,15 +175,15 @@ int main(int argc, char* argv[])
 
/* --------------------------------------------------------------------------------------------------------- */
 
bool runInteractive = interactive.isSet();
// if no -f, -c, or -i, go interactive.
if (!queries.isSet() && !files.isSet() && !interactive.isSet()) {
if (isatty(fileno(stdin)) || interactive.isSet())
Prompt::getPrompt().appendCharSequence(ReadlineLineInterface(true));
runInteractive = true;
else
Prompt::getPrompt().appendCharSequence(cli::IstreamLineInterface<std::istream&>(std::cin));
}
 
cli::CommandResult res = Prompt::getPrompt().run();
 
/* --------------------------------------------------------------------------------------------------------- */
 
......@@ -190,6 +191,8 @@ int main(int argc, char* argv[])
delete fileVisitor;
delete interactiveVisitor;
 
cli::CommandResult res = Prompt::getPrompt().run(runInteractive);
if (res == cli::CommandResult::QUIT || res == cli::CommandResult::RETURN)
return cli::ResultInterpret::cli(Prompt::getPrompt().getEnvironment().getResult());
else if (res == cli::CommandResult::EOT || res == cli::CommandResult::OK)
......
#include <global/GlobalData.h>
#include "Prompt.h"
#include "REPL.h"
 
Prompt::Prompt(cli::Environment environment)
: m_environment(std::move(environment))
{
}
 
cli::CommandResult Prompt::run()
cli::CommandResult Prompt::run(bool runInteractive)
{
cli::CommandResult res = cli::CommandResult::OK;
 
......@@ -28,5 +29,10 @@ cli::CommandResult Prompt::run()
m_lineInterfaces.pop_front();
}
 
if (runInteractive) {
REPL repl;
res = repl.run(getEnvironment());
}
return res;
}
......@@ -38,7 +38,7 @@ public:
m_lineInterfaces.push_front(std::make_shared<LineInterface>(std::forward<LineInterface>(lineInterface)));
}
 
cli::CommandResult run();
cli::CommandResult run(bool runInteractive);
 
cli::Environment& getEnvironment()
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment