Skip to content
Snippets Groups Projects
Commit 1d4fd8e7 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

add stub for help command in cli

parent 6e4b1e84
No related branches found
No related tags found
No related merge requests found
#ifndef _CLI_HELP_COMMAND_H_
#define _CLI_HELP_COMMAND_H_
#include <command/Command.h>
#include <environment/Environment.h>
namespace cli {
class HelpCommand : public Command {
std::string m_command;
public:
HelpCommand ( std::string command ) : m_command ( std::move ( command ) ) {
}
virtual Command::Result run ( Environment & ) const override {
if ( m_command == "execute" ) {
std::cout << "Execute command executes statements and either prints the result or writes the result to a file" << std::endl;
} else if ( m_command == "export" ) {
std::cout << "Export command stores the result of statements in a variable" << std::endl;
std::cout << "" << std::endl;
std::cout << "Syntax:" << std::endl;
std::cout << "execute variable = statement_list" << std::endl;
std::cout << "" << std::endl;
std::cout << "variable is an identifier under which the result should be stored." << std::endl;
std::cout << "for details of syntax of statement_list see help of execute statement." << std::endl;
} else if ( m_command == "" ) {
std::cout << "Simple help for the query language" << std::endl;
std::cout << "" << std::endl;
std::cout << "command quit: quits the processor." << std::endl;
std::cout << "command help: shows this help." << std::endl;
std::cout << "command export: stores the result of statements into a variable" << std::endl;
std::cout << "command execute: executes statements" << std::endl;
std::cout << "" << std::endl;
std::cout << "for details use help of individual command" << std::endl;
} else {
std::cout << "The command " << m_command << " either does not exist or does not have a help entry." << std::endl;
}
return Command::Result::OK;
}
};
} /* namespace cli */
#endif /* _CLI_HELP_COMMAND_H_ */
......@@ -19,6 +19,7 @@
#include <command/ExecuteCommand.h>
#include <command/ExportCommand.h>
#include <command/QuitCommand.h>
#include <command/HelpCommand.h>
 
#include <primitive/Integer.h>
#include <primitive/String.h>
......@@ -144,6 +145,14 @@ void Parser::result ( std::shared_ptr < StatementList > & list ) {
}
}
 
std::string Parser::help_parameter ( ) {
if ( check ( cli::Lexer::TokenType::IDENTIFIER ) ) {
return matchIdentifier ( );
} else {
return "";
}
}
std::unique_ptr < Command > Parser::parse ( ) {
if ( check_nonreserved_kw ( "execute" ) ) {
match_nonreserved_kw ( "execute" );
......@@ -163,6 +172,11 @@ std::unique_ptr < Command > Parser::parse ( ) {
match_nonreserved_kw ( "quit" );
match ( cli::Lexer::TokenType::END );
return std::make_unique < QuitCommand > ( );
} else if ( check_nonreserved_kw ( "help" ) ) {
match_nonreserved_kw ( "help" );
std::string command = help_parameter ( );
match ( cli::Lexer::TokenType::END );
return std::make_unique < HelpCommand > ( std::move ( command ) );
} else {
throw exception::CommonException ( "Mismatched set while expanding param rule." );
}
......
......@@ -84,6 +84,8 @@ public:
 
void result ( std::shared_ptr < StatementList > & list );
 
std::string help_parameter ( );
std::unique_ptr < Command > parse ( );
 
};
......
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