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

add set command to cli

parent f9105219
No related branches found
No related tags found
No related merge requests found
#ifndef _CLI_SET_COMMAND_H_
#define _CLI_SET_COMMAND_H_
#include <command/Command.h>
#include <environment/Environment.h>
#include <global/GlobalData.h>
namespace cli {
class SetCommand : public Command {
std::string m_param;
std::string m_value;
public:
SetCommand ( std::string param, std::string value ) : m_param ( std::move ( param ) ), m_value ( std::move ( value ) ) {
}
virtual Command::Result run ( Environment & ) const override {
if ( m_param == "verbose" ) {
common::GlobalData::verbose = std::from_string < bool > ( m_value );
} else if ( m_param == "measure" ) {
common::GlobalData::measure = std::from_string < bool > ( m_value );
} else if ( m_param == "optimizeXml" ) {
common::GlobalData::optimizeXml = std::from_string < bool > ( m_value );
} else {
std::cout << "The set parameter " << m_param << " does not exist." << std::endl;
}
return Command::Result::OK;
}
};
} /* namespace cli */
#endif /* _CLI_SET_COMMAND_H_ */
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <command/QuitCommand.h> #include <command/QuitCommand.h>
#include <command/HelpCommand.h> #include <command/HelpCommand.h>
#include <command/IntrospectionCommand.h> #include <command/IntrospectionCommand.h>
#include <command/SetCommand.h>
   
#include <primitive/Integer.h> #include <primitive/Integer.h>
#include <primitive/String.h> #include <primitive/String.h>
...@@ -196,6 +197,13 @@ std::unique_ptr < Command > Parser::parse ( ) { ...@@ -196,6 +197,13 @@ std::unique_ptr < Command > Parser::parse ( ) {
std::string command = optional_identifier ( ); std::string command = optional_identifier ( );
match ( cli::Lexer::TokenType::END ); match ( cli::Lexer::TokenType::END );
return std::make_unique < IntrospectionCommand > ( std::move ( command ) ); return std::make_unique < IntrospectionCommand > ( std::move ( command ) );
} else if ( check_nonreserved_kw ( "set" ) ) {
match_nonreserved_kw ( "set" );
std::string param = matchIdentifier ( );
std::string value = getTokenValue ( );
match ( cli::Lexer::TokenType::INTEGER, cli::Lexer::TokenType::IDENTIFIER );
match ( cli::Lexer::TokenType::END );
return std::make_unique < SetCommand > ( std::move ( param ), std::move ( value ) );
} else { } else {
throw exception::CommonException ( "Mismatched set while expanding param rule." ); throw exception::CommonException ( "Mismatched set while expanding param rule." );
} }
......
...@@ -25,6 +25,14 @@ int from_string ( const string & value ) { ...@@ -25,6 +25,14 @@ int from_string ( const string & value ) {
return stoi__private ( value.c_str() ); return stoi__private ( value.c_str() );
} }
   
template < >
bool from_string ( const string & value ) {
if ( value == "true" || value == "1" )
return true;
else
return false;
}
template < > template < >
long from_string ( const string & value ) { long from_string ( const string & value ) {
return stol__private ( value.c_str() ); return stol__private ( value.c_str() );
......
...@@ -39,6 +39,9 @@ string from_string ( const string & value ); ...@@ -39,6 +39,9 @@ string from_string ( const string & value );
template < > template < >
int from_string ( const string & value ); int from_string ( const string & value );
   
template < >
bool from_string ( const string & value );
template < > template < >
long from_string ( const string & value ); long from_string ( const string & value );
   
......
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