in cli/cli.cpp [111:168]
ResponseCode CLI::InitializeCLI(int argc, char **argv) {
int opt;
int long_index = 0;
static struct option long_options[] = {
{"subscribe", no_argument, 0, 's'},
{"publish", no_argument, 0, 'p'},
{"topic", required_argument, 0, 't'},
{"qos", required_argument, 0, 'q'},
{"endpoint", required_argument, 0, 'e'},
{"port", required_argument, 0, 'r'},
{0, 0, 0, 0}
};
InitializeCliConfig();
while (-1 != (opt = getopt_long(argc, argv, "spt:q:c:e:r:", long_options, &long_index))) {
switch (opt) {
case 's':
is_subscribe_ = true;
std::cout << "Subscribe" << std::endl;
break;
case 'p':
is_publish_ = true;
std::cout << "Publish" << std::endl;
break;
case 'e':
endpoint_ = util::String(optarg, MAX_PATH_LENGTH_);
std::cout << "Host : " << optarg << std::endl;
break;
case 'r':
port_ = atoi(optarg);
std::cout << "Port : " << optarg << std::endl;
break;
case 't':
snprintf(topic_, MAX_PATH_LENGTH_, "%s", optarg);
std::cout << "Topic : " << optarg << std::endl;
break;
case 'q':
qos_ = atoi(optarg);
std::cout << "Publish Count :" << optarg << " times" << std::endl;
break;
default:
std::cout << "Error in command line argument parsing" << std::endl;
break;
}
}
// Atleast one option should be selected but not both
if (!(is_publish_ ^ is_subscribe_)) {
return ResponseCode::FAILURE;
}
InitializeTLS();
p_iot_client_ = MqttClient::Create(p_network_connection_, ConfigCommon::mqtt_command_timeout_);
return ResponseCode::SUCCESS;
}