#ifndef _CLI_COMMAND_LIST_H_
#define _CLI_COMMAND_LIST_H_

#include <command/Command.h>

namespace cli {

class CommandList final : public Command {
	ext::vector < std::unique_ptr < Command > > m_commands;

public:
	CommandList ( ext::vector < std::unique_ptr < Command > > commands ) : m_commands ( std::move ( commands ) ) {
	}

	Command::Result run ( Environment & environment ) const override {
		if ( m_commands.empty ( ) )
			throw std::invalid_argument ( "Command list can't be empty" );

		Command::Result res = Command::Result::OK;
		for ( size_t i = 0; i < m_commands.size ( ) && res == Command::Result::OK; ++ i )
			res = m_commands [ i ]->run ( environment );

		return res;
	}

	void append ( std::unique_ptr < Command > command ) {
		m_commands.emplace_back ( std::move ( command ) );
	}

};

} /* namespace cli */

#endif /* _CLI_COMMAND_LIST_H_ */
