Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/client/cli/formatter/csv_formatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ void format_images(Dest&& dest,
auto image_id = mp::format::image_string_for(image.remote_name(), aliases[0]);

fmt::format_to(dest,
"{},{},{},{},{},{},{}\n",
"{},{},{},{},{},{},{},{}\n",
image_id,
image.remote_name(),
fmt::join(aliases.cbegin() + 1, aliases.cend(), ";"),
image.os(),
image.release(),
image.version(),
image.image_hash(),
type);
}
}
Expand Down Expand Up @@ -220,7 +221,7 @@ std::string mp::CSVFormatter::format(const FindReply& reply) const
{
fmt::memory_buffer buf;

fmt::format_to(std::back_inserter(buf), "Image,Remote,Aliases,OS,Release,Version,Type\n");
fmt::format_to(std::back_inserter(buf), "Image,Remote,Aliases,OS,Release,Version,Hash,Type\n");
format_images(std::back_inserter(buf), reply.images_info(), "Cloud Image");

return fmt::to_string(buf);
Expand Down
1 change: 1 addition & 0 deletions src/client/cli/formatter/json_formatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ QJsonObject format_images(

image_obj.insert("aliases", aliases_arr);
image_obj.insert("remote", QString::fromStdString(image.remote_name()));
image_obj.insert("image_hash", QString::fromStdString(image.image_hash()));

images_obj.insert(
QString::fromStdString(mp::format::image_string_for(image.remote_name(), aliases[0])),
Expand Down
14 changes: 12 additions & 2 deletions src/client/cli/formatter/table_formatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ template <typename Dest>
void format_images(Dest&& dest,
const google::protobuf::RepeatedPtrField<mp::FindReply_ImageInfo>& images_info)
{
fmt::format_to(dest, "{:<28}{:<18}{:<17}{:<}\n", "Image", "Aliases", "Version", "Description");
fmt::format_to(dest,
"{:<28}{:<18}{:<17}{:<15}{:<}\n",
"Image",
"Aliases",
"Version",
"Hash",
"Description");

auto sorted_images = images_info;
std::sort(sorted_images.begin(),
Expand All @@ -56,12 +62,16 @@ void format_images(Dest&& dest,
auto aliases = image.aliases();
mp::format::filter_aliases(aliases);

auto hash = image.image_hash();
auto short_hash = hash.size() > 12 ? hash.substr(0, 12) : hash;

fmt::format_to(
dest,
"{:<28}{:<18}{:<17}{:<}\n",
"{:<28}{:<18}{:<17}{:<15}{:<}\n",
mp::format::image_string_for(image.remote_name(), aliases[0]),
fmt::format("{}", fmt::join(aliases.cbegin() + 1, aliases.cend(), ",")),
image.version(),
short_hash,
fmt::format("{}{}", image.os().empty() ? "" : image.os() + " ", image.release()));
}
fmt::format_to(dest, "\n");
Expand Down
1 change: 1 addition & 0 deletions src/client/cli/formatter/yaml_formatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ std::map<std::string, YAML::Node> format_images(const ImageInfo& images_info)
image_node["release"] = image.release();
image_node["version"] = image.version();
image_node["remote"] = image.remote_name();
image_node["image_hash"] = image.image_hash();

images_node[mp::format::image_string_for(image.remote_name(), aliases[0])] = image_node;
}
Expand Down
1 change: 1 addition & 0 deletions src/daemon/daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,7 @@ void add_aliases(google::protobuf::RepeatedPtrField<mp::FindReply_ImageInfo>* co
entry->set_version(info.version.toStdString());
entry->set_codename(info.release_codename.toStdString());
entry->set_remote_name(remote_name);
entry->set_image_hash(info.id.toStdString());
}
}

Expand Down
1 change: 1 addition & 0 deletions src/rpc/multipass.proto
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ message FindReply {
repeated string aliases = 4;
string codename = 5;
string remote_name = 6;
string image_hash = 7;
}
repeated ImageInfo images_info = 1;
string log_line = 2;
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_data/formatters/csv/empty_find_reply.csv
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Image,Remote,Aliases,OS,Release,Version,Type
Image,Remote,Aliases,OS,Release,Version,Hash,Type
8 changes: 4 additions & 4 deletions tests/unit/test_data/formatters/csv/find_multiple_reply.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Image,Remote,Aliases,OS,Release,Version,Type
19.04,release,disco,Ubuntu,19.04,20190516,Cloud Image
18.04,release,bionic;lts,Ubuntu,18.04 LTS,20180421,Cloud Image
daily:19.10,daily,eoan;devel,Ubuntu,19.10,20190516,Cloud Image
Image,Remote,Aliases,OS,Release,Version,Hash,Type
19.04,release,disco,Ubuntu,19.04,20190516,,Cloud Image
18.04,release,bionic;lts,Ubuntu,18.04 LTS,20180421,,Cloud Image
daily:19.10,daily,eoan;devel,Ubuntu,19.10,20190516,,Cloud Image
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Image,Remote,Aliases,OS,Release,Version,Type
core:core18,core,,Ubuntu,Core 18,20190520,Cloud Image
snapcraft:core18,snapcraft,,,Snapcraft builder for core18,20190520,Cloud Image
Image,Remote,Aliases,OS,Release,Version,Hash,Type
core:core18,core,,Ubuntu,Core 18,20190520,,Cloud Image
snapcraft:core18,snapcraft,,,Snapcraft builder for core18,20190520,,Cloud Image
4 changes: 2 additions & 2 deletions tests/unit/test_data/formatters/csv/find_one_reply.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Image,Remote,Aliases,OS,Release,Version,Type
ubuntu,,,Ubuntu,18.04 LTS,20190516,Cloud Image
Image,Remote,Aliases,OS,Release,Version,Hash,Type
ubuntu,,,Ubuntu,18.04 LTS,20190516,,Cloud Image
3 changes: 3 additions & 0 deletions tests/unit/test_data/formatters/json/find_multiple_reply.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"bionic",
"lts"
],
"image_hash": "",
"os": "Ubuntu",
"release": "18.04 LTS",
"remote": "release",
Expand All @@ -16,6 +17,7 @@
"aliases": [
"disco"
],
"image_hash": "",
"os": "Ubuntu",
"release": "19.04",
"remote": "release",
Expand All @@ -26,6 +28,7 @@
"eoan",
"devel"
],
"image_hash": "",
"os": "Ubuntu",
"release": "19.10",
"remote": "daily",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"core:core18": {
"aliases": [
],
"image_hash": "",
"os": "Ubuntu",
"release": "Core 18",
"remote": "core",
Expand All @@ -13,6 +14,7 @@
"snapcraft:core18": {
"aliases": [
],
"image_hash": "",
"os": "",
"release": "Snapcraft builder for core18",
"remote": "snapcraft",
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_data/formatters/json/find_one_reply.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"ubuntu": {
"aliases": [
],
"image_hash": "",
"os": "Ubuntu",
"release": "18.04 LTS",
"remote": "",
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/test_data/formatters/table/find_multiple_reply.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Image Aliases Version Description
18.04 bionic,lts 20180421 Ubuntu 18.04 LTS
19.04 disco 20190516 Ubuntu 19.04
daily:19.10 eoan,devel 20190516 Ubuntu 19.10
Image Aliases Version Hash Description
18.04 bionic,lts 20180421 Ubuntu 18.04 LTS
19.04 disco 20190516 Ubuntu 19.04
daily:19.10 eoan,devel 20190516 Ubuntu 19.10

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Image Aliases Version Description
snapcraft:core18 20190520 Snapcraft builder for core18
core:core18 20190520 Ubuntu Core 18
Image Aliases Version Hash Description
snapcraft:core18 20190520 Snapcraft builder for core18
core:core18 20190520 Ubuntu Core 18

4 changes: 2 additions & 2 deletions tests/unit/test_data/formatters/table/find_one_reply.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Image Aliases Version Description
ubuntu 20190516 Ubuntu 18.04 LTS
Image Aliases Version Hash Description
ubuntu 20190516 Ubuntu 18.04 LTS

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Image Aliases Version Description
snapcraft:core18 20190520 Snapcraft builder for core18
Image Aliases Version Hash Description
snapcraft:core18 20190520 Snapcraft builder for core18

3 changes: 3 additions & 0 deletions tests/unit/test_data/formatters/yaml/find_multiple_reply.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ images:
release: 18.04 LTS
version: 20180421
remote: release
image_hash: ""
19.04:
aliases:
- disco
os: Ubuntu
release: 19.04
version: 20190516
remote: release
image_hash: ""
"daily:19.10":
aliases:
- eoan
Expand All @@ -24,3 +26,4 @@ images:
release: 19.10
version: 20190516
remote: daily
image_hash: ""
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ images:
release: Core 18
version: 20190520
remote: core
image_hash: ""
"snapcraft:core18":
aliases:
[]
os: ""
release: Snapcraft builder for core18
version: 20190520
remote: snapcraft
image_hash: ""
1 change: 1 addition & 0 deletions tests/unit/test_data/formatters/yaml/find_one_reply.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ images:
release: 18.04 LTS
version: 20190516
remote: ""
image_hash: ""