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/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 af681ef108..1f976c103b 100644 --- a/src/client/cli/cmd/get.cpp +++ b/src/client/cli/cmd/get.cpp @@ -55,17 +55,18 @@ 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"); + 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) { - 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 +78,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..a894102c0b 100644 --- a/src/client/cli/cmd/set.cpp +++ b/src/client/cli/cmd/set.cpp @@ -96,19 +96,20 @@ 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"); + 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) { 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); 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 {