From c47cdf327deeb36beeb17b9680c5a015a5204261 Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Mon, 10 May 2021 22:05:34 -0400 Subject: [PATCH 01/53] [cli] update msg to . Outputting the available updates message to until I read up on QT Command Line Parser and setup flag options. --- src/client/cli/cmd/version.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/cli/cmd/version.cpp b/src/client/cli/cmd/version.cpp index fd82e90871..7cd31d6b42 100644 --- a/src/client/cli/cmd/version.cpp +++ b/src/client/cli/cmd/version.cpp @@ -37,7 +37,7 @@ mp::ReturnCode cmd::Version::run(mp::ArgParser* parser) auto on_success = [this](mp::VersionReply& reply) { cout << "multipassd " << reply.version() << "\n"; if (term->is_live() && update_available(reply.update_info())) - cout << update_notice(reply.update_info()); + cerr << update_notice(reply.update_info()); return ReturnCode::Ok; }; From 6588b8a221545ab15cc6837614ad82aca698d358 Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Mon, 10 May 2021 22:05:34 -0400 Subject: [PATCH 02/53] [cli] added flag to cmdl options. Add the <--format> flag to the cmdl options. --- src/client/cli/argparser.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/client/cli/argparser.cpp b/src/client/cli/argparser.cpp index 0147fa88b2..160640b0e8 100644 --- a/src/client/cli/argparser.cpp +++ b/src/client/cli/argparser.cpp @@ -105,6 +105,12 @@ mp::ParseCode mp::ArgParser::parse() parser.addOption(verbose_option); parser.addOption(version_option); + //-- Switch formatting to or for updates notice. + QCommandLineOption version_option_format("format", "Outputs the \"Updates Notice\" for the \"-V\" and \"--version\" + "command to instead of for more reliable parsing."); + parser.addOption(version_option_format); + //-- + // Register "command" as the first positional argument, will need to be removed from all help text later parser.addPositionalArgument("command", "The command to execute", ""); From 136c7bbc260646e2f605f3823eeed83fccac581f Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Mon, 10 May 2021 22:05:34 -0400 Subject: [PATCH 03/53] [cli] added output switching. Added format switching to for "Update Notice" messages. --- src/client/cli/cmd/version.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/client/cli/cmd/version.cpp b/src/client/cli/cmd/version.cpp index 7cd31d6b42..14692ccec4 100644 --- a/src/client/cli/cmd/version.cpp +++ b/src/client/cli/cmd/version.cpp @@ -34,10 +34,13 @@ mp::ReturnCode cmd::Version::run(mp::ArgParser* parser) cout << "multipass " << multipass::version_string << "\n"; - auto on_success = [this](mp::VersionReply& reply) { + auto on_success = [this, &parser](mp::VersionReply& reply) { cout << "multipassd " << reply.version() << "\n"; if (term->is_live() && update_available(reply.update_info())) - cerr << update_notice(reply.update_info()); + { + std::ostream& output = parser->isSet("format") ? cerr : cout; + output << update_notice(reply.update_info()); + } return ReturnCode::Ok; }; From 6f0ee3212eba5bd87dfbc49fffcb6dafd4490920 Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Mon, 10 May 2021 22:05:34 -0400 Subject: [PATCH 04/53] [cli] fixed missing quote. Fixed a missing quote which got accidentally deleted. --- src/client/cli/argparser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/cli/argparser.cpp b/src/client/cli/argparser.cpp index 160640b0e8..1f7eb37351 100644 --- a/src/client/cli/argparser.cpp +++ b/src/client/cli/argparser.cpp @@ -106,7 +106,7 @@ mp::ParseCode mp::ArgParser::parse() parser.addOption(version_option); //-- Switch formatting to or for updates notice. - QCommandLineOption version_option_format("format", "Outputs the \"Updates Notice\" for the \"-V\" and \"--version\" + QCommandLineOption version_option_format("format", "Outputs the \"Updates Notice\" for the \"-V\" and \"--version\"" "command to instead of for more reliable parsing."); parser.addOption(version_option_format); //-- From 1780e89703dce9e6110ba3016cd6163d7587b08c Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Mon, 10 May 2021 22:05:34 -0400 Subject: [PATCH 05/53] [cli] moved option setup. --- .gitignore | 4 ++++ src/client/cli/argparser.cpp | 6 ------ src/client/cli/cmd/version.cpp | 31 +++++++++++++++++++++++++------ src/client/cli/cmd/version.h | 4 ++++ 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index a1c0324d87..98613d450d 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,7 @@ parts prime stage snap/.snapcraft/state + +build/ + +multipass-build-deps* diff --git a/src/client/cli/argparser.cpp b/src/client/cli/argparser.cpp index 1f7eb37351..0147fa88b2 100644 --- a/src/client/cli/argparser.cpp +++ b/src/client/cli/argparser.cpp @@ -105,12 +105,6 @@ mp::ParseCode mp::ArgParser::parse() parser.addOption(verbose_option); parser.addOption(version_option); - //-- Switch formatting to or for updates notice. - QCommandLineOption version_option_format("format", "Outputs the \"Updates Notice\" for the \"-V\" and \"--version\"" - "command to instead of for more reliable parsing."); - parser.addOption(version_option_format); - //-- - // Register "command" as the first positional argument, will need to be removed from all help text later parser.addPositionalArgument("command", "The command to execute", ""); diff --git a/src/client/cli/cmd/version.cpp b/src/client/cli/cmd/version.cpp index 14692ccec4..4508e64656 100644 --- a/src/client/cli/cmd/version.cpp +++ b/src/client/cli/cmd/version.cpp @@ -34,13 +34,11 @@ mp::ReturnCode cmd::Version::run(mp::ArgParser* parser) cout << "multipass " << multipass::version_string << "\n"; - auto on_success = [this, &parser](mp::VersionReply& reply) { + auto on_success = [this](mp::VersionReply& reply) { cout << "multipassd " << reply.version() << "\n"; if (term->is_live() && update_available(reply.update_info())) - { - std::ostream& output = parser->isSet("format") ? cerr : cout; - output << update_notice(reply.update_info()); - } + cout << update_notice(reply.update_info()); + return ReturnCode::Ok; }; @@ -69,5 +67,26 @@ QString cmd::Version::description() const mp::ParseCode cmd::Version::parse_args(mp::ArgParser* parser) { - return parser->commandParse(this); + QCommandLineOption formatOption( + "format", "Output list in the requested format.\nValid formats are: table (default), json, csv and yaml", + "format", "table"); + + parser->addOption(formatOption); + + auto status = parser->commandParse(this); + + if (status != ParseCode::Ok) + { + return status; + } + + if (parser->positionalArguments().count() > 0) + { + cerr << "Wrong number of arguments\n"; + return ParseCode::CommandLineError; + } + + status = handle_format_option(parser, &chosen_formatter, cerr); + + return status; } diff --git a/src/client/cli/cmd/version.h b/src/client/cli/cmd/version.h index 7fb60867a3..070d722bc7 100644 --- a/src/client/cli/cmd/version.h +++ b/src/client/cli/cmd/version.h @@ -24,6 +24,8 @@ namespace multipass { +class Formatter; + namespace cmd { class Version final : public Command @@ -38,6 +40,8 @@ class Version final : public Command private: ParseCode parse_args(ArgParser *parser) override; + + Formatter* chosen_formatter; }; } } From 4d002c31f49656b1834ba7b293a48afbf13267f1 Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Mon, 10 May 2021 22:05:34 -0400 Subject: [PATCH 06/53] [cli] added virtual void method in . --- include/multipass/cli/formatter.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/multipass/cli/formatter.h b/include/multipass/cli/formatter.h index 18c44efdc6..51facc15db 100644 --- a/include/multipass/cli/formatter.h +++ b/include/multipass/cli/formatter.h @@ -36,6 +36,7 @@ class Formatter virtual std::string format(const ListReply& reply) const = 0; virtual std::string format(const NetworksReply& reply) const = 0; virtual std::string format(const FindReply& reply) const = 0; + virtual std::string format(const VersionReply& reply) const = 0; protected: Formatter() = default; From f6c8ebc2cdb48b9704fbde8cb53ff64c0a86f650 Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Mon, 10 May 2021 22:05:34 -0400 Subject: [PATCH 07/53] [cli] created prelimary . --- include/multipass/cli/yaml_formatter.h | 1 + src/client/cli/formatter/yaml_formatter.cpp | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/multipass/cli/yaml_formatter.h b/include/multipass/cli/yaml_formatter.h index 9cf8d4ccf3..682354d119 100644 --- a/include/multipass/cli/yaml_formatter.h +++ b/include/multipass/cli/yaml_formatter.h @@ -29,6 +29,7 @@ class YamlFormatter final : public Formatter std::string format(const ListReply& list) const override; std::string format(const NetworksReply& list) const override; std::string format(const FindReply& list) const override; + std::string format(const VersionReply& list) const override; }; } #endif // MULTIPASS_YAML_FORMATTER diff --git a/src/client/cli/formatter/yaml_formatter.cpp b/src/client/cli/formatter/yaml_formatter.cpp index b310b7d386..7a2113657b 100644 --- a/src/client/cli/formatter/yaml_formatter.cpp +++ b/src/client/cli/formatter/yaml_formatter.cpp @@ -179,3 +179,19 @@ std::string mp::YamlFormatter::format(const FindReply& reply) const return mpu::emit_yaml(find); } + +std::string mp::YamlFormatter::format(const VersionReply& reply) const +{ + YAML::Node version; + version["multipass"] = reply.version(); + version["mulitpassd"] = reply.log_line(); + + YAML::Node update; + update["title"] = reply.update_info().title(); + update["description"] = reply.update_info().description(); + update["url"] = reply.update_info().url(); + + version["update"] = update; + + return mpu::emit_yaml(version); +} From bfa8671efbdcdde14ebfe30cc20abbbc370b2979 Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Mon, 10 May 2021 22:05:34 -0400 Subject: [PATCH 08/53] [cli] created prelimary . --- include/multipass/cli/json_formatter.h | 1 + src/client/cli/formatter/json_formatter.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/include/multipass/cli/json_formatter.h b/include/multipass/cli/json_formatter.h index 2d254941e0..15bc43ee9f 100644 --- a/include/multipass/cli/json_formatter.h +++ b/include/multipass/cli/json_formatter.h @@ -29,6 +29,7 @@ class JsonFormatter final : public Formatter std::string format(const ListReply& list) const override; std::string format(const NetworksReply& list) const override; std::string format(const FindReply& list) const override; + std::string format(const VersionReply& list) const override; }; } #endif // MULTIPASS_JSON_FORMATTER diff --git a/src/client/cli/formatter/json_formatter.cpp b/src/client/cli/formatter/json_formatter.cpp index b91d8174f9..8e129c1f76 100644 --- a/src/client/cli/formatter/json_formatter.cpp +++ b/src/client/cli/formatter/json_formatter.cpp @@ -188,3 +188,16 @@ std::string mp::JsonFormatter::format(const FindReply& reply) const return QString(QJsonDocument(find_json).toJson()).toStdString(); } + +std::string mp::JsonFormatter::format(const VersionReply& reply) const +{ + QJsonObject version_json; + QJsonObject update; + + version_json.insert("multipass", QString::fromStdString(reply.version())); + version_json.insert("multipassd", QString::fromStdString(reply.log_line())); + + version_json.insert("update", update); + + return QString(QJsonDocument(version_json).toJson()).toStdString(); +} From 54911aa7f6d9c4c5ec0dd1c45fb7545b254fe85e Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Mon, 10 May 2021 22:05:34 -0400 Subject: [PATCH 09/53] [cli] created stub . --- include/multipass/cli/table_formatter.h | 1 + src/client/cli/formatter/table_formatter.cpp | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/include/multipass/cli/table_formatter.h b/include/multipass/cli/table_formatter.h index 61ae550308..cdf717ffad 100644 --- a/include/multipass/cli/table_formatter.h +++ b/include/multipass/cli/table_formatter.h @@ -29,6 +29,7 @@ class TableFormatter final : public Formatter std::string format(const ListReply& list) const override; std::string format(const NetworksReply& list) const override; std::string format(const FindReply& list) const override; + std::string format(const VersionReply& list) const override; }; } #endif // MULTIPASS_TABLE_FORMATTER diff --git a/src/client/cli/formatter/table_formatter.cpp b/src/client/cli/formatter/table_formatter.cpp index 6ef57e3c11..ffbc1b9cd3 100644 --- a/src/client/cli/formatter/table_formatter.cpp +++ b/src/client/cli/formatter/table_formatter.cpp @@ -221,3 +221,12 @@ std::string mp::TableFormatter::format(const FindReply& reply) const return fmt::to_string(buf); } + +std::string mp::TableFormatter::format(const VersionReply& reply) const +{ + fmt::memory_buffer buf; + + // TODO: STUBBED. + + return fmt::to_string(buf); +} From c684d05f7db8ae3d8533cf3b00723fd24204fd1d Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Mon, 10 May 2021 22:05:34 -0400 Subject: [PATCH 10/53] [cli] created preliminary . --- include/multipass/cli/csv_formatter.h | 1 + src/client/cli/formatter/csv_formatter.cpp | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/multipass/cli/csv_formatter.h b/include/multipass/cli/csv_formatter.h index 9dc95b4966..20096832e9 100644 --- a/include/multipass/cli/csv_formatter.h +++ b/include/multipass/cli/csv_formatter.h @@ -29,6 +29,7 @@ class CSVFormatter final : public Formatter std::string format(const ListReply& list) const override; std::string format(const NetworksReply& list) const override; std::string format(const FindReply& list) const override; + std::string format(const VersionReply& list) const override; }; } #endif // MULTIPASS_CSV_FORMATTER diff --git a/src/client/cli/formatter/csv_formatter.cpp b/src/client/cli/formatter/csv_formatter.cpp index 113e2ddda4..b50db13b68 100644 --- a/src/client/cli/formatter/csv_formatter.cpp +++ b/src/client/cli/formatter/csv_formatter.cpp @@ -100,3 +100,18 @@ std::string mp::CSVFormatter::format(const FindReply& reply) const return fmt::to_string(buf); } + +std::string mp::CSVFormatter::format(const VersionReply& reply) const +{ + fmt::memory_buffer buf; + + fmt::format_to(buf, "Multipass,Multipassd,Title,Description,URL\n"); + + fmt::format_to(buf, "{},{},{},{},{}\n", reply.version(), + reply.log_line(), + reply.update_info().title(), + reply.update_info().description(), + reply.update_info().url()); + + return fmt::to_string(buf); +} \ No newline at end of file From f11fd96d276d90cfdff3f9aa70911a74c9350ef3 Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Mon, 10 May 2021 22:05:34 -0400 Subject: [PATCH 11/53] [cli] added update info to . --- src/client/cli/formatter/json_formatter.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/client/cli/formatter/json_formatter.cpp b/src/client/cli/formatter/json_formatter.cpp index 8e129c1f76..d5ce22b39b 100644 --- a/src/client/cli/formatter/json_formatter.cpp +++ b/src/client/cli/formatter/json_formatter.cpp @@ -197,6 +197,10 @@ std::string mp::JsonFormatter::format(const VersionReply& reply) const version_json.insert("multipass", QString::fromStdString(reply.version())); version_json.insert("multipassd", QString::fromStdString(reply.log_line())); + update.insert("title", QString::fromStdString(reply.update_info().title())); + update.insert("description", QString::fromStdString(reply.update_info().description())); + update.insert("url", QString::fromStdString(reply.update_info().url())); + version_json.insert("update", update); return QString(QJsonDocument(version_json).toJson()).toStdString(); From 97b73989f474cb00182d7abbaa127867d4b209e4 Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Mon, 10 May 2021 22:05:34 -0400 Subject: [PATCH 12/53] [cli] stubbing testing framework methods. --- tests/test_output_formatter.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/test_output_formatter.cpp b/tests/test_output_formatter.cpp index eb1b0d5a95..6fd52862bb 100644 --- a/tests/test_output_formatter.cpp +++ b/tests/test_output_formatter.cpp @@ -318,6 +318,31 @@ auto construct_find_multiple_reply_duplicate_image() return reply; } + +auto construct_version_info_multipass() +{ + auto reply = mp::VersionReply(); + + + return reply; +} + +auto construct_version_info_multipassd_update_available() +{ + auto reply = mp::VersionReply(); + + + return reply; +} + +auto construct_version_info_multipassd_up_to_date() +{ + auto reply = mp::VersionReply(); + + + return reply; +} + class LocaleSettingTest : public testing::Test { public: @@ -1050,6 +1075,10 @@ const std::vector find_formatter_outputs{ "yaml_find_multiple_duplicate_image"}}; } // namespace +const std::vector version_formatter_outputs { + +} + TEST_P(FormatterSuite, properly_formats_output) { const auto& [formatter, reply, expected_output, test_name] = GetParam(); @@ -1065,6 +1094,8 @@ TEST_P(FormatterSuite, properly_formats_output) output = formatter->format(*input); else if (auto input = dynamic_cast(reply)) output = formatter->format(*input); + else if (auto input = dynamic_cast(reply)) + output = formatter->format(*input); else FAIL() << "Not a supported reply type."; From fcb0c83d786694f85cf3490b9d0fd2066f08d9dd Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Mon, 10 May 2021 22:05:34 -0400 Subject: [PATCH 13/53] [cli] created base input tests. --- tests/test_output_formatter.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/test_output_formatter.cpp b/tests/test_output_formatter.cpp index 6fd52862bb..3de75c458a 100644 --- a/tests/test_output_formatter.cpp +++ b/tests/test_output_formatter.cpp @@ -322,7 +322,10 @@ auto construct_find_multiple_reply_duplicate_image() auto construct_version_info_multipass() { auto reply = mp::VersionReply(); + reply.set_version("CLIENT Version"); + reply.set_log_line("Some logline goes here"); + reply.set_allocated_update_info(nullptr); return reply; } @@ -330,7 +333,15 @@ auto construct_version_info_multipass() auto construct_version_info_multipassd_update_available() { auto reply = mp::VersionReply(); + reply.set_version("Daemon Version"); + reply.set_log_line("Some logline goes here"); + mp::UpdateInfo updateInfo; + updateInfo.set_title("update title information"); + updateInfo.set_description("update description information"); + updateInfo.set_version("update version number"); + + reply.set_allocated_update_info(&updateInfo); return reply; } @@ -338,7 +349,16 @@ auto construct_version_info_multipassd_update_available() auto construct_version_info_multipassd_up_to_date() { auto reply = mp::VersionReply(); - + reply.set_version("MULTIPASS DEAMON VERSION"); + reply.set_log_line("THIS IS THE LOGLINE"); + reply.set_allocated_update_info(nullptr); + +// mp::UpdateInfo updateInfo; +// updateInfo.set_title("update title information"); +// updateInfo.set_description("update description information"); +// updateInfo.set_version("update version number"); +// +// reply.set_allocated_update_info(&updateInfo); return reply; } From 8a1086ae440099202e0553f33c6a59be0fed1092 Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Mon, 10 May 2021 22:05:34 -0400 Subject: [PATCH 14/53] [cli] test fixtures completed. --- src/client/cli/formatter/yaml_formatter.cpp | 17 ++++++---- tests/test_output_formatter.cpp | 36 ++++++++++++++------- 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/src/client/cli/formatter/yaml_formatter.cpp b/src/client/cli/formatter/yaml_formatter.cpp index 7a2113657b..6ade16352a 100644 --- a/src/client/cli/formatter/yaml_formatter.cpp +++ b/src/client/cli/formatter/yaml_formatter.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include @@ -183,15 +184,17 @@ std::string mp::YamlFormatter::format(const FindReply& reply) const std::string mp::YamlFormatter::format(const VersionReply& reply) const { YAML::Node version; - version["multipass"] = reply.version(); - version["mulitpassd"] = reply.log_line(); + version["version"] = reply.version(); - YAML::Node update; - update["title"] = reply.update_info().title(); - update["description"] = reply.update_info().description(); - update["url"] = reply.update_info().url(); + if (mp::cmd::update_available(reply.update_info())) + { + YAML::Node update; + update["title"] = reply.update_info().title(); + update["description"] = reply.update_info().description(); + update["url"] = reply.update_info().url(); - version["update"] = update; + version["update"] = update; + } return mpu::emit_yaml(version); } diff --git a/tests/test_output_formatter.cpp b/tests/test_output_formatter.cpp index 3de75c458a..ad25eec036 100644 --- a/tests/test_output_formatter.cpp +++ b/tests/test_output_formatter.cpp @@ -322,7 +322,7 @@ auto construct_find_multiple_reply_duplicate_image() auto construct_version_info_multipass() { auto reply = mp::VersionReply(); - reply.set_version("CLIENT Version"); + reply.set_version("Client Version"); reply.set_log_line("Some logline goes here"); reply.set_allocated_update_info(nullptr); @@ -349,16 +349,10 @@ auto construct_version_info_multipassd_update_available() auto construct_version_info_multipassd_up_to_date() { auto reply = mp::VersionReply(); - reply.set_version("MULTIPASS DEAMON VERSION"); - reply.set_log_line("THIS IS THE LOGLINE"); - reply.set_allocated_update_info(nullptr); + reply.set_version("Daemon Version"); + reply.set_log_line("Some logline goes here"); -// mp::UpdateInfo updateInfo; -// updateInfo.set_title("update title information"); -// updateInfo.set_description("update description information"); -// updateInfo.set_version("update version number"); -// -// reply.set_allocated_update_info(&updateInfo); + reply.set_allocated_update_info(nullptr); return reply; } @@ -1093,11 +1087,27 @@ const std::vector find_formatter_outputs{ " version: 20190520\n" " remote: snapcraft\n", "yaml_find_multiple_duplicate_image"}}; -} // namespace + +const auto version_client_reply = construct_version_info_multipass(); +const auto version_daemon_no_update_reply = construct_version_info_multipassd_up_to_date(); +const auto version_daemon_update_reply = construct_version_info_multipassd_update_available(); const std::vector version_formatter_outputs { + {&yaml_formatter, &version_client_reply, "version: Client Version\n", "VERSION: Client version"}, + {&yaml_formatter, &version_daemon_no_update_reply, + "version: Daemon Version\n", + "VERSION: Daemon version with no updates available."}, + {&yaml_formatter, &version_daemon_update_reply, + "version: Daemon Version\n" + " - title: update title information\n" + " description: update description information\n" + " update version number:\n", + "VERSION: Daemon version with updates available."} +}; + +} // namespace + -} TEST_P(FormatterSuite, properly_formats_output) { @@ -1129,6 +1139,8 @@ INSTANTIATE_TEST_SUITE_P(NonOrderableListInfoOutputFormatter, FormatterSuite, INSTANTIATE_TEST_SUITE_P(FindOutputFormatter, FormatterSuite, ValuesIn(find_formatter_outputs), print_param_name); INSTANTIATE_TEST_SUITE_P(NonOrderableNetworksOutputFormatter, FormatterSuite, ValuesIn(non_orderable_networks_formatter_outputs), print_param_name); +INSTANTIATE_TEST_SUITE_P(VersionInfoOutputFormatter, FormatterSuite, + ValuesIn(version_formatter_outputs), print_param_name); #if GTEST_HAS_POSIX_RE TEST_P(PetenvFormatterSuite, pet_env_first_in_output) From 6ea6d3a2ccee30c88481e72c76d07c575e7d9cd5 Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Mon, 10 May 2021 22:05:34 -0400 Subject: [PATCH 15/53] [cli] test fixture corrections, all passing. --- tests/test_output_formatter.cpp | 37 +++++++++++++++------------------ 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/tests/test_output_formatter.cpp b/tests/test_output_formatter.cpp index ad25eec036..14864f9101 100644 --- a/tests/test_output_formatter.cpp +++ b/tests/test_output_formatter.cpp @@ -322,26 +322,25 @@ auto construct_find_multiple_reply_duplicate_image() auto construct_version_info_multipass() { auto reply = mp::VersionReply(); - reply.set_version("Client Version"); + reply.set_version("Client version"); reply.set_log_line("Some logline goes here"); - reply.set_allocated_update_info(nullptr); - return reply; } auto construct_version_info_multipassd_update_available() { auto reply = mp::VersionReply(); - reply.set_version("Daemon Version"); + reply.set_version("Daemon version"); reply.set_log_line("Some logline goes here"); - mp::UpdateInfo updateInfo; - updateInfo.set_title("update title information"); - updateInfo.set_description("update description information"); - updateInfo.set_version("update version number"); + mp::UpdateInfo *updateInfo = new mp::UpdateInfo; // Leak? expecting protobuf to deal with memory dealloc. + updateInfo->set_version("update version number"); + updateInfo->set_title("update title information"); + updateInfo->set_description("update description information"); + updateInfo->set_url("http://multipass.web"); - reply.set_allocated_update_info(&updateInfo); + reply.set_allocated_update_info(updateInfo); return reply; } @@ -349,11 +348,9 @@ auto construct_version_info_multipassd_update_available() auto construct_version_info_multipassd_up_to_date() { auto reply = mp::VersionReply(); - reply.set_version("Daemon Version"); + reply.set_version("Daemon version"); reply.set_log_line("Some logline goes here"); - reply.set_allocated_update_info(nullptr); - return reply; } @@ -1093,16 +1090,16 @@ const auto version_daemon_no_update_reply = construct_version_info_multipassd_up const auto version_daemon_update_reply = construct_version_info_multipassd_update_available(); const std::vector version_formatter_outputs { - {&yaml_formatter, &version_client_reply, "version: Client Version\n", "VERSION: Client version"}, + {&yaml_formatter, &version_client_reply, "version: Client version\n", "yaml_version_client"}, {&yaml_formatter, &version_daemon_no_update_reply, - "version: Daemon Version\n", - "VERSION: Daemon version with no updates available."}, + "version: Daemon version\n", + "yaml_version_daemon_no_updates"}, {&yaml_formatter, &version_daemon_update_reply, - "version: Daemon Version\n" - " - title: update title information\n" - " description: update description information\n" - " update version number:\n", - "VERSION: Daemon version with updates available."} + "version: Daemon version\n" + "update:\n title: update title information\n" + " description: update description information\n" + " url: \"http://multipass.web\"\n", + "yaml_version_daemon_updates"} }; } // namespace From f0b3e4a72afafdb1358beb7377f541740e17445a Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Mon, 10 May 2021 22:05:34 -0400 Subject: [PATCH 16/53] [cli] test fixtures completed. --- tests/test_output_formatter.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/test_output_formatter.cpp b/tests/test_output_formatter.cpp index 14864f9101..394b3dca48 100644 --- a/tests/test_output_formatter.cpp +++ b/tests/test_output_formatter.cpp @@ -1090,6 +1090,26 @@ const auto version_daemon_no_update_reply = construct_version_info_multipassd_up const auto version_daemon_update_reply = construct_version_info_multipassd_update_available(); const std::vector version_formatter_outputs { + {&json_formatter, &version_client_reply, + "{\n" + " \"version\": \"Client version\"\n" + "}\n", + "json_version_client"}, + {&json_formatter, &version_daemon_no_update_reply, + "{\n" + " \"version\": \"Daemon version\"\n" + "}\n", + "json_version_daemon_no_updates"}, + {&json_formatter, &version_daemon_update_reply, + "{\n" + " \"update\": {\n" + " \"description\": \"update description information\",\n" + " \"title\": \"update title information\",\n" + " \"url\": \"http://multipass.web\"\n" + " },\n" + " \"version\": \"Daemon version\"\n" + "}\n", + "json_version_daemon_updates"}, {&yaml_formatter, &version_client_reply, "version: Client version\n", "yaml_version_client"}, {&yaml_formatter, &version_daemon_no_update_reply, "version: Daemon version\n", From 0382c6841213f08c8ef5143dd8143c78465829ff Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Mon, 10 May 2021 22:05:34 -0400 Subject: [PATCH 17/53] [cli] fomatter corrected, passing all tests. --- src/client/cli/formatter/json_formatter.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/client/cli/formatter/json_formatter.cpp b/src/client/cli/formatter/json_formatter.cpp index d5ce22b39b..65a1aeef3e 100644 --- a/src/client/cli/formatter/json_formatter.cpp +++ b/src/client/cli/formatter/json_formatter.cpp @@ -16,8 +16,8 @@ */ #include - #include +#include #include #include @@ -192,16 +192,17 @@ std::string mp::JsonFormatter::format(const FindReply& reply) const std::string mp::JsonFormatter::format(const VersionReply& reply) const { QJsonObject version_json; - QJsonObject update; - - version_json.insert("multipass", QString::fromStdString(reply.version())); - version_json.insert("multipassd", QString::fromStdString(reply.log_line())); + version_json.insert("version", QString::fromStdString(reply.version())); - update.insert("title", QString::fromStdString(reply.update_info().title())); - update.insert("description", QString::fromStdString(reply.update_info().description())); - update.insert("url", QString::fromStdString(reply.update_info().url())); + if (mp::cmd::update_available(reply.update_info())) + { + QJsonObject update; + update.insert("title", QString::fromStdString(reply.update_info().title())); + update.insert("description", QString::fromStdString(reply.update_info().description())); + update.insert("url", QString::fromStdString(reply.update_info().url())); - version_json.insert("update", update); + version_json.insert("update", update); + } return QString(QJsonDocument(version_json).toJson()).toStdString(); } From e3cc08500e4160e6a9ae6365faef3392d79080ba Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Mon, 10 May 2021 22:05:34 -0400 Subject: [PATCH 18/53] [cli] add client version parameter for . --- include/multipass/cli/csv_formatter.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/multipass/cli/csv_formatter.h b/include/multipass/cli/csv_formatter.h index 20096832e9..3f073884c7 100644 --- a/include/multipass/cli/csv_formatter.h +++ b/include/multipass/cli/csv_formatter.h @@ -29,7 +29,7 @@ class CSVFormatter final : public Formatter std::string format(const ListReply& list) const override; std::string format(const NetworksReply& list) const override; std::string format(const FindReply& list) const override; - std::string format(const VersionReply& list) const override; + std::string format(const VersionReply& list, const std::string& multipassVer) const override; }; } #endif // MULTIPASS_CSV_FORMATTER From e056907dcd4ae2fb3d70656336a79b651ce0d169 Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Mon, 10 May 2021 22:05:34 -0400 Subject: [PATCH 19/53] [cli] add client version parameter for . --- include/multipass/cli/formatter.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/multipass/cli/formatter.h b/include/multipass/cli/formatter.h index 51facc15db..8b1e697d6e 100644 --- a/include/multipass/cli/formatter.h +++ b/include/multipass/cli/formatter.h @@ -36,7 +36,7 @@ class Formatter virtual std::string format(const ListReply& reply) const = 0; virtual std::string format(const NetworksReply& reply) const = 0; virtual std::string format(const FindReply& reply) const = 0; - virtual std::string format(const VersionReply& reply) const = 0; + virtual std::string format(const VersionReply& reply, const std::string& multipassVer) const = 0; protected: Formatter() = default; From a9aa49fb87af2d19bfa111b3563ec8be03cb3cdd Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Mon, 10 May 2021 22:05:34 -0400 Subject: [PATCH 20/53] [cli] add client version parameter for in . --- src/client/cli/formatter/csv_formatter.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/client/cli/formatter/csv_formatter.cpp b/src/client/cli/formatter/csv_formatter.cpp index b50db13b68..f6b488cc85 100644 --- a/src/client/cli/formatter/csv_formatter.cpp +++ b/src/client/cli/formatter/csv_formatter.cpp @@ -101,14 +101,14 @@ std::string mp::CSVFormatter::format(const FindReply& reply) const return fmt::to_string(buf); } -std::string mp::CSVFormatter::format(const VersionReply& reply) const +std::string mp::CSVFormatter::format(const VersionReply& reply, const std::string& multipassVer) const { fmt::memory_buffer buf; fmt::format_to(buf, "Multipass,Multipassd,Title,Description,URL\n"); - fmt::format_to(buf, "{},{},{},{},{}\n", reply.version(), - reply.log_line(), + fmt::format_to(buf, "{},{},{},{},{}\n", multipassVer, + reply.version(), reply.update_info().title(), reply.update_info().description(), reply.update_info().url()); From 7062eed69f2cb0e152316482e416b45c00950356 Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Mon, 10 May 2021 22:05:34 -0400 Subject: [PATCH 21/53] [cli] add client version parameter for in . --- include/multipass/cli/json_formatter.h | 2 +- src/client/cli/formatter/json_formatter.cpp | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/multipass/cli/json_formatter.h b/include/multipass/cli/json_formatter.h index 15bc43ee9f..4ca1d76674 100644 --- a/include/multipass/cli/json_formatter.h +++ b/include/multipass/cli/json_formatter.h @@ -29,7 +29,7 @@ class JsonFormatter final : public Formatter std::string format(const ListReply& list) const override; std::string format(const NetworksReply& list) const override; std::string format(const FindReply& list) const override; - std::string format(const VersionReply& list) const override; + std::string format(const VersionReply& list, const std::string& multipassVer) const override; }; } #endif // MULTIPASS_JSON_FORMATTER diff --git a/src/client/cli/formatter/json_formatter.cpp b/src/client/cli/formatter/json_formatter.cpp index 65a1aeef3e..42b72b7727 100644 --- a/src/client/cli/formatter/json_formatter.cpp +++ b/src/client/cli/formatter/json_formatter.cpp @@ -189,10 +189,12 @@ std::string mp::JsonFormatter::format(const FindReply& reply) const return QString(QJsonDocument(find_json).toJson()).toStdString(); } -std::string mp::JsonFormatter::format(const VersionReply& reply) const +std::string mp::JsonFormatter::format(const VersionReply& reply, const std::string& multipassVer) const { QJsonObject version_json; - version_json.insert("version", QString::fromStdString(reply.version())); + + version_json.insert("multipass", QString::fromStdString(multipassVer)); + version_json.insert("multipassd", QString::fromStdString(reply.version())); if (mp::cmd::update_available(reply.update_info())) { From d73b22d851f5c6e3189e7c5cabbd7e5bda002961 Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Mon, 10 May 2021 22:05:34 -0400 Subject: [PATCH 22/53] [cli] add client version parameter for in . --- include/multipass/cli/yaml_formatter.h | 2 +- src/client/cli/formatter/yaml_formatter.cpp | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/multipass/cli/yaml_formatter.h b/include/multipass/cli/yaml_formatter.h index 682354d119..a8ee66674b 100644 --- a/include/multipass/cli/yaml_formatter.h +++ b/include/multipass/cli/yaml_formatter.h @@ -29,7 +29,7 @@ class YamlFormatter final : public Formatter std::string format(const ListReply& list) const override; std::string format(const NetworksReply& list) const override; std::string format(const FindReply& list) const override; - std::string format(const VersionReply& list) const override; + std::string format(const VersionReply& list, const std::string& multipassVer) const override; }; } #endif // MULTIPASS_YAML_FORMATTER diff --git a/src/client/cli/formatter/yaml_formatter.cpp b/src/client/cli/formatter/yaml_formatter.cpp index 6ade16352a..286e6151b1 100644 --- a/src/client/cli/formatter/yaml_formatter.cpp +++ b/src/client/cli/formatter/yaml_formatter.cpp @@ -181,10 +181,11 @@ std::string mp::YamlFormatter::format(const FindReply& reply) const return mpu::emit_yaml(find); } -std::string mp::YamlFormatter::format(const VersionReply& reply) const +std::string mp::YamlFormatter::format(const VersionReply& reply, const std::string& multipassVer) const { YAML::Node version; - version["version"] = reply.version(); + version["multipass"] = multipassVer; + version["multipassd"] = reply.version(); if (mp::cmd::update_available(reply.update_info())) { From d2f754300dd01c7cf197897bd081496ffd2b7e6c Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Mon, 10 May 2021 22:05:34 -0400 Subject: [PATCH 23/53] [cli] add client version parameter for in
. --- include/multipass/cli/table_formatter.h | 2 +- src/client/cli/formatter/table_formatter.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/multipass/cli/table_formatter.h b/include/multipass/cli/table_formatter.h index cdf717ffad..0a30ab44c6 100644 --- a/include/multipass/cli/table_formatter.h +++ b/include/multipass/cli/table_formatter.h @@ -29,7 +29,7 @@ class TableFormatter final : public Formatter std::string format(const ListReply& list) const override; std::string format(const NetworksReply& list) const override; std::string format(const FindReply& list) const override; - std::string format(const VersionReply& list) const override; + std::string format(const VersionReply& list, const std::string& multipassVer) const override; }; } #endif // MULTIPASS_TABLE_FORMATTER diff --git a/src/client/cli/formatter/table_formatter.cpp b/src/client/cli/formatter/table_formatter.cpp index ffbc1b9cd3..807257558c 100644 --- a/src/client/cli/formatter/table_formatter.cpp +++ b/src/client/cli/formatter/table_formatter.cpp @@ -222,7 +222,7 @@ std::string mp::TableFormatter::format(const FindReply& reply) const return fmt::to_string(buf); } -std::string mp::TableFormatter::format(const VersionReply& reply) const +std::string mp::TableFormatter::format(const VersionReply& reply, const std::string& multipassVer) const { fmt::memory_buffer buf; From 3632b7506b8da3890cb8a2e31bc5b2572297c8b3 Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Mon, 10 May 2021 22:05:34 -0400 Subject: [PATCH 24/53] [cli] (RFC 8259) tests passing. --- tests/test_output_formatter.cpp | 44 ++++++++++++++------------------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/tests/test_output_formatter.cpp b/tests/test_output_formatter.cpp index 394b3dca48..e90bff0e77 100644 --- a/tests/test_output_formatter.cpp +++ b/tests/test_output_formatter.cpp @@ -319,15 +319,6 @@ auto construct_find_multiple_reply_duplicate_image() return reply; } -auto construct_version_info_multipass() -{ - auto reply = mp::VersionReply(); - reply.set_version("Client version"); - reply.set_log_line("Some logline goes here"); - - return reply; -} - auto construct_version_info_multipassd_update_available() { auto reply = mp::VersionReply(); @@ -1085,41 +1076,44 @@ const std::vector find_formatter_outputs{ " remote: snapcraft\n", "yaml_find_multiple_duplicate_image"}}; -const auto version_client_reply = construct_version_info_multipass(); +const auto version_client_reply = mp::VersionReply(); const auto version_daemon_no_update_reply = construct_version_info_multipassd_up_to_date(); const auto version_daemon_update_reply = construct_version_info_multipassd_update_available(); const std::vector version_formatter_outputs { {&json_formatter, &version_client_reply, "{\n" - " \"version\": \"Client version\"\n" + " \"multipass\": \"Client version\",\n" + " \"multipassd\": \"\"\n" "}\n", "json_version_client"}, {&json_formatter, &version_daemon_no_update_reply, "{\n" - " \"version\": \"Daemon version\"\n" + " \"multipass\": \"Client version\",\n" + " \"multipassd\": \"Daemon version\"\n" "}\n", "json_version_daemon_no_updates"}, {&json_formatter, &version_daemon_update_reply, "{\n" + " \"multipass\": \"Client version\",\n" + " \"multipassd\": \"Daemon version\",\n" " \"update\": {\n" " \"description\": \"update description information\",\n" " \"title\": \"update title information\",\n" " \"url\": \"http://multipass.web\"\n" - " },\n" - " \"version\": \"Daemon version\"\n" + " }\n" "}\n", "json_version_daemon_updates"}, - {&yaml_formatter, &version_client_reply, "version: Client version\n", "yaml_version_client"}, - {&yaml_formatter, &version_daemon_no_update_reply, - "version: Daemon version\n", - "yaml_version_daemon_no_updates"}, - {&yaml_formatter, &version_daemon_update_reply, - "version: Daemon version\n" - "update:\n title: update title information\n" - " description: update description information\n" - " url: \"http://multipass.web\"\n", - "yaml_version_daemon_updates"} +// {&yaml_formatter, &version_client_reply, "version: Client version\n", "yaml_version_client"}, +// {&yaml_formatter, &version_daemon_no_update_reply, +// "version: Daemon version\n", +// "yaml_version_daemon_no_updates"}, +// {&yaml_formatter, &version_daemon_update_reply, +// "version: Daemon version\n" +// "update:\n title: update title information\n" +// " description: update description information\n" +// " url: \"http://multipass.web\"\n", +// "yaml_version_daemon_updates"} }; } // namespace @@ -1142,7 +1136,7 @@ TEST_P(FormatterSuite, properly_formats_output) else if (auto input = dynamic_cast(reply)) output = formatter->format(*input); else if (auto input = dynamic_cast(reply)) - output = formatter->format(*input); + output = formatter->format(*input, "Client version"); else FAIL() << "Not a supported reply type."; From a8caa959f986499c1ab3157965b2c67ab323e504 Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Mon, 10 May 2021 22:06:44 -0400 Subject: [PATCH 25/53] [cli] test fixtures added. --- tests/test_output_formatter.cpp | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/tests/test_output_formatter.cpp b/tests/test_output_formatter.cpp index e90bff0e77..124c72400c 100644 --- a/tests/test_output_formatter.cpp +++ b/tests/test_output_formatter.cpp @@ -1104,16 +1104,28 @@ const std::vector version_formatter_outputs { " }\n" "}\n", "json_version_daemon_updates"}, -// {&yaml_formatter, &version_client_reply, "version: Client version\n", "yaml_version_client"}, -// {&yaml_formatter, &version_daemon_no_update_reply, -// "version: Daemon version\n", -// "yaml_version_daemon_no_updates"}, -// {&yaml_formatter, &version_daemon_update_reply, -// "version: Daemon version\n" -// "update:\n title: update title information\n" -// " description: update description information\n" -// " url: \"http://multipass.web\"\n", -// "yaml_version_daemon_updates"} + {&csv_formatter, &version_client_reply, + "Multipass,Mulitpassd,Title,Description,URL\n" + "Client version,,,\n", + "csv_version_client"}, + {&csv_formatter, &version_daemon_no_update_reply, + "Multipass,Mulitpassd,Title,Description,URL\n" + "Client version, Daemon version,,,\n", + "csv_version_daemon_no_updates"}, + {&csv_formatter, &version_daemon_update_reply, + "Multipass,Mulitpassd,Title,Description,URLn" + "Client version, Daemon version,update title information,update description information,\"http://multipass.web\"\n", + "csv_version_daemon_updates"}, + {&yaml_formatter, &version_client_reply, "version: Client version\n", "yaml_version_client"}, + {&yaml_formatter, &version_daemon_no_update_reply, + "version: Daemon version\n", + "yaml_version_daemon_no_updates"}, + {&yaml_formatter, &version_daemon_update_reply, + "version: Daemon version\n" + "update:\n title: update title information\n" + " description: update description information\n" + " url: \"http://multipass.web\"\n", + "yaml_version_daemon_updates"} }; } // namespace From 6cd30274a4fe6759380746b20332fd4bce0b9310 Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Mon, 10 May 2021 22:07:21 -0400 Subject: [PATCH 26/53] [cli] tests updated and passing. --- tests/test_output_formatter.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/test_output_formatter.cpp b/tests/test_output_formatter.cpp index 124c72400c..8dbd6d44dd 100644 --- a/tests/test_output_formatter.cpp +++ b/tests/test_output_formatter.cpp @@ -1105,16 +1105,16 @@ const std::vector version_formatter_outputs { "}\n", "json_version_daemon_updates"}, {&csv_formatter, &version_client_reply, - "Multipass,Mulitpassd,Title,Description,URL\n" - "Client version,,,\n", + "Multipass,Multipassd,Title,Description,URL\n" + "Client version,,,,\n", "csv_version_client"}, {&csv_formatter, &version_daemon_no_update_reply, - "Multipass,Mulitpassd,Title,Description,URL\n" - "Client version, Daemon version,,,\n", + "Multipass,Multipassd,Title,Description,URL\n" + "Client version,Daemon version,,,\n", "csv_version_daemon_no_updates"}, {&csv_formatter, &version_daemon_update_reply, - "Multipass,Mulitpassd,Title,Description,URLn" - "Client version, Daemon version,update title information,update description information,\"http://multipass.web\"\n", + "Multipass,Multipassd,Title,Description,URL\n" + "Client version,Daemon version,update title information,update description information,http://multipass.web\n", "csv_version_daemon_updates"}, {&yaml_formatter, &version_client_reply, "version: Client version\n", "yaml_version_client"}, {&yaml_formatter, &version_daemon_no_update_reply, From ed7af5cd2466b0b2d8b0c6ff74fc29de4fa49451 Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Mon, 10 May 2021 22:07:21 -0400 Subject: [PATCH 27/53] [cli]
formatter completed and passing tests. --- src/client/cli/formatter/table_formatter.cpp | 11 +++++++++-- tests/test_output_formatter.cpp | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/client/cli/formatter/table_formatter.cpp b/src/client/cli/formatter/table_formatter.cpp index 807257558c..c069bbf1ba 100644 --- a/src/client/cli/formatter/table_formatter.cpp +++ b/src/client/cli/formatter/table_formatter.cpp @@ -16,8 +16,8 @@ */ #include - #include +#include #include @@ -225,8 +225,15 @@ std::string mp::TableFormatter::format(const FindReply& reply) const std::string mp::TableFormatter::format(const VersionReply& reply, const std::string& multipassVer) const { fmt::memory_buffer buf; + fmt::format_to(buf, "{:<16}{}\n", "multipass:", multipassVer); + fmt::format_to(buf, "{:<16}{}\n", "multipassd:", reply.version()); - // TODO: STUBBED. + if (mp::cmd::update_available(reply.update_info())) + { + fmt::format_to(buf, "{:<16}{}\n", "title:", reply.update_info().title()); + fmt::format_to(buf, "{:<16}{}\n", "description:", reply.update_info().description()); + fmt::format_to(buf, "{:<16}{}\n", "url:", reply.update_info().url()); + } return fmt::to_string(buf); } diff --git a/tests/test_output_formatter.cpp b/tests/test_output_formatter.cpp index 8dbd6d44dd..e3422e937b 100644 --- a/tests/test_output_formatter.cpp +++ b/tests/test_output_formatter.cpp @@ -1081,6 +1081,21 @@ const auto version_daemon_no_update_reply = construct_version_info_multipassd_up const auto version_daemon_update_reply = construct_version_info_multipassd_update_available(); const std::vector version_formatter_outputs { + {&table_formatter, &version_client_reply, + "multipass: Client version\n" + "multipassd: \n", + "table_version_client"}, + {&table_formatter, &version_daemon_no_update_reply, + "multipass: Client version\n" + "multipassd: Daemon version\n", + "table_version_daemon_no_updates"}, + {&table_formatter, &version_daemon_update_reply, + "multipass: Client version\n" + "multipassd: Daemon version\n" + "title: update title information\n" + "description: update description information\n" + "url: http://multipass.web\n", + "table_version_daemon_updates"}, {&json_formatter, &version_client_reply, "{\n" " \"multipass\": \"Client version\",\n" From 0a940654c1346e355e91828cf36b25a32ecdfd93 Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Mon, 10 May 2021 22:07:46 -0400 Subject: [PATCH 28/53] [cli] removed duplicate fields from record. --- tests/test_output_formatter.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/test_output_formatter.cpp b/tests/test_output_formatter.cpp index e3422e937b..f39284bfb2 100644 --- a/tests/test_output_formatter.cpp +++ b/tests/test_output_formatter.cpp @@ -1131,12 +1131,17 @@ const std::vector version_formatter_outputs { "Multipass,Multipassd,Title,Description,URL\n" "Client version,Daemon version,update title information,update description information,http://multipass.web\n", "csv_version_daemon_updates"}, - {&yaml_formatter, &version_client_reply, "version: Client version\n", "yaml_version_client"}, + {&yaml_formatter, &version_client_reply, + "multipass: Client version\n" + "multipassd: \"\"\n", + "yaml_version_client"}, {&yaml_formatter, &version_daemon_no_update_reply, - "version: Daemon version\n", + "multipass: Client version\n" + "multipassd: Daemon version\n", "yaml_version_daemon_no_updates"}, {&yaml_formatter, &version_daemon_update_reply, - "version: Daemon version\n" + "multipass: Client version\n" + "multipassd: Daemon version\n" "update:\n title: update title information\n" " description: update description information\n" " url: \"http://multipass.web\"\n", From e0c71360fc3b8df68f47be1c1d703cb2fd0be735 Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Mon, 10 May 2021 22:07:46 -0400 Subject: [PATCH 29/53] [cli]
no long displaying if is empty. --- src/client/cli/formatter/table_formatter.cpp | 15 +++++++++------ tests/test_output_formatter.cpp | 3 +-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/client/cli/formatter/table_formatter.cpp b/src/client/cli/formatter/table_formatter.cpp index c069bbf1ba..14850b11fe 100644 --- a/src/client/cli/formatter/table_formatter.cpp +++ b/src/client/cli/formatter/table_formatter.cpp @@ -226,14 +226,17 @@ std::string mp::TableFormatter::format(const VersionReply& reply, const std::str { fmt::memory_buffer buf; fmt::format_to(buf, "{:<16}{}\n", "multipass:", multipassVer); - fmt::format_to(buf, "{:<16}{}\n", "multipassd:", reply.version()); - if (mp::cmd::update_available(reply.update_info())) + if (!reply.version().empty()) { - fmt::format_to(buf, "{:<16}{}\n", "title:", reply.update_info().title()); - fmt::format_to(buf, "{:<16}{}\n", "description:", reply.update_info().description()); - fmt::format_to(buf, "{:<16}{}\n", "url:", reply.update_info().url()); - } + fmt::format_to(buf, "{:<16}{}\n", "multipassd:", reply.version()); + if (mp::cmd::update_available(reply.update_info())) + { + fmt::format_to(buf, "{:<16}{}\n", "title:", reply.update_info().title()); + fmt::format_to(buf, "{:<16}{}\n", "description:", reply.update_info().description()); + fmt::format_to(buf, "{:<16}{}\n", "url:", reply.update_info().url()); + } + } return fmt::to_string(buf); } diff --git a/tests/test_output_formatter.cpp b/tests/test_output_formatter.cpp index f39284bfb2..6171b219f1 100644 --- a/tests/test_output_formatter.cpp +++ b/tests/test_output_formatter.cpp @@ -1082,8 +1082,7 @@ const auto version_daemon_update_reply = construct_version_info_multipassd_updat const std::vector version_formatter_outputs { {&table_formatter, &version_client_reply, - "multipass: Client version\n" - "multipassd: \n", + "multipass: Client version\n", "table_version_client"}, {&table_formatter, &version_daemon_no_update_reply, "multipass: Client version\n" From b7ff10f8583afed1db7e6e97530ea7d624abc8e5 Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Mon, 10 May 2021 22:07:46 -0400 Subject: [PATCH 30/53] [cli] no long displaying if is empty. --- src/client/cli/formatter/json_formatter.cpp | 19 +++++++++++-------- tests/test_output_formatter.cpp | 3 +-- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/client/cli/formatter/json_formatter.cpp b/src/client/cli/formatter/json_formatter.cpp index 42b72b7727..79a2e2f5d9 100644 --- a/src/client/cli/formatter/json_formatter.cpp +++ b/src/client/cli/formatter/json_formatter.cpp @@ -194,17 +194,20 @@ std::string mp::JsonFormatter::format(const VersionReply& reply, const std::stri QJsonObject version_json; version_json.insert("multipass", QString::fromStdString(multipassVer)); - version_json.insert("multipassd", QString::fromStdString(reply.version())); - if (mp::cmd::update_available(reply.update_info())) + if (!reply.version().empty()) { - QJsonObject update; - update.insert("title", QString::fromStdString(reply.update_info().title())); - update.insert("description", QString::fromStdString(reply.update_info().description())); - update.insert("url", QString::fromStdString(reply.update_info().url())); + version_json.insert("multipassd", QString::fromStdString(reply.version())); - version_json.insert("update", update); - } + if (mp::cmd::update_available(reply.update_info())) + { + QJsonObject update; + update.insert("title", QString::fromStdString(reply.update_info().title())); + update.insert("description", QString::fromStdString(reply.update_info().description())); + update.insert("url", QString::fromStdString(reply.update_info().url())); + version_json.insert("update", update); + } + } return QString(QJsonDocument(version_json).toJson()).toStdString(); } diff --git a/tests/test_output_formatter.cpp b/tests/test_output_formatter.cpp index 6171b219f1..bedd39807d 100644 --- a/tests/test_output_formatter.cpp +++ b/tests/test_output_formatter.cpp @@ -1097,8 +1097,7 @@ const std::vector version_formatter_outputs { "table_version_daemon_updates"}, {&json_formatter, &version_client_reply, "{\n" - " \"multipass\": \"Client version\",\n" - " \"multipassd\": \"\"\n" + " \"multipass\": \"Client version\"\n" "}\n", "json_version_client"}, {&json_formatter, &version_daemon_no_update_reply, From e2ca2dcb525b5ad9ff973bea6fa6b566fdb2d70e Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Mon, 10 May 2021 22:07:46 -0400 Subject: [PATCH 31/53] [cli] no long displaying if is empty. --- src/client/cli/formatter/yaml_formatter.cpp | 18 +++++++++++------- tests/test_output_formatter.cpp | 3 +-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/client/cli/formatter/yaml_formatter.cpp b/src/client/cli/formatter/yaml_formatter.cpp index 286e6151b1..4ba06809c2 100644 --- a/src/client/cli/formatter/yaml_formatter.cpp +++ b/src/client/cli/formatter/yaml_formatter.cpp @@ -185,16 +185,20 @@ std::string mp::YamlFormatter::format(const VersionReply& reply, const std::stri { YAML::Node version; version["multipass"] = multipassVer; - version["multipassd"] = reply.version(); - if (mp::cmd::update_available(reply.update_info())) + if (!reply.version().empty()) { - YAML::Node update; - update["title"] = reply.update_info().title(); - update["description"] = reply.update_info().description(); - update["url"] = reply.update_info().url(); + version["multipassd"] = reply.version(); - version["update"] = update; + if (mp::cmd::update_available(reply.update_info())) + { + YAML::Node update; + update["title"] = reply.update_info().title(); + update["description"] = reply.update_info().description(); + update["url"] = reply.update_info().url(); + + version["update"] = update; + } } return mpu::emit_yaml(version); diff --git a/tests/test_output_formatter.cpp b/tests/test_output_formatter.cpp index bedd39807d..250a6adaeb 100644 --- a/tests/test_output_formatter.cpp +++ b/tests/test_output_formatter.cpp @@ -1130,8 +1130,7 @@ const std::vector version_formatter_outputs { "Client version,Daemon version,update title information,update description information,http://multipass.web\n", "csv_version_daemon_updates"}, {&yaml_formatter, &version_client_reply, - "multipass: Client version\n" - "multipassd: \"\"\n", + "multipass: Client version\n", "yaml_version_client"}, {&yaml_formatter, &version_daemon_no_update_reply, "multipass: Client version\n" From 96b356c76f3a845e6aad7a4951741d28a162bf0f Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Mon, 10 May 2021 22:07:46 -0400 Subject: [PATCH 32/53] [cli] wired up to formatters. --- src/client/cli/cmd/version.cpp | 35 ++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/client/cli/cmd/version.cpp b/src/client/cli/cmd/version.cpp index 4508e64656..f8b30016f9 100644 --- a/src/client/cli/cmd/version.cpp +++ b/src/client/cli/cmd/version.cpp @@ -18,6 +18,7 @@ #include "version.h" #include "common_cli.h" #include +#include #include namespace mp = multipass; @@ -32,17 +33,39 @@ mp::ReturnCode cmd::Version::run(mp::ArgParser* parser) return parser->returnCodeFrom(ret); } - cout << "multipass " << multipass::version_string << "\n"; + bool formatIsSet = parser->isSet("format"); - auto on_success = [this](mp::VersionReply& reply) { - cout << "multipassd " << reply.version() << "\n"; - if (term->is_live() && update_available(reply.update_info())) - cout << update_notice(reply.update_info()); + if (!formatIsSet) + { + cout << "multipass " << multipass::version_string << "\n"; + } + + auto on_success = [this, &formatIsSet] (mp::VersionReply& reply) { + + if (formatIsSet) + { + cout << chosen_formatter->format(reply, multipass::version_string); + } + else + { + cout << "multipassd " << reply.version() << "\n"; + if (term->is_live() && update_available(reply.update_info())) + cout << update_notice(reply.update_info()); + } return ReturnCode::Ok; }; - auto on_failure = [](grpc::Status& status) { return ReturnCode::Ok; }; + auto on_failure = [this, &formatIsSet](grpc::Status& status) { + + if (formatIsSet) + { + VersionReply reply; + cout << chosen_formatter->format(reply, multipass::version_string); + } + + return ReturnCode::Ok; + }; mp::VersionRequest request; request.set_verbosity_level(parser->verbosityLevel()); From b6efdf290d83764c2be2befbe155a76e19435078 Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Tue, 18 May 2021 17:34:23 -0400 Subject: [PATCH 33/53] [cli] clang-formatted. --- include/multipass/cli/formatter.h | 2 +- src/client/cli/cmd/version.cpp | 4 +--- src/client/cli/formatter/csv_formatter.cpp | 9 +++------ src/client/cli/formatter/json_formatter.cpp | 8 ++++---- src/client/cli/formatter/table_formatter.cpp | 8 ++++---- src/client/cli/formatter/yaml_formatter.cpp | 8 ++++---- tests/test_output_formatter.cpp | 21 +++++++------------- 7 files changed, 24 insertions(+), 36 deletions(-) diff --git a/include/multipass/cli/formatter.h b/include/multipass/cli/formatter.h index 8b1e697d6e..3c859b3f8d 100644 --- a/include/multipass/cli/formatter.h +++ b/include/multipass/cli/formatter.h @@ -36,7 +36,7 @@ class Formatter virtual std::string format(const ListReply& reply) const = 0; virtual std::string format(const NetworksReply& reply) const = 0; virtual std::string format(const FindReply& reply) const = 0; - virtual std::string format(const VersionReply& reply, const std::string& multipassVer) const = 0; + virtual std::string format(const VersionReply& reply, const std::string& multipass_version) const = 0; protected: Formatter() = default; diff --git a/src/client/cli/cmd/version.cpp b/src/client/cli/cmd/version.cpp index f8b30016f9..18895bfec7 100644 --- a/src/client/cli/cmd/version.cpp +++ b/src/client/cli/cmd/version.cpp @@ -40,8 +40,7 @@ mp::ReturnCode cmd::Version::run(mp::ArgParser* parser) cout << "multipass " << multipass::version_string << "\n"; } - auto on_success = [this, &formatIsSet] (mp::VersionReply& reply) { - + auto on_success = [this, &formatIsSet](mp::VersionReply& reply) { if (formatIsSet) { cout << chosen_formatter->format(reply, multipass::version_string); @@ -57,7 +56,6 @@ mp::ReturnCode cmd::Version::run(mp::ArgParser* parser) }; auto on_failure = [this, &formatIsSet](grpc::Status& status) { - if (formatIsSet) { VersionReply reply; diff --git a/src/client/cli/formatter/csv_formatter.cpp b/src/client/cli/formatter/csv_formatter.cpp index f6b488cc85..46bdb7a808 100644 --- a/src/client/cli/formatter/csv_formatter.cpp +++ b/src/client/cli/formatter/csv_formatter.cpp @@ -101,17 +101,14 @@ std::string mp::CSVFormatter::format(const FindReply& reply) const return fmt::to_string(buf); } -std::string mp::CSVFormatter::format(const VersionReply& reply, const std::string& multipassVer) const +std::string mp::CSVFormatter::format(const VersionReply& reply, const std::string& multipass_version) const { fmt::memory_buffer buf; fmt::format_to(buf, "Multipass,Multipassd,Title,Description,URL\n"); - fmt::format_to(buf, "{},{},{},{},{}\n", multipassVer, - reply.version(), - reply.update_info().title(), - reply.update_info().description(), - reply.update_info().url()); + fmt::format_to(buf, "{},{},{},{},{}\n", multipass_version, reply.version(), reply.update_info().title(), + reply.update_info().description(), reply.update_info().url()); return fmt::to_string(buf); } \ No newline at end of file diff --git a/src/client/cli/formatter/json_formatter.cpp b/src/client/cli/formatter/json_formatter.cpp index 79a2e2f5d9..0d046d5e0e 100644 --- a/src/client/cli/formatter/json_formatter.cpp +++ b/src/client/cli/formatter/json_formatter.cpp @@ -15,9 +15,9 @@ * */ -#include -#include #include +#include +#include #include #include @@ -189,11 +189,11 @@ std::string mp::JsonFormatter::format(const FindReply& reply) const return QString(QJsonDocument(find_json).toJson()).toStdString(); } -std::string mp::JsonFormatter::format(const VersionReply& reply, const std::string& multipassVer) const +std::string mp::JsonFormatter::format(const VersionReply& reply, const std::string& multipass_version) const { QJsonObject version_json; - version_json.insert("multipass", QString::fromStdString(multipassVer)); + version_json.insert("multipass", QString::fromStdString(multipass_version)); if (!reply.version().empty()) { diff --git a/src/client/cli/formatter/table_formatter.cpp b/src/client/cli/formatter/table_formatter.cpp index 14850b11fe..c76bdb50bb 100644 --- a/src/client/cli/formatter/table_formatter.cpp +++ b/src/client/cli/formatter/table_formatter.cpp @@ -15,9 +15,9 @@ * */ -#include -#include #include +#include +#include #include @@ -222,10 +222,10 @@ std::string mp::TableFormatter::format(const FindReply& reply) const return fmt::to_string(buf); } -std::string mp::TableFormatter::format(const VersionReply& reply, const std::string& multipassVer) const +std::string mp::TableFormatter::format(const VersionReply& reply, const std::string& multipass_version) const { fmt::memory_buffer buf; - fmt::format_to(buf, "{:<16}{}\n", "multipass:", multipassVer); + fmt::format_to(buf, "{:<16}{}\n", "multipass:", multipass_version); if (!reply.version().empty()) { diff --git a/src/client/cli/formatter/yaml_formatter.cpp b/src/client/cli/formatter/yaml_formatter.cpp index 4ba06809c2..67db49a96c 100644 --- a/src/client/cli/formatter/yaml_formatter.cpp +++ b/src/client/cli/formatter/yaml_formatter.cpp @@ -15,9 +15,9 @@ * */ -#include -#include #include +#include +#include #include #include @@ -181,10 +181,10 @@ std::string mp::YamlFormatter::format(const FindReply& reply) const return mpu::emit_yaml(find); } -std::string mp::YamlFormatter::format(const VersionReply& reply, const std::string& multipassVer) const +std::string mp::YamlFormatter::format(const VersionReply& reply, const std::string& multipass_version) const { YAML::Node version; - version["multipass"] = multipassVer; + version["multipass"] = multipass_version; if (!reply.version().empty()) { diff --git a/tests/test_output_formatter.cpp b/tests/test_output_formatter.cpp index 250a6adaeb..83b57ee4a3 100644 --- a/tests/test_output_formatter.cpp +++ b/tests/test_output_formatter.cpp @@ -325,7 +325,7 @@ auto construct_version_info_multipassd_update_available() reply.set_version("Daemon version"); reply.set_log_line("Some logline goes here"); - mp::UpdateInfo *updateInfo = new mp::UpdateInfo; // Leak? expecting protobuf to deal with memory dealloc. + mp::UpdateInfo* updateInfo = new mp::UpdateInfo; // Leak? expecting protobuf to deal with memory dealloc. updateInfo->set_version("update version number"); updateInfo->set_title("update title information"); updateInfo->set_description("update description information"); @@ -1080,10 +1080,8 @@ const auto version_client_reply = mp::VersionReply(); const auto version_daemon_no_update_reply = construct_version_info_multipassd_up_to_date(); const auto version_daemon_update_reply = construct_version_info_multipassd_update_available(); -const std::vector version_formatter_outputs { - {&table_formatter, &version_client_reply, - "multipass: Client version\n", - "table_version_client"}, +const std::vector version_formatter_outputs{ + {&table_formatter, &version_client_reply, "multipass: Client version\n", "table_version_client"}, {&table_formatter, &version_daemon_no_update_reply, "multipass: Client version\n" "multipassd: Daemon version\n", @@ -1129,9 +1127,7 @@ const std::vector version_formatter_outputs { "Multipass,Multipassd,Title,Description,URL\n" "Client version,Daemon version,update title information,update description information,http://multipass.web\n", "csv_version_daemon_updates"}, - {&yaml_formatter, &version_client_reply, - "multipass: Client version\n", - "yaml_version_client"}, + {&yaml_formatter, &version_client_reply, "multipass: Client version\n", "yaml_version_client"}, {&yaml_formatter, &version_daemon_no_update_reply, "multipass: Client version\n" "multipassd: Daemon version\n", @@ -1142,13 +1138,10 @@ const std::vector version_formatter_outputs { "update:\n title: update title information\n" " description: update description information\n" " url: \"http://multipass.web\"\n", - "yaml_version_daemon_updates"} -}; + "yaml_version_daemon_updates"}}; } // namespace - - TEST_P(FormatterSuite, properly_formats_output) { const auto& [formatter, reply, expected_output, test_name] = GetParam(); @@ -1179,8 +1172,8 @@ INSTANTIATE_TEST_SUITE_P(NonOrderableListInfoOutputFormatter, FormatterSuite, INSTANTIATE_TEST_SUITE_P(FindOutputFormatter, FormatterSuite, ValuesIn(find_formatter_outputs), print_param_name); INSTANTIATE_TEST_SUITE_P(NonOrderableNetworksOutputFormatter, FormatterSuite, ValuesIn(non_orderable_networks_formatter_outputs), print_param_name); -INSTANTIATE_TEST_SUITE_P(VersionInfoOutputFormatter, FormatterSuite, - ValuesIn(version_formatter_outputs), print_param_name); +INSTANTIATE_TEST_SUITE_P(VersionInfoOutputFormatter, FormatterSuite, ValuesIn(version_formatter_outputs), + print_param_name); #if GTEST_HAS_POSIX_RE TEST_P(PetenvFormatterSuite, pet_env_first_in_output) From 91f0ca9e0bd095ba358ed4166d6dab8aa029291c Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Sat, 19 Jun 2021 13:39:17 -0400 Subject: [PATCH 34/53] Restoring original .gitignore. --- .gitignore | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.gitignore b/.gitignore index 98613d450d..a1c0324d87 100644 --- a/.gitignore +++ b/.gitignore @@ -11,7 +11,3 @@ parts prime stage snap/.snapcraft/state - -build/ - -multipass-build-deps* From a75a3ea260562ec812270a4f9c07b48937c0ce0a Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Sat, 19 Jun 2021 14:02:31 -0400 Subject: [PATCH 35/53] [cli] correct formatting for variable names. --- include/multipass/cli/csv_formatter.h | 2 +- include/multipass/cli/json_formatter.h | 2 +- include/multipass/cli/table_formatter.h | 2 +- include/multipass/cli/yaml_formatter.h | 2 +- src/client/cli/cmd/version.cpp | 12 ++++++------ 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/multipass/cli/csv_formatter.h b/include/multipass/cli/csv_formatter.h index 3f073884c7..7af108a103 100644 --- a/include/multipass/cli/csv_formatter.h +++ b/include/multipass/cli/csv_formatter.h @@ -29,7 +29,7 @@ class CSVFormatter final : public Formatter std::string format(const ListReply& list) const override; std::string format(const NetworksReply& list) const override; std::string format(const FindReply& list) const override; - std::string format(const VersionReply& list, const std::string& multipassVer) const override; + std::string format(const VersionReply& list, const std::string& multipass_version) const override; }; } #endif // MULTIPASS_CSV_FORMATTER diff --git a/include/multipass/cli/json_formatter.h b/include/multipass/cli/json_formatter.h index 4ca1d76674..843317940a 100644 --- a/include/multipass/cli/json_formatter.h +++ b/include/multipass/cli/json_formatter.h @@ -29,7 +29,7 @@ class JsonFormatter final : public Formatter std::string format(const ListReply& list) const override; std::string format(const NetworksReply& list) const override; std::string format(const FindReply& list) const override; - std::string format(const VersionReply& list, const std::string& multipassVer) const override; + std::string format(const VersionReply& list, const std::string& multipass_version) const override; }; } #endif // MULTIPASS_JSON_FORMATTER diff --git a/include/multipass/cli/table_formatter.h b/include/multipass/cli/table_formatter.h index 0a30ab44c6..0340ff2dde 100644 --- a/include/multipass/cli/table_formatter.h +++ b/include/multipass/cli/table_formatter.h @@ -29,7 +29,7 @@ class TableFormatter final : public Formatter std::string format(const ListReply& list) const override; std::string format(const NetworksReply& list) const override; std::string format(const FindReply& list) const override; - std::string format(const VersionReply& list, const std::string& multipassVer) const override; + std::string format(const VersionReply& list, const std::string& multipass_version) const override; }; } #endif // MULTIPASS_TABLE_FORMATTER diff --git a/include/multipass/cli/yaml_formatter.h b/include/multipass/cli/yaml_formatter.h index a8ee66674b..36d046bce4 100644 --- a/include/multipass/cli/yaml_formatter.h +++ b/include/multipass/cli/yaml_formatter.h @@ -29,7 +29,7 @@ class YamlFormatter final : public Formatter std::string format(const ListReply& list) const override; std::string format(const NetworksReply& list) const override; std::string format(const FindReply& list) const override; - std::string format(const VersionReply& list, const std::string& multipassVer) const override; + std::string format(const VersionReply& list, const std::string& multipass_version) const override; }; } #endif // MULTIPASS_YAML_FORMATTER diff --git a/src/client/cli/cmd/version.cpp b/src/client/cli/cmd/version.cpp index 18895bfec7..ec57099cc8 100644 --- a/src/client/cli/cmd/version.cpp +++ b/src/client/cli/cmd/version.cpp @@ -33,15 +33,15 @@ mp::ReturnCode cmd::Version::run(mp::ArgParser* parser) return parser->returnCodeFrom(ret); } - bool formatIsSet = parser->isSet("format"); + bool format_is_set = parser->isSet("format"); - if (!formatIsSet) + if (!format_is_set) { cout << "multipass " << multipass::version_string << "\n"; } - auto on_success = [this, &formatIsSet](mp::VersionReply& reply) { - if (formatIsSet) + auto on_success = [this, &format_is_set](mp::VersionReply& reply) { + if (format_is_set) { cout << chosen_formatter->format(reply, multipass::version_string); } @@ -55,8 +55,8 @@ mp::ReturnCode cmd::Version::run(mp::ArgParser* parser) return ReturnCode::Ok; }; - auto on_failure = [this, &formatIsSet](grpc::Status& status) { - if (formatIsSet) + auto on_failure = [this, &format_is_set](grpc::Status& status) { + if (format_is_set) { VersionReply reply; cout << chosen_formatter->format(reply, multipass::version_string); From d3fc062fb673bc3877c246d9c0428912ce9a38d3 Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Sat, 19 Jun 2021 16:20:47 -0400 Subject: [PATCH 36/53] [cli] updates to messages. --- src/client/cli/cmd/version.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/client/cli/cmd/version.cpp b/src/client/cli/cmd/version.cpp index ec57099cc8..ed0cd9e583 100644 --- a/src/client/cli/cmd/version.cpp +++ b/src/client/cli/cmd/version.cpp @@ -88,9 +88,10 @@ QString cmd::Version::description() const mp::ParseCode cmd::Version::parse_args(mp::ArgParser* parser) { - QCommandLineOption formatOption( - "format", "Output list in the requested format.\nValid formats are: table (default), json, csv and yaml", - "format", "table"); + QCommandLineOption formatOption("format", + "Output list in the requested format.\n" + "Valid formats are: table (default), json, csv and yaml", + "format", "table"); parser->addOption(formatOption); @@ -103,7 +104,7 @@ mp::ParseCode cmd::Version::parse_args(mp::ArgParser* parser) if (parser->positionalArguments().count() > 0) { - cerr << "Wrong number of arguments\n"; + cerr << "This command takes no arguments\n"; return ParseCode::CommandLineError; } From 275b3d5c02b773657b588f191db3129fdb715bf9 Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Sat, 19 Jun 2021 16:21:19 -0400 Subject: [PATCH 37/53] [tests] cli version format tests. --- tests/test_cli_client.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/test_cli_client.cpp b/tests/test_cli_client.cpp index 4fe0cca7ec..db948c18a0 100644 --- a/tests/test_cli_client.cpp +++ b/tests/test_cli_client.cpp @@ -1063,6 +1063,32 @@ TEST_F(Client, start_cmd_can_target_petenv_among_others) EXPECT_THAT(send_command({"start", "foo", petenv_name(), "bar", "baz"}), Eq(mp::ReturnCode::Ok)); } +// version cli tests +TEST_F(Client, version_without_arg) +{ + EXPECT_CALL(mock_daemon, version(_, _, _)); + EXPECT_THAT(send_command({"version"}), Eq(mp::ReturnCode::Ok)); +} + +TEST_F(Client, version_with_positional_format_arg) +{ + EXPECT_THAT(send_command({"version", "format"}), Eq(mp::ReturnCode::CommandLineError)); +} + +TEST_F(Client, version_with_option_format_arg) +{ + EXPECT_CALL(mock_daemon, version(_, _, _)).Times(4); + EXPECT_THAT(send_command({"version", "--format=table"}), Eq(mp::ReturnCode::Ok)); + EXPECT_THAT(send_command({"version", "--format=yaml"}), Eq(mp::ReturnCode::Ok)); + EXPECT_THAT(send_command({"version", "--format=json"}), Eq(mp::ReturnCode::Ok)); + EXPECT_THAT(send_command({"version", "--format=csv"}), Eq(mp::ReturnCode::Ok)); +} + +TEST_F(Client, version_with_option_format_invalid_arg) +{ + EXPECT_THAT(send_command({"version", "--format=default"}), Eq(mp::ReturnCode::CommandLineError)); +} + namespace { grpc::Status aborted_start_status(const std::vector& absent_instances = {}, From 59d9bec679c7211491805db93ff8ab639619c413 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sawicz?= Date: Tue, 27 Jul 2021 19:58:18 +0200 Subject: [PATCH 38/53] Fix linting --- src/client/cli/cmd/version.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/client/cli/cmd/version.cpp b/src/client/cli/cmd/version.cpp index ed0cd9e583..7818d388f1 100644 --- a/src/client/cli/cmd/version.cpp +++ b/src/client/cli/cmd/version.cpp @@ -40,7 +40,8 @@ mp::ReturnCode cmd::Version::run(mp::ArgParser* parser) cout << "multipass " << multipass::version_string << "\n"; } - auto on_success = [this, &format_is_set](mp::VersionReply& reply) { + auto on_success = [this, &format_is_set](mp::VersionReply& reply) + { if (format_is_set) { cout << chosen_formatter->format(reply, multipass::version_string); @@ -55,7 +56,8 @@ mp::ReturnCode cmd::Version::run(mp::ArgParser* parser) return ReturnCode::Ok; }; - auto on_failure = [this, &format_is_set](grpc::Status& status) { + auto on_failure = [this, &format_is_set](grpc::Status& status) + { if (format_is_set) { VersionReply reply; From bd7242384d479ba5cd87ee4f8f87e6e6f80f04d7 Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Wed, 28 Jul 2021 10:46:06 -0400 Subject: [PATCH 39/53] [cli] switching parameter to a more appropriate variable name. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Michał Sawicz --- include/multipass/cli/csv_formatter.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/multipass/cli/csv_formatter.h b/include/multipass/cli/csv_formatter.h index 7af108a103..0e5c8910a7 100644 --- a/include/multipass/cli/csv_formatter.h +++ b/include/multipass/cli/csv_formatter.h @@ -29,7 +29,7 @@ class CSVFormatter final : public Formatter std::string format(const ListReply& list) const override; std::string format(const NetworksReply& list) const override; std::string format(const FindReply& list) const override; - std::string format(const VersionReply& list, const std::string& multipass_version) const override; + std::string format(const VersionReply& list, const std::string& client_version) const override; }; } #endif // MULTIPASS_CSV_FORMATTER From d8933e4c4f709731cb56e2a86f66d5dd23d6f166 Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Wed, 28 Jul 2021 10:48:06 -0400 Subject: [PATCH 40/53] [cli] updated option info message. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Michał Sawicz --- src/client/cli/cmd/version.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/cli/cmd/version.cpp b/src/client/cli/cmd/version.cpp index 7818d388f1..42b94802c6 100644 --- a/src/client/cli/cmd/version.cpp +++ b/src/client/cli/cmd/version.cpp @@ -91,7 +91,7 @@ QString cmd::Version::description() const mp::ParseCode cmd::Version::parse_args(mp::ArgParser* parser) { QCommandLineOption formatOption("format", - "Output list in the requested format.\n" + "Output version information in the requested format.\n" "Valid formats are: table (default), json, csv and yaml", "format", "table"); From 21aa1d13f4f9f925b53be0aa3aac6ca464a50703 Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Wed, 28 Jul 2021 11:21:48 -0400 Subject: [PATCH 41/53] Copyright updated to 2021. --- include/multipass/cli/csv_formatter.h | 2 +- include/multipass/cli/formatter.h | 2 +- include/multipass/cli/json_formatter.h | 2 +- include/multipass/cli/table_formatter.h | 2 +- include/multipass/cli/yaml_formatter.h | 2 +- src/client/cli/cmd/version.cpp | 2 +- src/client/cli/cmd/version.h | 2 +- src/client/cli/formatter/csv_formatter.cpp | 2 +- src/client/cli/formatter/format_utils.cpp | 2 +- src/client/cli/formatter/json_formatter.cpp | 2 +- src/client/cli/formatter/table_formatter.cpp | 2 +- src/client/cli/formatter/yaml_formatter.cpp | 2 +- tests/test_output_formatter.cpp | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/include/multipass/cli/csv_formatter.h b/include/multipass/cli/csv_formatter.h index 0e5c8910a7..79e4430cbf 100644 --- a/include/multipass/cli/csv_formatter.h +++ b/include/multipass/cli/csv_formatter.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2020 Canonical, Ltd. + * Copyright (C) 2018-2021 Canonical, Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/include/multipass/cli/formatter.h b/include/multipass/cli/formatter.h index 3c859b3f8d..6d2641dfb6 100644 --- a/include/multipass/cli/formatter.h +++ b/include/multipass/cli/formatter.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2020 Canonical, Ltd. + * Copyright (C) 2018-2021 Canonical, Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/include/multipass/cli/json_formatter.h b/include/multipass/cli/json_formatter.h index 843317940a..c415567878 100644 --- a/include/multipass/cli/json_formatter.h +++ b/include/multipass/cli/json_formatter.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2020 Canonical, Ltd. + * Copyright (C) 2018-2021 Canonical, Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/include/multipass/cli/table_formatter.h b/include/multipass/cli/table_formatter.h index 0340ff2dde..1182604691 100644 --- a/include/multipass/cli/table_formatter.h +++ b/include/multipass/cli/table_formatter.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2020 Canonical, Ltd. + * Copyright (C) 2018-2021 Canonical, Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/include/multipass/cli/yaml_formatter.h b/include/multipass/cli/yaml_formatter.h index 36d046bce4..2db8db4f44 100644 --- a/include/multipass/cli/yaml_formatter.h +++ b/include/multipass/cli/yaml_formatter.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2020 Canonical, Ltd. + * Copyright (C) 2018-2021 Canonical, Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/client/cli/cmd/version.cpp b/src/client/cli/cmd/version.cpp index 42b94802c6..e639302a9d 100644 --- a/src/client/cli/cmd/version.cpp +++ b/src/client/cli/cmd/version.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 Canonical, Ltd. + * Copyright (C) 2017-2021 Canonical, Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/client/cli/cmd/version.h b/src/client/cli/cmd/version.h index 070d722bc7..272445fa02 100644 --- a/src/client/cli/cmd/version.h +++ b/src/client/cli/cmd/version.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 Canonical, Ltd. + * Copyright (C) 2017-2021 Canonical, Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/client/cli/formatter/csv_formatter.cpp b/src/client/cli/formatter/csv_formatter.cpp index 46bdb7a808..2e410134e4 100644 --- a/src/client/cli/formatter/csv_formatter.cpp +++ b/src/client/cli/formatter/csv_formatter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2020 Canonical, Ltd. + * Copyright (C) 2018-2021 Canonical, Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/client/cli/formatter/format_utils.cpp b/src/client/cli/formatter/format_utils.cpp index 7b528813c5..9f5788e096 100644 --- a/src/client/cli/formatter/format_utils.cpp +++ b/src/client/cli/formatter/format_utils.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Canonical, Ltd. + * Copyright (C) 2018-2021 Canonical, Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/client/cli/formatter/json_formatter.cpp b/src/client/cli/formatter/json_formatter.cpp index 0d046d5e0e..d54839bca0 100644 --- a/src/client/cli/formatter/json_formatter.cpp +++ b/src/client/cli/formatter/json_formatter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2020 Canonical, Ltd. + * Copyright (C) 2018-2021 Canonical, Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/client/cli/formatter/table_formatter.cpp b/src/client/cli/formatter/table_formatter.cpp index c76bdb50bb..061ee6da25 100644 --- a/src/client/cli/formatter/table_formatter.cpp +++ b/src/client/cli/formatter/table_formatter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2020 Canonical, Ltd. + * Copyright (C) 2018-2021 Canonical, Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/client/cli/formatter/yaml_formatter.cpp b/src/client/cli/formatter/yaml_formatter.cpp index 67db49a96c..868a79c19c 100644 --- a/src/client/cli/formatter/yaml_formatter.cpp +++ b/src/client/cli/formatter/yaml_formatter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2020 Canonical, Ltd. + * Copyright (C) 2018-2021 Canonical, Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/tests/test_output_formatter.cpp b/tests/test_output_formatter.cpp index 83b57ee4a3..f143eef9fb 100644 --- a/tests/test_output_formatter.cpp +++ b/tests/test_output_formatter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2020 Canonical, Ltd. + * Copyright (C) 2018-2021 Canonical, Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by From 03605c8875d9f4bc13176afc6d1bd156cfebcc61 Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Wed, 28 Jul 2021 11:25:04 -0400 Subject: [PATCH 42/53] [cli] switching from to . --- include/multipass/cli/formatter.h | 2 +- include/multipass/cli/json_formatter.h | 2 +- include/multipass/cli/table_formatter.h | 2 +- include/multipass/cli/yaml_formatter.h | 2 +- src/client/cli/formatter/csv_formatter.cpp | 6 +++--- src/client/cli/formatter/json_formatter.cpp | 4 ++-- src/client/cli/formatter/table_formatter.cpp | 4 ++-- src/client/cli/formatter/yaml_formatter.cpp | 4 ++-- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/include/multipass/cli/formatter.h b/include/multipass/cli/formatter.h index 6d2641dfb6..60618a44c8 100644 --- a/include/multipass/cli/formatter.h +++ b/include/multipass/cli/formatter.h @@ -36,7 +36,7 @@ class Formatter virtual std::string format(const ListReply& reply) const = 0; virtual std::string format(const NetworksReply& reply) const = 0; virtual std::string format(const FindReply& reply) const = 0; - virtual std::string format(const VersionReply& reply, const std::string& multipass_version) const = 0; + virtual std::string format(const VersionReply& reply, const std::string& client_version) const = 0; protected: Formatter() = default; diff --git a/include/multipass/cli/json_formatter.h b/include/multipass/cli/json_formatter.h index c415567878..ff1e2da1ba 100644 --- a/include/multipass/cli/json_formatter.h +++ b/include/multipass/cli/json_formatter.h @@ -29,7 +29,7 @@ class JsonFormatter final : public Formatter std::string format(const ListReply& list) const override; std::string format(const NetworksReply& list) const override; std::string format(const FindReply& list) const override; - std::string format(const VersionReply& list, const std::string& multipass_version) const override; + std::string format(const VersionReply& list, const std::string& client_version) const override; }; } #endif // MULTIPASS_JSON_FORMATTER diff --git a/include/multipass/cli/table_formatter.h b/include/multipass/cli/table_formatter.h index 1182604691..3de1e36da3 100644 --- a/include/multipass/cli/table_formatter.h +++ b/include/multipass/cli/table_formatter.h @@ -29,7 +29,7 @@ class TableFormatter final : public Formatter std::string format(const ListReply& list) const override; std::string format(const NetworksReply& list) const override; std::string format(const FindReply& list) const override; - std::string format(const VersionReply& list, const std::string& multipass_version) const override; + std::string format(const VersionReply& list, const std::string& client_version) const override; }; } #endif // MULTIPASS_TABLE_FORMATTER diff --git a/include/multipass/cli/yaml_formatter.h b/include/multipass/cli/yaml_formatter.h index 2db8db4f44..9fd1047261 100644 --- a/include/multipass/cli/yaml_formatter.h +++ b/include/multipass/cli/yaml_formatter.h @@ -29,7 +29,7 @@ class YamlFormatter final : public Formatter std::string format(const ListReply& list) const override; std::string format(const NetworksReply& list) const override; std::string format(const FindReply& list) const override; - std::string format(const VersionReply& list, const std::string& multipass_version) const override; + std::string format(const VersionReply& list, const std::string& client_version) const override; }; } #endif // MULTIPASS_YAML_FORMATTER diff --git a/src/client/cli/formatter/csv_formatter.cpp b/src/client/cli/formatter/csv_formatter.cpp index 2e410134e4..b6513c9fb8 100644 --- a/src/client/cli/formatter/csv_formatter.cpp +++ b/src/client/cli/formatter/csv_formatter.cpp @@ -101,14 +101,14 @@ std::string mp::CSVFormatter::format(const FindReply& reply) const return fmt::to_string(buf); } -std::string mp::CSVFormatter::format(const VersionReply& reply, const std::string& multipass_version) const +std::string mp::CSVFormatter::format(const VersionReply& reply, const std::string& client_version) const { fmt::memory_buffer buf; fmt::format_to(buf, "Multipass,Multipassd,Title,Description,URL\n"); - fmt::format_to(buf, "{},{},{},{},{}\n", multipass_version, reply.version(), reply.update_info().title(), + fmt::format_to(buf, "{},{},{},{},{}\n", client_version, reply.version(), reply.update_info().title(), reply.update_info().description(), reply.update_info().url()); return fmt::to_string(buf); -} \ No newline at end of file +} diff --git a/src/client/cli/formatter/json_formatter.cpp b/src/client/cli/formatter/json_formatter.cpp index d54839bca0..67b6c9efc2 100644 --- a/src/client/cli/formatter/json_formatter.cpp +++ b/src/client/cli/formatter/json_formatter.cpp @@ -189,11 +189,11 @@ std::string mp::JsonFormatter::format(const FindReply& reply) const return QString(QJsonDocument(find_json).toJson()).toStdString(); } -std::string mp::JsonFormatter::format(const VersionReply& reply, const std::string& multipass_version) const +std::string mp::JsonFormatter::format(const VersionReply& reply, const std::string& client_version) const { QJsonObject version_json; - version_json.insert("multipass", QString::fromStdString(multipass_version)); + version_json.insert("multipass", QString::fromStdString(client_version)); if (!reply.version().empty()) { diff --git a/src/client/cli/formatter/table_formatter.cpp b/src/client/cli/formatter/table_formatter.cpp index 061ee6da25..2391baab98 100644 --- a/src/client/cli/formatter/table_formatter.cpp +++ b/src/client/cli/formatter/table_formatter.cpp @@ -222,10 +222,10 @@ std::string mp::TableFormatter::format(const FindReply& reply) const return fmt::to_string(buf); } -std::string mp::TableFormatter::format(const VersionReply& reply, const std::string& multipass_version) const +std::string mp::TableFormatter::format(const VersionReply& reply, const std::string& client_version) const { fmt::memory_buffer buf; - fmt::format_to(buf, "{:<16}{}\n", "multipass:", multipass_version); + fmt::format_to(buf, "{:<16}{}\n", "multipass:", client_version); if (!reply.version().empty()) { diff --git a/src/client/cli/formatter/yaml_formatter.cpp b/src/client/cli/formatter/yaml_formatter.cpp index 868a79c19c..cf90485406 100644 --- a/src/client/cli/formatter/yaml_formatter.cpp +++ b/src/client/cli/formatter/yaml_formatter.cpp @@ -181,10 +181,10 @@ std::string mp::YamlFormatter::format(const FindReply& reply) const return mpu::emit_yaml(find); } -std::string mp::YamlFormatter::format(const VersionReply& reply, const std::string& multipass_version) const +std::string mp::YamlFormatter::format(const VersionReply& reply, const std::string& client_version) const { YAML::Node version; - version["multipass"] = multipass_version; + version["multipass"] = client_version; if (!reply.version().empty()) { From 0a2719c5d604cd07193724035427eede9cdb416a Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Wed, 28 Jul 2021 14:08:46 -0400 Subject: [PATCH 43/53] [tests] RPC message memory leak fix and tightening. --- tests/test_cli_client.cpp | 1 + tests/test_output_formatter.cpp | 13 ++++--------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/tests/test_cli_client.cpp b/tests/test_cli_client.cpp index db948c18a0..facc22cca1 100644 --- a/tests/test_cli_client.cpp +++ b/tests/test_cli_client.cpp @@ -1087,6 +1087,7 @@ TEST_F(Client, version_with_option_format_arg) TEST_F(Client, version_with_option_format_invalid_arg) { EXPECT_THAT(send_command({"version", "--format=default"}), Eq(mp::ReturnCode::CommandLineError)); + EXPECT_THAT(send_command({"version", "--format=MumboJumbo"}), Eq(mp::ReturnCode::CommandLineError)); } namespace diff --git a/tests/test_output_formatter.cpp b/tests/test_output_formatter.cpp index f143eef9fb..d22b047325 100644 --- a/tests/test_output_formatter.cpp +++ b/tests/test_output_formatter.cpp @@ -323,15 +323,11 @@ auto construct_version_info_multipassd_update_available() { auto reply = mp::VersionReply(); reply.set_version("Daemon version"); - reply.set_log_line("Some logline goes here"); - mp::UpdateInfo* updateInfo = new mp::UpdateInfo; // Leak? expecting protobuf to deal with memory dealloc. - updateInfo->set_version("update version number"); - updateInfo->set_title("update title information"); - updateInfo->set_description("update description information"); - updateInfo->set_url("http://multipass.web"); - - reply.set_allocated_update_info(updateInfo); + reply.mutable_update_info()->set_version("update version number"); + reply.mutable_update_info()->set_title("update title information"); + reply.mutable_update_info()->set_description("update description information"); + reply.mutable_update_info()->set_url("http://multipass.web"); return reply; } @@ -340,7 +336,6 @@ auto construct_version_info_multipassd_up_to_date() { auto reply = mp::VersionReply(); reply.set_version("Daemon version"); - reply.set_log_line("Some logline goes here"); return reply; } From 4dbf79c70fc4bb12e21b69764fae14cd89cf0385 Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Wed, 28 Jul 2021 14:20:52 -0400 Subject: [PATCH 44/53] [tests] parsing failure for . --- tests/test_cli_client.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/test_cli_client.cpp b/tests/test_cli_client.cpp index facc22cca1..35f7ebb003 100644 --- a/tests/test_cli_client.cpp +++ b/tests/test_cli_client.cpp @@ -1090,6 +1090,11 @@ TEST_F(Client, version_with_option_format_invalid_arg) EXPECT_THAT(send_command({"version", "--format=MumboJumbo"}), Eq(mp::ReturnCode::CommandLineError)); } +TEST_F(Client, version_parse_failure) +{ + EXPECT_THAT(send_command({"version", "MumboJumbo"}), Eq(mp::ReturnCode::CommandLineError)); +} + namespace { grpc::Status aborted_start_status(const std::vector& absent_instances = {}, From b0f76ddf44e433a108a77e4f36128e8f3a9a5e1d Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Thu, 29 Jul 2021 12:45:03 -0400 Subject: [PATCH 45/53] [cli] switched default and legacy output to the
format. Dropped the colon in output. --- src/client/cli/cmd/version.cpp | 29 ++++---------------- src/client/cli/formatter/table_formatter.cpp | 10 +++---- 2 files changed, 10 insertions(+), 29 deletions(-) diff --git a/src/client/cli/cmd/version.cpp b/src/client/cli/cmd/version.cpp index e639302a9d..a48a43047e 100644 --- a/src/client/cli/cmd/version.cpp +++ b/src/client/cli/cmd/version.cpp @@ -33,36 +33,17 @@ mp::ReturnCode cmd::Version::run(mp::ArgParser* parser) return parser->returnCodeFrom(ret); } - bool format_is_set = parser->isSet("format"); - - if (!format_is_set) - { - cout << "multipass " << multipass::version_string << "\n"; - } - - auto on_success = [this, &format_is_set](mp::VersionReply& reply) + auto on_success = [this](mp::VersionReply& reply) { - if (format_is_set) - { - cout << chosen_formatter->format(reply, multipass::version_string); - } - else - { - cout << "multipassd " << reply.version() << "\n"; - if (term->is_live() && update_available(reply.update_info())) - cout << update_notice(reply.update_info()); - } + cout << chosen_formatter->format(reply, multipass::version_string); return ReturnCode::Ok; }; - auto on_failure = [this, &format_is_set](grpc::Status& status) + auto on_failure = [this](grpc::Status& status) { - if (format_is_set) - { - VersionReply reply; - cout << chosen_formatter->format(reply, multipass::version_string); - } + VersionReply reply; + cout << chosen_formatter->format(reply, multipass::version_string); return ReturnCode::Ok; }; diff --git a/src/client/cli/formatter/table_formatter.cpp b/src/client/cli/formatter/table_formatter.cpp index 2391baab98..40d7708cab 100644 --- a/src/client/cli/formatter/table_formatter.cpp +++ b/src/client/cli/formatter/table_formatter.cpp @@ -225,17 +225,17 @@ std::string mp::TableFormatter::format(const FindReply& reply) const std::string mp::TableFormatter::format(const VersionReply& reply, const std::string& client_version) const { fmt::memory_buffer buf; - fmt::format_to(buf, "{:<16}{}\n", "multipass:", client_version); + fmt::format_to(buf, "{:<16}{}\n", "multipass", client_version); if (!reply.version().empty()) { - fmt::format_to(buf, "{:<16}{}\n", "multipassd:", reply.version()); + fmt::format_to(buf, "{:<16}{}\n", "multipassd", reply.version()); if (mp::cmd::update_available(reply.update_info())) { - fmt::format_to(buf, "{:<16}{}\n", "title:", reply.update_info().title()); - fmt::format_to(buf, "{:<16}{}\n", "description:", reply.update_info().description()); - fmt::format_to(buf, "{:<16}{}\n", "url:", reply.update_info().url()); + fmt::format_to(buf, "{:<16}{}\n", "title", reply.update_info().title()); + fmt::format_to(buf, "{:<16}{}\n", "description", reply.update_info().description()); + fmt::format_to(buf, "{:<16}{}\n", "url", reply.update_info().url()); } } return fmt::to_string(buf); From 142e3dc3c2d90d90c71ab37c343a21cf4e300231 Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Thu, 29 Jul 2021 12:45:35 -0400 Subject: [PATCH 46/53] [tests] dropped colon from
format tests. --- tests/test_output_formatter.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/test_output_formatter.cpp b/tests/test_output_formatter.cpp index d22b047325..8cfc206a24 100644 --- a/tests/test_output_formatter.cpp +++ b/tests/test_output_formatter.cpp @@ -1076,17 +1076,17 @@ const auto version_daemon_no_update_reply = construct_version_info_multipassd_up const auto version_daemon_update_reply = construct_version_info_multipassd_update_available(); const std::vector version_formatter_outputs{ - {&table_formatter, &version_client_reply, "multipass: Client version\n", "table_version_client"}, + {&table_formatter, &version_client_reply, "multipass Client version\n", "table_version_client"}, {&table_formatter, &version_daemon_no_update_reply, - "multipass: Client version\n" - "multipassd: Daemon version\n", + "multipass Client version\n" + "multipassd Daemon version\n", "table_version_daemon_no_updates"}, {&table_formatter, &version_daemon_update_reply, - "multipass: Client version\n" - "multipassd: Daemon version\n" - "title: update title information\n" - "description: update description information\n" - "url: http://multipass.web\n", + "multipass Client version\n" + "multipassd Daemon version\n" + "title update title information\n" + "description update description information\n" + "url http://multipass.web\n", "table_version_daemon_updates"}, {&json_formatter, &version_client_reply, "{\n" From 2f5fe9b16613eae7bbebaf367924a20f0226ad83 Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Thu, 29 Jul 2021 13:11:05 -0400 Subject: [PATCH 47/53] [test] test for formatters. --- tests/test_cli_client.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/test_cli_client.cpp b/tests/test_cli_client.cpp index 35f7ebb003..5e4cfe54a6 100644 --- a/tests/test_cli_client.cpp +++ b/tests/test_cli_client.cpp @@ -1095,6 +1095,14 @@ TEST_F(Client, version_parse_failure) EXPECT_THAT(send_command({"version", "MumboJumbo"}), Eq(mp::ReturnCode::CommandLineError)); } +TEST_F(Client, version_info_on_failure) +{ + const grpc::Status notfound{grpc::StatusCode::NOT_FOUND, "msg"}; + + EXPECT_CALL(mock_daemon, version(_, _, _)).WillOnce(Return(notfound)); + EXPECT_THAT(send_command({"version", "--format=yaml"}), Eq(mp::ReturnCode::Ok)); +} + namespace { grpc::Status aborted_start_status(const std::vector& absent_instances = {}, From 21fbf37f0d4ebca452021bcc3361d8066b855e29 Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Thu, 29 Jul 2021 13:31:57 -0400 Subject: [PATCH 48/53] [tests] update to hit parse failure. --- tests/test_cli_client.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_cli_client.cpp b/tests/test_cli_client.cpp index 5e4cfe54a6..ea83638dfc 100644 --- a/tests/test_cli_client.cpp +++ b/tests/test_cli_client.cpp @@ -1092,7 +1092,7 @@ TEST_F(Client, version_with_option_format_invalid_arg) TEST_F(Client, version_parse_failure) { - EXPECT_THAT(send_command({"version", "MumboJumbo"}), Eq(mp::ReturnCode::CommandLineError)); + EXPECT_THAT(send_command({"version", "--format"}), Eq(mp::ReturnCode::CommandLineError)); } TEST_F(Client, version_info_on_failure) From bf6acb2f104a7d636e0cc5c7a5830068b10d9215 Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Fri, 30 Jul 2021 10:45:38 -0400 Subject: [PATCH 49/53] [cli]
formatter updated to include . --- src/client/cli/formatter/table_formatter.cpp | 11 +++++------ tests/test_output_formatter.cpp | 18 ++++++++++-------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/client/cli/formatter/table_formatter.cpp b/src/client/cli/formatter/table_formatter.cpp index 40d7708cab..3a4182e820 100644 --- a/src/client/cli/formatter/table_formatter.cpp +++ b/src/client/cli/formatter/table_formatter.cpp @@ -15,10 +15,11 @@ * */ +#include #include #include -#include +#include "../cmd/common_cli.h" #include namespace mp = multipass; @@ -225,17 +226,15 @@ std::string mp::TableFormatter::format(const FindReply& reply) const std::string mp::TableFormatter::format(const VersionReply& reply, const std::string& client_version) const { fmt::memory_buffer buf; - fmt::format_to(buf, "{:<16}{}\n", "multipass", client_version); + fmt::format_to(buf, "{:<12}{}\n", "multipass", client_version); if (!reply.version().empty()) { - fmt::format_to(buf, "{:<16}{}\n", "multipassd", reply.version()); + fmt::format_to(buf, "{:<12}{}\n", "multipassd", reply.version()); if (mp::cmd::update_available(reply.update_info())) { - fmt::format_to(buf, "{:<16}{}\n", "title", reply.update_info().title()); - fmt::format_to(buf, "{:<16}{}\n", "description", reply.update_info().description()); - fmt::format_to(buf, "{:<16}{}\n", "url", reply.update_info().url()); + fmt::format_to(buf, "{}", mp::cmd::update_notice(reply.update_info())); } } return fmt::to_string(buf); diff --git a/tests/test_output_formatter.cpp b/tests/test_output_formatter.cpp index 8cfc206a24..cb416f649d 100644 --- a/tests/test_output_formatter.cpp +++ b/tests/test_output_formatter.cpp @@ -1076,17 +1076,19 @@ const auto version_daemon_no_update_reply = construct_version_info_multipassd_up const auto version_daemon_update_reply = construct_version_info_multipassd_update_available(); const std::vector version_formatter_outputs{ - {&table_formatter, &version_client_reply, "multipass Client version\n", "table_version_client"}, + {&table_formatter, &version_client_reply, "multipass Client version\n", "table_version_client"}, {&table_formatter, &version_daemon_no_update_reply, - "multipass Client version\n" - "multipassd Daemon version\n", + "multipass Client version\n" + "multipassd Daemon version\n", "table_version_daemon_no_updates"}, {&table_formatter, &version_daemon_update_reply, - "multipass Client version\n" - "multipassd Daemon version\n" - "title update title information\n" - "description update description information\n" - "url http://multipass.web\n", + "multipass Client version\n" + "multipassd Daemon version\n" + "\n##################################################\n" + "update title information\n" + "update description information\n" + "\nGo here for more information: http://multipass.web\n" + "##################################################\n", "table_version_daemon_updates"}, {&json_formatter, &version_client_reply, "{\n" From 3de357286f2f815e66a8f33cd8ae077bc0545c4c Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Fri, 30 Jul 2021 10:48:45 -0400 Subject: [PATCH 50/53] [cli] bringing "self" headers to top. --- src/client/cli/formatter/json_formatter.cpp | 2 +- src/client/cli/formatter/yaml_formatter.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client/cli/formatter/json_formatter.cpp b/src/client/cli/formatter/json_formatter.cpp index 67b6c9efc2..4acfd83d25 100644 --- a/src/client/cli/formatter/json_formatter.cpp +++ b/src/client/cli/formatter/json_formatter.cpp @@ -15,9 +15,9 @@ * */ +#include #include #include -#include #include #include diff --git a/src/client/cli/formatter/yaml_formatter.cpp b/src/client/cli/formatter/yaml_formatter.cpp index cf90485406..da4d6dabf2 100644 --- a/src/client/cli/formatter/yaml_formatter.cpp +++ b/src/client/cli/formatter/yaml_formatter.cpp @@ -15,9 +15,9 @@ * */ +#include #include #include -#include #include #include From bd06641b303275a4dbec96a12419ad763e389c37 Mon Sep 17 00:00:00 2001 From: Saad Ur Rahman Date: Fri, 30 Jul 2021 16:46:26 -0400 Subject: [PATCH 51/53] [cli] headers cleaned up and clang-formatted. --- src/client/cli/formatter/json_formatter.cpp | 2 +- src/client/cli/formatter/table_formatter.cpp | 3 +-- src/client/cli/formatter/yaml_formatter.cpp | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/client/cli/formatter/json_formatter.cpp b/src/client/cli/formatter/json_formatter.cpp index 4acfd83d25..67b6c9efc2 100644 --- a/src/client/cli/formatter/json_formatter.cpp +++ b/src/client/cli/formatter/json_formatter.cpp @@ -15,9 +15,9 @@ * */ -#include #include #include +#include #include #include diff --git a/src/client/cli/formatter/table_formatter.cpp b/src/client/cli/formatter/table_formatter.cpp index 3a4182e820..452caafbe2 100644 --- a/src/client/cli/formatter/table_formatter.cpp +++ b/src/client/cli/formatter/table_formatter.cpp @@ -15,9 +15,8 @@ * */ -#include -#include #include +#include #include "../cmd/common_cli.h" #include diff --git a/src/client/cli/formatter/yaml_formatter.cpp b/src/client/cli/formatter/yaml_formatter.cpp index da4d6dabf2..cf90485406 100644 --- a/src/client/cli/formatter/yaml_formatter.cpp +++ b/src/client/cli/formatter/yaml_formatter.cpp @@ -15,9 +15,9 @@ * */ -#include #include #include +#include #include #include From 66e59692ef8e7e41530ef962f6a7afd447f814aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sawicz?= Date: Sat, 31 Jul 2021 11:38:39 +0200 Subject: [PATCH 52/53] [cli] move update helpers to client_common Also undo include reordering --- include/multipass/cli/client_common.h | 3 ++- src/client/cli/cmd/common_cli.cpp | 26 -------------------- src/client/cli/cmd/common_cli.h | 4 --- src/client/cli/formatter/CMakeLists.txt | 3 ++- src/client/cli/formatter/json_formatter.cpp | 3 ++- src/client/cli/formatter/table_formatter.cpp | 5 ++-- src/client/cli/formatter/yaml_formatter.cpp | 2 +- src/client/common/client_common.cpp | 26 +++++++++++++++++++- 8 files changed, 35 insertions(+), 37 deletions(-) diff --git a/include/multipass/cli/client_common.h b/include/multipass/cli/client_common.h index c36b18293f..b616a7a3f3 100644 --- a/include/multipass/cli/client_common.h +++ b/include/multipass/cli/client_common.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2020 Canonical, Ltd. + * Copyright (C) 2019-2021 Canonical, Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -42,6 +42,7 @@ multipass::ReturnCode standard_failure_handler_for(const std::string& command, s const grpc::Status& status, const std::string& error_details = std::string()); bool update_available(const UpdateInfo& update_info); +std::string update_notice(const multipass::UpdateInfo& update_info); } namespace client diff --git a/src/client/cli/cmd/common_cli.cpp b/src/client/cli/cmd/common_cli.cpp index 40488a9a8f..be89abf36b 100644 --- a/src/client/cli/cmd/common_cli.cpp +++ b/src/client/cli/cmd/common_cli.cpp @@ -36,26 +36,6 @@ namespace mp = multipass; namespace cmd = multipass::cmd; -namespace -{ -std::string message_box(const std::string& message) -{ - std::string::size_type divider_length = 50; - { - std::istringstream m(message); - std::string s; - while (getline(m, s, '\n')) - { - divider_length = std::max(divider_length, s.length()); - } - } - - const auto divider = std::string(divider_length, '#'); - - return '\n' + divider + '\n' + message + '\n' + divider + '\n'; -} -} // namespace - mp::ParseCode cmd::check_for_name_and_all_option_conflict(const mp::ArgParser* parser, std::ostream& cerr, bool allow_empty) { @@ -125,12 +105,6 @@ std::string cmd::instance_action_message_for(const mp::InstanceNames& instance_n return message; } -std::string cmd::update_notice(const mp::UpdateInfo& update_info) -{ - return ::message_box(fmt::format("{}\n{}\n\nGo here for more information: {}", update_info.title(), - update_info.description(), update_info.url())); -} - mp::ReturnCode cmd::run_cmd(const QStringList& args, const mp::ArgParser* parser, std::ostream& cout, std::ostream& cerr) { diff --git a/src/client/cli/cmd/common_cli.h b/src/client/cli/cmd/common_cli.h index 8352462603..c18e50cf69 100644 --- a/src/client/cli/cmd/common_cli.h +++ b/src/client/cli/cmd/common_cli.h @@ -50,10 +50,6 @@ ReturnCode run_cmd_and_retry(const QStringList& args, const ArgParser* parser, s ReturnCode return_code_from(const SettingsException& e); QString describe_settings_keys(); -// helpers for update handling -bool update_available(const multipass::UpdateInfo& update_info); -std::string update_notice(const multipass::UpdateInfo& update_info); - // parser helpers void add_timeout(multipass::ArgParser*); int parse_timeout(const multipass::ArgParser* parser); diff --git a/src/client/cli/formatter/CMakeLists.txt b/src/client/cli/formatter/CMakeLists.txt index 29e3ec64e5..8c4fa30363 100644 --- a/src/client/cli/formatter/CMakeLists.txt +++ b/src/client/cli/formatter/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright © 2018-2020 Canonical Ltd. +# Copyright © 2018-2021 Canonical Ltd. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License version 3 as @@ -20,6 +20,7 @@ add_library(formatter STATIC yaml_formatter.cpp) target_link_libraries(formatter + client_common fmt rpc yaml diff --git a/src/client/cli/formatter/json_formatter.cpp b/src/client/cli/formatter/json_formatter.cpp index 67b6c9efc2..25f5a4804e 100644 --- a/src/client/cli/formatter/json_formatter.cpp +++ b/src/client/cli/formatter/json_formatter.cpp @@ -15,9 +15,10 @@ * */ +#include + #include #include -#include #include #include diff --git a/src/client/cli/formatter/table_formatter.cpp b/src/client/cli/formatter/table_formatter.cpp index 452caafbe2..65c814db32 100644 --- a/src/client/cli/formatter/table_formatter.cpp +++ b/src/client/cli/formatter/table_formatter.cpp @@ -15,10 +15,11 @@ * */ -#include #include -#include "../cmd/common_cli.h" +#include +#include + #include namespace mp = multipass; diff --git a/src/client/cli/formatter/yaml_formatter.cpp b/src/client/cli/formatter/yaml_formatter.cpp index cf90485406..438db930ca 100644 --- a/src/client/cli/formatter/yaml_formatter.cpp +++ b/src/client/cli/formatter/yaml_formatter.cpp @@ -14,10 +14,10 @@ * along with this program. If not, see . * */ +#include #include #include -#include #include #include diff --git a/src/client/common/client_common.cpp b/src/client/common/client_common.cpp index 01c90b1671..94accc09bc 100644 --- a/src/client/common/client_common.cpp +++ b/src/client/common/client_common.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2020 Canonical, Ltd. + * Copyright (C) 2019-2021 Canonical, Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -34,6 +34,24 @@ mp::ReturnCode return_code_for(const grpc::StatusCode& code) { return code == grpc::StatusCode::UNAVAILABLE ? mp::ReturnCode::DaemonFail : mp::ReturnCode::CommandFail; } + +std::string message_box(const std::string& message) +{ + std::string::size_type divider_length = 50; + { + std::istringstream m(message); + std::string s; + while (getline(m, s, '\n')) + { + divider_length = std::max(divider_length, s.length()); + } + } + + const auto divider = std::string(divider_length, '#'); + + return '\n' + divider + '\n' + message + '\n' + divider + '\n'; +} + } // namespace mp::ReturnCode mp::cmd::standard_failure_handler_for(const std::string& command, std::ostream& cerr, @@ -52,6 +70,12 @@ bool mp::cmd::update_available(const mp::UpdateInfo& update_info) return update_info.version() != ""; } +std::string mp::cmd::update_notice(const mp::UpdateInfo& update_info) +{ + return ::message_box(fmt::format("{}\n{}\n\nGo here for more information: {}", update_info.title(), + update_info.description(), update_info.url())); +} + std::shared_ptr mp::client::make_channel(const std::string& server_address, mp::RpcConnectionType conn_type, mp::CertProvider& cert_provider) From 28f79fcc8939fd7781b553327bfb8911c37c0bec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sawicz?= Date: Mon, 2 Aug 2021 13:41:03 +0200 Subject: [PATCH 53/53] [yaml] add removed newline --- src/client/cli/formatter/yaml_formatter.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/client/cli/formatter/yaml_formatter.cpp b/src/client/cli/formatter/yaml_formatter.cpp index 438db930ca..d9f615c73d 100644 --- a/src/client/cli/formatter/yaml_formatter.cpp +++ b/src/client/cli/formatter/yaml_formatter.cpp @@ -14,6 +14,7 @@ * along with this program. If not, see . * */ + #include #include