Skip to content

Commit a9919b5

Browse files
authored
Sample region argument (#582)
* check two commands for one assignment in CommandLineUtils
1 parent 33a3a1c commit a9919b5

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

samples/utils/CommandLineUtils.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -154,21 +154,24 @@ namespace Utils
154154
return commandDefault;
155155
}
156156

157-
Aws::Crt::String CommandLineUtils::GetCommandRequired(
158-
Aws::Crt::String command,
159-
Aws::Crt::String optionalAdditionalMessage)
157+
Aws::Crt::String CommandLineUtils::GetCommandRequired(Aws::Crt::String command)
160158
{
161159
if (HasCommand(command))
162160
{
163161
return GetCommand(command);
164162
}
165163
PrintHelp();
166164
fprintf(stderr, "Missing required argument: --%s\n", command.c_str());
167-
if (optionalAdditionalMessage != "")
165+
exit(-1);
166+
}
167+
168+
Aws::Crt::String CommandLineUtils::GetCommandRequired(Aws::Crt::String command, Aws::Crt::String commandAlt)
169+
{
170+
if (HasCommand(commandAlt))
168171
{
169-
fprintf(stderr, "%s\n", optionalAdditionalMessage.c_str());
172+
return GetCommand(commandAlt);
170173
}
171-
exit(-1);
174+
return GetCommandRequired(command);
172175
}
173176

174177
void CommandLineUtils::PrintHelp()
@@ -449,7 +452,7 @@ namespace Utils
449452
{
450453
returnData.input_ca = cmdUtils.GetCommand(m_cmd_ca_file);
451454
}
452-
returnData.input_signingRegion = cmdUtils.GetCommandRequired(m_cmd_region);
455+
returnData.input_signingRegion = cmdUtils.GetCommandRequired(m_cmd_region, m_cmd_signing_region);
453456
s_populateTopic(&cmdUtils, &returnData);
454457
returnData.input_message = cmdUtils.GetCommandOrDefault(m_cmd_message, "");
455458
returnData.input_mode = cmdUtils.GetCommandOrDefault(m_cmd_mode, "both");
@@ -568,9 +571,9 @@ namespace Utils
568571
s_parseCommonMQTTCommands(&cmdUtils, &returnData);
569572
returnData.input_clientId =
570573
cmdUtils.GetCommandOrDefault(m_cmd_client_id, Aws::Crt::String("test-") + Aws::Crt::UUID().ToString());
571-
returnData.input_signingRegion = cmdUtils.GetCommandRequired(m_cmd_signing_region);
574+
returnData.input_signingRegion = cmdUtils.GetCommandRequired(m_cmd_signing_region, m_cmd_region);
572575
returnData.input_cognitoEndpoint =
573-
"cognito-identity." + cmdUtils.GetCommandRequired(m_cmd_signing_region) + ".amazonaws.com";
576+
"cognito-identity." + cmdUtils.GetCommandRequired(m_cmd_signing_region, m_cmd_region) + ".amazonaws.com";
574577
returnData.input_cognitoIdentity = cmdUtils.GetCommandRequired(m_cmd_cognito_identity);
575578
if (cmdUtils.HasCommand(m_cmd_proxy_host))
576579
{
@@ -653,7 +656,7 @@ namespace Utils
653656
s_parseCommonMQTTCommands(&cmdUtils, &returnData);
654657
returnData.input_clientId =
655658
cmdUtils.GetCommandOrDefault(m_cmd_client_id, Aws::Crt::String("test-") + Aws::Crt::UUID().ToString());
656-
returnData.input_signingRegion = cmdUtils.GetCommandRequired(m_cmd_signing_region);
659+
returnData.input_signingRegion = cmdUtils.GetCommandRequired(m_cmd_signing_region, m_cmd_region);
657660
if (cmdUtils.HasCommand(m_cmd_proxy_host))
658661
{
659662
returnData.input_proxyHost = cmdUtils.GetCommandRequired(m_cmd_proxy_host);
@@ -706,7 +709,7 @@ namespace Utils
706709
s_parseCommonMQTTCommands(&cmdUtils, &returnData);
707710
returnData.input_clientId =
708711
cmdUtils.GetCommandOrDefault(m_cmd_client_id, Aws::Crt::String("test-") + Aws::Crt::UUID().ToString());
709-
returnData.input_signingRegion = cmdUtils.GetCommandRequired(m_cmd_signing_region);
712+
returnData.input_signingRegion = cmdUtils.GetCommandRequired(m_cmd_signing_region, m_cmd_region);
710713
if (cmdUtils.HasCommand(m_cmd_proxy_host))
711714
{
712715
returnData.input_proxyHost = cmdUtils.GetCommandRequired(m_cmd_proxy_host);
@@ -849,7 +852,7 @@ namespace Utils
849852
s_addLoggingSendArgumentsStartLogging(argc, argv, api_handle, &cmdUtils);
850853

851854
cmdData returnData = cmdData();
852-
returnData.input_signingRegion = cmdUtils.GetCommandRequired(m_cmd_signing_region);
855+
returnData.input_signingRegion = cmdUtils.GetCommandRequired(m_cmd_signing_region, m_cmd_region);
853856
returnData.input_endpoint = "data.tunneling.iot." + returnData.input_signingRegion + ".amazonaws.com";
854857
returnData.input_accessTokenFile = cmdUtils.GetCommandOrDefault(m_cmd_access_token_file, "");
855858
returnData.input_accessToken = cmdUtils.GetCommandOrDefault(m_cmd_access_token, "");

samples/utils/CommandLineUtils.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,17 @@ namespace Utils
124124
* @param CommandName The name of the command you want to get the value of
125125
* @return Aws::Crt::String The value passed into the program at the command name
126126
*/
127-
Aws::Crt::String GetCommandRequired(
128-
Aws::Crt::String CommandName,
129-
Aws::Crt::String OptionalAdditionalMessage = "");
127+
Aws::Crt::String GetCommandRequired(Aws::Crt::String CommandName);
128+
129+
/**
130+
* Gets the value of the command passed into the console/terminal if it exists. If it does not exist,
131+
* the program will exit with an error message.
132+
*
133+
* @param CommandName The name of the command you want to get the value of
134+
* @param CommandNameAlt The alternate name of the command you want to get the value of
135+
* @return Aws::Crt::String The value passed into the program at the command name
136+
*/
137+
Aws::Crt::String GetCommandRequired(Aws::Crt::String CommandName, Aws::Crt::String CommandNameAlt);
130138

131139
/**
132140
* Prints to the console/terminal all of the commands and their descriptions.

0 commit comments

Comments
 (0)