src/CLIParser.h
branchv_0
changeset 12 e8aae4d42c01
parent 11 07247893054e
child 13 326935d1bfab
equal deleted inserted replaced
11:07247893054e 12:e8aae4d42c01
    46 		else throw relpipe::cli::RelpipeCLIException(L"Unable to parse boolean value: " + value + L" (expecting true or false)", relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
    46 		else throw relpipe::cli::RelpipeCLIException(L"Unable to parse boolean value: " + value + L" (expecting true or false)", relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
    47 	}
    47 	}
    48 
    48 
    49 public:
    49 public:
    50 
    50 
    51 	static const relpipe::common::type::StringX OPTION_JACK_CLIENT_NAME;
    51 	static const relpipe::common::type::StringX OPTION_CLIENT;
    52 	static const relpipe::common::type::StringX OPTION_JACK_CONNECT_TO_PORT;
    52 	static const relpipe::common::type::StringX OPTION_PORT;
    53 	static const relpipe::common::type::StringX OPTION_REQUIRED_JACK_CONNECTIONS;
    53 	static const relpipe::common::type::StringX OPTION_CONNECT_TO;
    54 	static const relpipe::common::type::StringX OPTION_LIST_JACK_PORTS;
    54 	static const relpipe::common::type::StringX OPTION_REQUIRED_CONNECTIONS;
       
    55 	static const relpipe::common::type::StringX OPTION_LIST_PORTS;
    55 	static const relpipe::common::type::StringX OPTION_LIST_MIDI_MESSAGES;
    56 	static const relpipe::common::type::StringX OPTION_LIST_MIDI_MESSAGES;
    56 
    57 
    57 	Configuration parse(const std::vector<relpipe::common::type::StringX>& arguments) {
    58 	Configuration parse(const std::vector<relpipe::common::type::StringX>& arguments) {
    58 		Configuration c;
    59 		Configuration c;
    59 
    60 
    60 		for (int i = 0; i < arguments.size();) {
    61 		for (int i = 0; i < arguments.size();) {
    61 			relpipe::common::type::StringX option = readNext(arguments, i);
    62 			relpipe::common::type::StringX option = readNext(arguments, i);
    62 
    63 
    63 			if (option == OPTION_JACK_CLIENT_NAME) {
    64 			if (option == OPTION_CLIENT) {
    64 				c.jackClientName = readNext(arguments, i);
    65 				c.client = readNext(arguments, i);
    65 			} else if (option == OPTION_JACK_CONNECT_TO_PORT) {
    66 			} else if (option == OPTION_PORT) {
    66 				c.portsToConnect.push_back(readNext(arguments, i));
    67 				c.port = readNext(arguments, i);
    67 			} else if (option == OPTION_REQUIRED_JACK_CONNECTIONS) {
    68 			} else if (option == OPTION_CONNECT_TO) {
    68 				c.requiredJackConnections = std::stoi(readNext(arguments, i));
    69 				c.connectTo.push_back(readNext(arguments, i));
    69 			} else if (option == OPTION_LIST_JACK_PORTS) {
    70 			} else if (option == OPTION_REQUIRED_CONNECTIONS) {
    70 				c.listJackPorts = parseBoolean(readNext(arguments, i));
    71 				c.requiredConnections = std::stoi(readNext(arguments, i));
       
    72 			} else if (option == OPTION_LIST_PORTS) {
       
    73 				c.listPorts = parseBoolean(readNext(arguments, i));
    71 			} else if (option == OPTION_LIST_MIDI_MESSAGES) {
    74 			} else if (option == OPTION_LIST_MIDI_MESSAGES) {
    72 				c.listMidiMessages = parseBoolean(readNext(arguments, i));
    75 				c.listMidiMessages = parseBoolean(readNext(arguments, i));
    73 			} else throw relpipe::cli::RelpipeCLIException(L"Unsupported CLI option: " + option, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
    76 			} else throw relpipe::cli::RelpipeCLIException(L"Unsupported CLI option: " + option, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
    74 		}
    77 		}
    75 
    78 
    78 
    81 
    79 	virtual ~CLIParser() {
    82 	virtual ~CLIParser() {
    80 	}
    83 	}
    81 };
    84 };
    82 
    85 
    83 const relpipe::common::type::StringX CLIParser::OPTION_JACK_CLIENT_NAME = L"--jack-client-name";
    86 const relpipe::common::type::StringX CLIParser::OPTION_CLIENT = L"--client";
    84 const relpipe::common::type::StringX CLIParser::OPTION_JACK_CONNECT_TO_PORT = L"--jack-connect-to-port";
    87 const relpipe::common::type::StringX CLIParser::OPTION_PORT = L"--port";
    85 const relpipe::common::type::StringX CLIParser::OPTION_REQUIRED_JACK_CONNECTIONS = L"--required-jack-connections";
    88 const relpipe::common::type::StringX CLIParser::OPTION_CONNECT_TO = L"--connect-to";
    86 const relpipe::common::type::StringX CLIParser::OPTION_LIST_JACK_PORTS = L"--list-jack-ports";
    89 const relpipe::common::type::StringX CLIParser::OPTION_REQUIRED_CONNECTIONS = L"--required-connections";
       
    90 const relpipe::common::type::StringX CLIParser::OPTION_LIST_PORTS = L"--list-ports";
    87 const relpipe::common::type::StringX CLIParser::OPTION_LIST_MIDI_MESSAGES = L"--list-midi-messages";
    91 const relpipe::common::type::StringX CLIParser::OPTION_LIST_MIDI_MESSAGES = L"--list-midi-messages";
    88 
    92 
    89 }
    93 }
    90 }
    94 }
    91 }
    95 }