From e3417ca0d5825ce03215f1f38b34664cede1ed87 Mon Sep 17 00:00:00 2001 From: Ricardo Abreu Date: Fri, 27 Sep 2019 18:16:41 +0100 Subject: [PATCH 1/4] [cli] Rename "option" as "setting" in get/set help To avoid confusion with command line options. --- src/client/cli/cmd/get.cpp | 8 ++++---- src/client/cli/cmd/set.cpp | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/client/cli/cmd/get.cpp b/src/client/cli/cmd/get.cpp index af681ef108..0cb1abe411 100644 --- a/src/client/cli/cmd/get.cpp +++ b/src/client/cli/cmd/get.cpp @@ -55,17 +55,17 @@ std::string cmd::Get::name() const QString cmd::Get::short_help() const { - return QStringLiteral("Get a configuration option"); + return QStringLiteral("Get a configuration setting"); } QString cmd::Get::description() const { - return QStringLiteral("Get the configuration option corresponding to the given key"); + return QStringLiteral("Get the configuration setting corresponding to the given key"); } mp::ParseCode cmd::Get::parse_args(mp::ArgParser* parser) { - parser->addPositionalArgument("key", "Path to the option whose configured value should be obtained.", ""); + parser->addPositionalArgument("key", "Path to the setting whose configured value should be obtained.", ""); auto status = parser->commandParse(this); if (status == ParseCode::Ok) @@ -77,7 +77,7 @@ mp::ParseCode cmd::Get::parse_args(mp::ArgParser* parser) } else { - cerr << "Need exactly one option key.\n"; + cerr << "Need exactly one setting key.\n"; status = ParseCode::CommandLineError; } } diff --git a/src/client/cli/cmd/set.cpp b/src/client/cli/cmd/set.cpp index 976d318705..29184b9070 100644 --- a/src/client/cli/cmd/set.cpp +++ b/src/client/cli/cmd/set.cpp @@ -96,19 +96,19 @@ std::string cmd::Set::name() const QString cmd::Set::short_help() const { - return QStringLiteral("Set a configuration option"); + return QStringLiteral("Set a configuration setting"); } QString cmd::Set::description() const { - return QStringLiteral("Set, to the given value, the configuration option corresponding to the given key"); + return QStringLiteral("Set, to the given value, the configuration setting corresponding to the given key"); } mp::ParseCode cmd::Set::parse_args(mp::ArgParser* parser) { parser->addPositionalArgument( "keyval", - "A key-value pair. The key specifies a path to the option to configure. The value is its intended value.", + "A key-value pair. The key specifies a path to the setting to configure. The value is its intended value.", "="); auto status = parser->commandParse(this); From 8f011575ca3f0e3908bf132426caa2f61d94cc4f Mon Sep 17 00:00:00 2001 From: Ricardo Abreu Date: Fri, 27 Sep 2019 18:20:19 +0100 Subject: [PATCH 2/4] [settings] Provide available keys --- include/multipass/settings.h | 2 ++ src/utils/settings.cpp | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/include/multipass/settings.h b/include/multipass/settings.h index 5d6b602bb7..5fd90d45b7 100644 --- a/include/multipass/settings.h +++ b/include/multipass/settings.h @@ -25,6 +25,7 @@ #include #include +#include namespace multipass { @@ -33,6 +34,7 @@ class Settings : public Singleton public: Settings(const Singleton::PrivatePass&); + std::set keys() const; virtual QString get(const QString& key) const; // throws on unknown key virtual void set(const QString& key, const QString& val); // throws on unknown key or bad settings diff --git a/src/utils/settings.cpp b/src/utils/settings.cpp index c6d38f6ea8..fe7fe61dfb 100644 --- a/src/utils/settings.cpp +++ b/src/utils/settings.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include namespace mp = multipass; @@ -132,6 +133,15 @@ mp::Settings::Settings(const Singleton::PrivatePass& pass) { } +std::set multipass::Settings::keys() const +{ + std::set ret{}; + std::transform(cbegin(defaults), cend(defaults), std::inserter(ret, begin(ret)), + [](const auto& elem) { return elem.first; }); // I wish get<0> worked here... maybe in C++20 + + return ret; +} + // TODO try installing yaml backend QString mp::Settings::get(const QString& key) const { From 7245eab25b8996f0617ba58f33946c36c8a7524e Mon Sep 17 00:00:00 2001 From: Ricardo Abreu Date: Fri, 27 Sep 2019 18:21:25 +0100 Subject: [PATCH 3/4] [cli] Document settings keys in help for get cmd --- src/client/cli/cmd/get.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/client/cli/cmd/get.cpp b/src/client/cli/cmd/get.cpp index 0cb1abe411..805b80367e 100644 --- a/src/client/cli/cmd/get.cpp +++ b/src/client/cli/cmd/get.cpp @@ -60,7 +60,11 @@ QString cmd::Get::short_help() const QString cmd::Get::description() const { - return QStringLiteral("Get the configuration setting corresponding to the given key"); + auto desc = QStringLiteral("Get the configuration setting corresponding to the given key.\n\n" + "Keys:"); + const auto keys = Settings::instance().keys(); + + return std::accumulate(cbegin(keys), cend(keys), desc, [](const auto& a, const auto& b) { return a + "\n " + b; }); } mp::ParseCode cmd::Get::parse_args(mp::ArgParser* parser) From ec8fcd241a4cb151b3e19390a59b05481f8b50dc Mon Sep 17 00:00:00 2001 From: Ricardo Abreu Date: Fri, 27 Sep 2019 19:02:20 +0100 Subject: [PATCH 4/4] [cli] Document available settings keys for set cmd Refactor to reduce duplication. --- src/client/cli/cmd/common_cli.cpp | 8 ++++++++ src/client/cli/cmd/common_cli.h | 1 + src/client/cli/cmd/get.cpp | 7 ++----- src/client/cli/cmd/set.cpp | 3 ++- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/client/cli/cmd/common_cli.cpp b/src/client/cli/cmd/common_cli.cpp index 563127a51e..335efc3183 100644 --- a/src/client/cli/cmd/common_cli.cpp +++ b/src/client/cli/cmd/common_cli.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -154,3 +155,10 @@ auto cmd::return_code_from(const mp::SettingsException& e) -> mp::ReturnCode { return dynamic_cast(&e) ? ReturnCode::CommandLineError : ReturnCode::CommandFail; } + +QString multipass::cmd::describe_settings_keys() +{ + const auto keys = Settings::instance().keys(); + return std::accumulate(cbegin(keys), cend(keys), QStringLiteral("Keys:"), + [](const auto& a, const auto& b) { return a + "\n " + b; }); +} diff --git a/src/client/cli/cmd/common_cli.h b/src/client/cli/cmd/common_cli.h index d46dcdefda..7eba69543e 100644 --- a/src/client/cli/cmd/common_cli.h +++ b/src/client/cli/cmd/common_cli.h @@ -46,6 +46,7 @@ std::string instance_action_message_for(const InstanceNames& instance_names, con ReturnCode run_cmd(const QStringList& args, const ArgParser* parser, std::ostream& cout, std::ostream& cerr); ReturnCode run_cmd_and_retry(const QStringList& args, const ArgParser* parser, std::ostream& cout, std::ostream& cerr); ReturnCode return_code_from(const SettingsException& e); +QString describe_settings_keys(); // helpers for update handling bool update_available(const multipass::UpdateInfo& update_info); diff --git a/src/client/cli/cmd/get.cpp b/src/client/cli/cmd/get.cpp index 805b80367e..1f976c103b 100644 --- a/src/client/cli/cmd/get.cpp +++ b/src/client/cli/cmd/get.cpp @@ -60,11 +60,8 @@ QString cmd::Get::short_help() const QString cmd::Get::description() const { - auto desc = QStringLiteral("Get the configuration setting corresponding to the given key.\n\n" - "Keys:"); - const auto keys = Settings::instance().keys(); - - return std::accumulate(cbegin(keys), cend(keys), desc, [](const auto& a, const auto& b) { return a + "\n " + b; }); + auto desc = QStringLiteral("Get the configuration setting corresponding to the given key."); + return desc + "\n\n" + describe_settings_keys(); } mp::ParseCode cmd::Get::parse_args(mp::ArgParser* parser) diff --git a/src/client/cli/cmd/set.cpp b/src/client/cli/cmd/set.cpp index 29184b9070..a894102c0b 100644 --- a/src/client/cli/cmd/set.cpp +++ b/src/client/cli/cmd/set.cpp @@ -101,7 +101,8 @@ QString cmd::Set::short_help() const QString cmd::Set::description() const { - return QStringLiteral("Set, to the given value, the configuration setting corresponding to the given key"); + auto desc = QStringLiteral("Set, to the given value, the configuration setting corresponding to the given key."); + return desc + "\n\n" + describe_settings_keys(); } mp::ParseCode cmd::Set::parse_args(mp::ArgParser* parser)