Skip to content

Commit

Permalink
[cli] Document available settings keys for set cmd
Browse files Browse the repository at this point in the history
Refactor to reduce duplication.
  • Loading branch information
ricab committed Sep 27, 2019
1 parent 7245eab commit ec8fcd2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
8 changes: 8 additions & 0 deletions src/client/cli/cmd/common_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <multipass/cli/argparser.h>
#include <multipass/cli/format_utils.h>
#include <multipass/exceptions/settings_exceptions.h>
#include <multipass/settings.h>

#include <fmt/ostream.h>
#include <sstream>
Expand Down Expand Up @@ -154,3 +155,10 @@ auto cmd::return_code_from(const mp::SettingsException& e) -> mp::ReturnCode
{
return dynamic_cast<const InvalidSettingsException*>(&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; });
}
1 change: 1 addition & 0 deletions src/client/cli/cmd/common_cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 2 additions & 5 deletions src/client/cli/cmd/get.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/client/cli/cmd/set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ec8fcd2

Please sign in to comment.