Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --version CLI option #280

Merged
merged 6 commits into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.6.0-31d162e*v1.6*1*6*0*0*31d162e
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be required since the version is auto-incremented by CMakeLists.txt.versioning

v1.6.12-8686765*v1.6*1*6*12*12*8686765
22 changes: 16 additions & 6 deletions source/config/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "../util/FileUtils.h"
#include "../util/MqttUtils.h"
#include "../util/StringUtils.h"
#include "Version.h"

#include <algorithm>
#include <aws/crt/JsonObject.h>
Expand Down Expand Up @@ -1978,6 +1979,7 @@ constexpr char Config::DEFAULT_CONFIG_DIR[];
constexpr char Config::DEFAULT_KEY_DIR[];
constexpr char Config::DEFAULT_CONFIG_FILE[];
constexpr char Config::CLI_HELP[];
constexpr char Config::CLI_VERSION[];
constexpr char Config::CLI_EXPORT_DEFAULT_SETTINGS[];
constexpr char Config::CLI_CONFIG_FILE[];
constexpr char Config::DEFAULT_FLEET_PROVISIONING_RUNTIME_CONFIG_FILE[];
Expand All @@ -1995,6 +1997,7 @@ bool Config::ParseCliArgs(int argc, char **argv, CliArgs &cliArgs)
};
ArgumentDefinition argumentDefinitions[] = {
{CLI_HELP, false, true, [](const string &additionalArg) { PrintHelpMessage(); }},
{CLI_VERSION, false, true, [](const string &additionalArg) { PrintVersion(); }},
{CLI_EXPORT_DEFAULT_SETTINGS,
true,
true,
Expand Down Expand Up @@ -2252,6 +2255,7 @@ void Config::PrintHelpMessage()
"Available sub-commands:\n"
"\n"
"%s:\t\t\t\t\t\t\t\t\tGet more help on commands\n"
"%s:\t\t\t\t\t\t\t\tOutput current version\n"
"%s <JSON-File-Location>:\t\t\t\tExport default settings for the AWS IoT Device Client binary to the specified "
"file "
"and exit "
Expand All @@ -2268,14 +2272,14 @@ void Config::PrintHelpMessage()
"%s [true|false]:\t\t\t\t\tEnables/Disables Device Defender feature\n"
"%s [true|false]:\t\t\t\tEnables/Disables Fleet Provisioning feature\n"
"%s [true|false]:\t\t\t\t\t\tEnables/Disables Pub/Sub Sample feature\n"
"%s [true|false]:\t\t\t\t\t\tEnables/Disables Sample Shadow feature\n"
"%s [true|false]:\t\t\t\t\t\tEnables/Disables Config Shadow feature\n"
"%s [true|false]:\t\t\t\t\tEnables/Disables Sample Shadow feature\n"
"%s [true|false]:\t\t\t\t\tEnables/Disables Config Shadow feature\n"
"%s [true|false]:\t\t\t\t\t\tEnables/Disables Secure Element Configuration\n"
"%s <endpoint-value>:\t\t\t\t\t\tUse Specified Endpoint\n"
"%s <Cert-Location>:\t\t\t\t\t\t\tUse Specified Cert file\n"
"%s <Key-Location>:\t\t\t\t\t\t\tUse Specified Key file\n"
"%s <Root-CA-Location>:\t\t\t\t\t\tUse Specified Root-CA file\n"
"%s <thing-name-value/client-id-value>:\t\t\t\t\tUse Specified Thing Name (Also used as Client ID)\n"
"%s <thing-name-value/client-id-value>:\t\t\tUse Specified Thing Name (Also used as Client ID)\n"
"%s <Jobs-handler-directory>:\t\t\t\tUse specified directory to find job handlers\n"
"%s <region>:\t\t\t\t\t\tUse Specified AWS Region for Secure Tunneling\n"
"%s <service>:\t\t\t\t\t\tConnect secure tunnel to specific service\n"
Expand All @@ -2295,9 +2299,9 @@ void Config::PrintHelpMessage()
"%s <path/to/publish/file>:\t\t\t\t\tThe file the Pub/Sub sample feature will read from when publishing\n"
"%s <subscribe-topic>:\t\t\t\t\tThe topic the Pub/Sub sample feature will receive messages on\n"
"%s <path/to/sub/file>:\t\t\t\t\tThe file the Pub/Sub sample feature will write received messaged to\n"
"%s <shadow-name>:\t\t\t\t\tThe name of shadow SampleShadow feature will create or update\n"
"%s <shadow-input-file>:\t\t\t\t\tThe file the Sample Shadow feature will read from when updating shadow data\n"
"%s <shadow-output-file>:\t\t\t\t\tThe file the Sample Shadow feature will write the latest shadow document "
"%s <shadow-name>:\t\t\t\t\t\tThe name of shadow SampleShadow feature will create or update\n"
"%s <shadow-input-file>:\t\t\t\tThe file the Sample Shadow feature will read from when updating shadow data\n"
"%s <shadow-output-file>:\t\t\t\tThe file the Sample Shadow feature will write the latest shadow document "
"to\n"
"%s <pkcs11-lib-path>:\t\t\t\t\tThe file path to PKCS#11 library\n"
"%s <secure-element-pin>:\t\t\t\t\tThe user PIN for logging into PKCS#11 token.\n"
Expand All @@ -2308,6 +2312,7 @@ void Config::PrintHelpMessage()
cout << FormatMessage(
helpMessageTemplate,
CLI_HELP,
CLI_VERSION,
CLI_EXPORT_DEFAULT_SETTINGS,
CLI_CONFIG_FILE,
PlainConfig::LogConfig::CLI_LOG_LEVEL,
Expand Down Expand Up @@ -2352,6 +2357,11 @@ void Config::PrintHelpMessage()
PlainConfig::SecureElement::CLI_SECURE_ELEMENT_TOKEN_LABEL);
}

void Config::PrintVersion()
{
cout << DEVICE_CLIENT_VERSION_FULL << endl;
}

bool Config::ExportDefaultSetting(const string &file)
{
string jsonTemplate = R"({
Expand Down
2 changes: 2 additions & 0 deletions source/config/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ namespace Aws
static constexpr char DEFAULT_SAMPLE_SHADOW_OUTPUT_DIR[] = "~/.aws-iot-device-client/sample-shadow/";

static constexpr char CLI_HELP[] = "--help";
static constexpr char CLI_VERSION[] = "--version";
static constexpr char CLI_EXPORT_DEFAULT_SETTINGS[] = "--export-default-settings";
static constexpr char CLI_CONFIG_FILE[] = "--config-file";

Expand Down Expand Up @@ -469,6 +470,7 @@ namespace Aws

private:
static void PrintHelpMessage();
static void PrintVersion();
static bool ExportDefaultSetting(const std::string &file);
};
} // namespace DeviceClient
Expand Down