Skip to content

Commit

Permalink
[format] Adapt to latest clang-format config
Browse files Browse the repository at this point in the history
  • Loading branch information
ricab committed Oct 16, 2023
1 parent 25869b8 commit e79e102
Show file tree
Hide file tree
Showing 63 changed files with 1,281 additions and 499 deletions.
19 changes: 10 additions & 9 deletions include/multipass/cli/format_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,16 @@ void filter_aliases(google::protobuf::RepeatedPtrField<multipass::FindReply_Alia

// Computes the column width needed to display all the elements of a range [begin, end). get_width is a function
// which takes as input the element in the range and returns its width in columns.
static constexpr auto column_width = [](const auto begin, const auto end, const auto get_width, int header_width,
int minimum_width = 0) {
if (0 == std::distance(begin, end))
return std::max({header_width + col_buffer, minimum_width});

auto max_width =
std::max_element(begin, end, [&get_width](auto& lhs, auto& rhs) { return get_width(lhs) < get_width(rhs); });
return std::max({get_width(*max_width) + col_buffer, header_width + col_buffer, minimum_width});
};
static constexpr auto column_width =
[](const auto begin, const auto end, const auto get_width, int header_width, int minimum_width = 0) {
if (0 == std::distance(begin, end))
return std::max({header_width + col_buffer, minimum_width});

auto max_width = std::max_element(begin, end, [&get_width](auto& lhs, auto& rhs) {
return get_width(lhs) < get_width(rhs);
});
return std::max({get_width(*max_width) + col_buffer, header_width + col_buffer, minimum_width});
};
} // namespace format
} // namespace multipass

Expand Down
3 changes: 2 additions & 1 deletion include/multipass/file_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ class FileOps : public Singleton<FileOps>
// QDir operations
virtual bool exists(const QDir& dir) const;
virtual bool isReadable(const QDir& dir) const;
virtual QFileInfoList entryInfoList(const QDir& dir, const QStringList& nameFilters,
virtual QFileInfoList entryInfoList(const QDir& dir,
const QStringList& nameFilters,
QDir::Filters filters = QDir::NoFilter,
QDir::SortFlags sort = QDir::NoSort) const;
virtual bool mkpath(const QDir& dir, const QString& dirName) const;
Expand Down
4 changes: 3 additions & 1 deletion include/multipass/mount_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ class MountHandler : private DisabledCopyMove

protected:
MountHandler() = default;
MountHandler(VirtualMachine* vm, const SSHKeyProvider* ssh_key_provider, VMMount mount_spec,
MountHandler(VirtualMachine* vm,
const SSHKeyProvider* ssh_key_provider,
VMMount mount_spec,
const std::string& target)
: vm{vm}, ssh_key_provider{ssh_key_provider}, mount_spec{std::move(mount_spec)}, target{target}, active{false}
{
Expand Down
4 changes: 3 additions & 1 deletion include/multipass/sshfs_mount/sshfs_mount_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ namespace multipass
class SSHFSMountHandler : public MountHandler
{
public:
SSHFSMountHandler(VirtualMachine* vm, const SSHKeyProvider* ssh_key_provider, const std::string& target,
SSHFSMountHandler(VirtualMachine* vm,
const SSHKeyProvider* ssh_key_provider,
const std::string& target,
VMMount mount_spec);
~SSHFSMountHandler() override;

Expand Down
3 changes: 2 additions & 1 deletion include/multipass/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ class Utils : public Singleton<Utils>
// virtual machine helpers
virtual void wait_for_cloud_init(VirtualMachine* virtual_machine, std::chrono::milliseconds timeout,
const SSHKeyProvider& key_provider) const;
virtual Path derive_instances_dir(const Path& data_dir, const Path& backend_directory_name,
virtual Path derive_instances_dir(const Path& data_dir,
const Path& backend_directory_name,
const Path& instances_subdir) const;

// system info helpers
Expand Down
3 changes: 2 additions & 1 deletion include/multipass/virtual_machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ class VirtualMachine : private DisabledCopyMove
virtual int get_num_snapshots() const noexcept = 0;
virtual std::shared_ptr<const Snapshot> get_snapshot(const std::string& name) const = 0;
virtual std::shared_ptr<Snapshot> get_snapshot(const std::string& name) = 0;
virtual std::shared_ptr<const Snapshot> take_snapshot(const VMSpecs& specs, const std::string& name,
virtual std::shared_ptr<const Snapshot> take_snapshot(const VMSpecs& specs,
const std::string& name,
const std::string& comment) = 0;
virtual void delete_snapshot(const std::string& name) = 0;
virtual void restore_snapshot(const std::string& name, VMSpecs& specs) = 0;
Expand Down
10 changes: 7 additions & 3 deletions include/multipass/vm_image_vault.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,13 @@ class VMImageVault : private DisabledCopyMove
using PrepareAction = std::function<VMImage(const VMImage&)>;

virtual ~VMImageVault() = default;
virtual VMImage fetch_image(const FetchType& fetch_type, const Query& query, const PrepareAction& prepare,
const ProgressMonitor& monitor, const bool unlock,
const std::optional<std::string>& checksum, const Path& save_dir) = 0;
virtual VMImage fetch_image(const FetchType& fetch_type,
const Query& query,
const PrepareAction& prepare,
const ProgressMonitor& monitor,
const bool unlock,
const std::optional<std::string>& checksum,
const Path& save_dir) = 0;
virtual void remove(const std::string& name) = 0;
virtual bool has_record_for(const std::string& name) = 0;
virtual void prune_expired_images() = 0;
Expand Down
11 changes: 8 additions & 3 deletions src/client/cli/cmd/delete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ QString cmd::Delete::description() const

mp::ParseCode cmd::Delete::parse_args(mp::ArgParser* parser)
{
parser->addPositionalArgument("name", "Names of instances and snapshots to delete",
parser->addPositionalArgument("name",
"Names of instances and snapshots to delete",
"<instance>[.snapshot] [<instance>[.snapshot] ...]");

QCommandLineOption all_option(all_option_name, "Delete all instances and snapshots");
Expand Down Expand Up @@ -140,15 +141,19 @@ mp::ParseCode cmd::Delete::parse_instances_snapshots(mp::ArgParser* parser)
return enforce_purged_snapshots(instances, snapshots, instance_found, snapshot_found);
}

mp::ParseCode cmd::Delete::enforce_purged_snapshots(std::string& instances, std::string& snapshots, bool instance_found,
mp::ParseCode cmd::Delete::enforce_purged_snapshots(std::string& instances,
std::string& snapshots,
bool instance_found,
bool snapshot_found)
{
if (snapshot_found && !request.purge())
{
if (instance_found)
cerr << fmt::format("{}:\n\n\tmultipass delete --purge {}\n\nYou can use a separate command to delete "

Check warning on line 152 in src/client/cli/cmd/delete.cpp

View check run for this annotation

Codecov / codecov/patch

src/client/cli/cmd/delete.cpp#L151-L152

Added lines #L151 - L152 were not covered by tests
"instances without purging them:\n\n\tmultipass delete {}\n",
no_purge_base_error_msg, snapshots, instances);
no_purge_base_error_msg,
snapshots,
instances);

Check warning on line 156 in src/client/cli/cmd/delete.cpp

View check run for this annotation

Codecov / codecov/patch

src/client/cli/cmd/delete.cpp#L156

Added line #L156 was not covered by tests
else
cerr << fmt::format("{}.\n", no_purge_base_error_msg);

Check warning on line 158 in src/client/cli/cmd/delete.cpp

View check run for this annotation

Codecov / codecov/patch

src/client/cli/cmd/delete.cpp#L158

Added line #L158 was not covered by tests

Expand Down
4 changes: 3 additions & 1 deletion src/client/cli/cmd/delete.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ class Delete final : public Command

ParseCode parse_args(ArgParser* parser);
ParseCode parse_instances_snapshots(ArgParser* parser);
ParseCode enforce_purged_snapshots(std::string& instances, std::string& snapshots, bool instance_found,
ParseCode enforce_purged_snapshots(std::string& instances,
std::string& snapshots,
bool instance_found,
bool snapshot_found);
};
} // namespace cmd
Expand Down
6 changes: 4 additions & 2 deletions src/client/cli/cmd/info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ QString cmd::Info::description() const

mp::ParseCode cmd::Info::parse_args(mp::ArgParser* parser)
{
parser->addPositionalArgument("instance", "Names of instances or snapshots to display information about",
parser->addPositionalArgument("instance",
"Names of instances or snapshots to display information about",
"<instance>[.snapshot] [<instance>[.snapshot] ...]");

QCommandLineOption all_option(all_option_name, "Display info for all instances");
Expand All @@ -69,7 +70,8 @@ mp::ParseCode cmd::Info::parse_args(mp::ArgParser* parser)
QCommandLineOption formatOption(
format_option_name,
"Output info in the requested format.\nValid formats are: table (default), json, csv and yaml",
format_option_name, "table");
format_option_name,
"table");

parser->addOptions({all_option, noRuntimeInfoOption, formatOption});

Expand Down
5 changes: 4 additions & 1 deletion src/client/cli/cmd/remote_settings_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ class RemoteSet : public RemoteSettingsCmd
mp::AnimatedSpinner spinner{cout};

[[maybe_unused]] auto ret =
dispatch(&RpcMethod::set, set_request, on_success<mp::SetReply>, on_failure,
dispatch(&RpcMethod::set,
set_request,
on_success<mp::SetReply>,
on_failure,
mp::make_reply_spinner_callback<mp::SetRequest, mp::SetReply>(spinner, cerr));
assert(ret == mp::ReturnCode::Ok && "should have thrown otherwise");
}
Expand Down
10 changes: 7 additions & 3 deletions src/client/cli/cmd/snapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ mp::ReturnCode cmd::Snapshot::run(mp::ArgParser* parser)
};

spinner.start("Taking snapshot ");
return dispatch(&RpcMethod::snapshot, request, on_success, on_failure,
return dispatch(&RpcMethod::snapshot,

Check warning on line 48 in src/client/cli/cmd/snapshot.cpp

View check run for this annotation

Codecov / codecov/patch

src/client/cli/cmd/snapshot.cpp#L48

Added line #L48 was not covered by tests
request,
on_success,
on_failure,
make_logging_spinner_callback<SnapshotRequest, SnapshotReply>(spinner, cerr));
}

Expand All @@ -72,8 +75,9 @@ mp::ParseCode cmd::Snapshot::parse_args(mp::ArgParser* parser)
"names (see `help launch`). Default: \"snapshotN\", where N is one plus the "
"number of snapshots that were ever taken for <instance>.",
"name");
QCommandLineOption comment_opt{
{"comment", "c", "m"}, "An optional free comment to associate with the snapshot.", "comment"};
QCommandLineOption comment_opt{{"comment", "c", "m"},
"An optional free comment to associate with the snapshot.",
"comment"};
parser->addOptions({name_opt, comment_opt});

if (auto status = parser->commandParse(this); status != ParseCode::Ok)
Expand Down
46 changes: 34 additions & 12 deletions src/client/cli/formatter/csv_formatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,22 @@ std::string generate_snapshot_details(const mp::InfoReply reply)
{
const auto& fundamentals = info.snapshot_info().fundamentals();

fmt::format_to(std::back_inserter(buf), "{},{},{},{},{},", fundamentals.snapshot_name(), info.name(),
info.cpu_count(), info.disk_total(), info.memory_total());
fmt::format_to(std::back_inserter(buf),
"{},{},{},{},{},",
fundamentals.snapshot_name(),
info.name(),
info.cpu_count(),
info.disk_total(),
info.memory_total());

fmt::format_to(std::back_inserter(buf), format_mounts(info.mount_info()));

fmt::format_to(std::back_inserter(buf), ",{},{},{},\"{}\"\n",
fmt::format_to(std::back_inserter(buf),
",{},{},{},\"{}\"\n",
google::protobuf::util::TimeUtil::ToString(fundamentals.creation_timestamp()),
fundamentals.parent(), fmt::join(info.snapshot_info().children(), ";"), fundamentals.comment());
fundamentals.parent(),
fmt::join(info.snapshot_info().children(), ";"),
fundamentals.comment());
}

return fmt::to_string(buf);
Expand All @@ -101,18 +109,28 @@ std::string generate_instance_details(const mp::InfoReply reply)
"outputting instance and snapshot details together is not supported in csv format");
const auto& instance_details = info.instance_info();

fmt::format_to(std::back_inserter(buf), "{},{},{},{},{},{},{},{},{},{},{},{},", info.name(),
fmt::format_to(std::back_inserter(buf),
"{},{},{},{},{},{},{},{},{},{},{},{},",
info.name(),
mp::format::status_string_for(info.instance_status()),
instance_details.ipv4_size() ? instance_details.ipv4(0) : "",
instance_details.ipv6_size() ? instance_details.ipv6(0) : "", instance_details.current_release(),
instance_details.id(), instance_details.image_release(), instance_details.load(),
instance_details.disk_usage(), info.disk_total(), instance_details.memory_usage(),
instance_details.ipv6_size() ? instance_details.ipv6(0) : "",
instance_details.current_release(),
instance_details.id(),
instance_details.image_release(),
instance_details.load(),
instance_details.disk_usage(),
info.disk_total(),
instance_details.memory_usage(),
info.memory_total());

fmt::format_to(std::back_inserter(buf), format_mounts(info.mount_info()));

fmt::format_to(std::back_inserter(buf), ",{},{},{}\n", fmt::join(instance_details.ipv4(), ";"),
info.cpu_count(), instance_details.num_snapshots());
fmt::format_to(std::back_inserter(buf),
",{},{},{}\n",
fmt::join(instance_details.ipv4(), ";"),
info.cpu_count(),
instance_details.num_snapshots());
}

return fmt::to_string(buf);
Expand Down Expand Up @@ -146,8 +164,12 @@ std::string generate_snapshots_list(const mp::SnapshotsList& snapshot_list)
for (const auto& item : mp::format::sorted(snapshot_list.snapshots()))
{
const auto& snapshot = item.fundamentals();
fmt::format_to(std::back_inserter(buf), "{},{},{},\"{}\"\n", item.name(), snapshot.snapshot_name(),
snapshot.parent(), snapshot.comment());
fmt::format_to(std::back_inserter(buf),
"{},{},{},\"{}\"\n",
item.name(),
snapshot.snapshot_name(),
snapshot.parent(),
snapshot.comment());
}

return fmt::to_string(buf);
Expand Down
5 changes: 3 additions & 2 deletions src/client/cli/formatter/json_formatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ QJsonObject generate_snapshot_details(const mp::DetailedInfoItem& item)
}
snapshot_info.insert("mounts", mounts);

snapshot_info.insert("created", QString::fromStdString(
google::protobuf::util::TimeUtil::ToString(fundamentals.creation_timestamp())));
snapshot_info.insert(
"created",
QString::fromStdString(google::protobuf::util::TimeUtil::ToString(fundamentals.creation_timestamp())));
snapshot_info.insert("parent", QString::fromStdString(fundamentals.parent()));

QJsonArray children;
Expand Down
Loading

0 comments on commit e79e102

Please sign in to comment.