Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cli] rename copy-files to transfer (Fixes #748) #778

Merged
merged 3 commits into from
May 10, 2019
Merged
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
6 changes: 3 additions & 3 deletions completions/bash/multipass
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright © 2017-2018 Canonical Ltd.
# Copyright © 2017-2019 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
Expand Down Expand Up @@ -46,7 +46,7 @@ _multipass_complete()
prev="${COMP_WORDS[COMP_CWORD-1]}"
cmd="${COMP_WORDS[1]}"
prev_opts=false
multipass_cmds="copy-files delete exec find help info launch list mount purge \
multipass_cmds="transfer delete exec find help info launch list mount purge \
recover shell start stop suspend restart umount version"

opts="--help --verbose"
Expand Down Expand Up @@ -125,7 +125,7 @@ _multipass_complete()
_multipass_instances
fi
;;
"copy-files")
"transfer"|"copy-files")
_multipass_instances "RUNNING"

COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
Expand Down
4 changes: 2 additions & 2 deletions include/multipass/cli/client_platform.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018 Canonical, Ltd.
* Copyright (C) 2018-2019 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
Expand Down Expand Up @@ -29,7 +29,7 @@ namespace cli
{
namespace platform
{
void parse_copy_files_entry(const QString& entry, QString& path, QString& instance_name);
void parse_transfer_entry(const QString& entry, QString& path, QString& instance_name);
int getuid();
int getgid();
}
Expand Down
6 changes: 3 additions & 3 deletions src/client/client.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017-2018 Canonical, Ltd.
* Copyright (C) 2017-2019 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
Expand All @@ -17,7 +17,6 @@
*
*/
#include "client.h"
#include "cmd/copy_files.h"
#include "cmd/delete.h"
#include "cmd/exec.h"
#include "cmd/find.h"
Expand All @@ -33,6 +32,7 @@
#include "cmd/start.h"
#include "cmd/stop.h"
#include "cmd/suspend.h"
#include "cmd/transfer.h"
#include "cmd/umount.h"
#include "cmd/version.h"

Expand Down Expand Up @@ -79,7 +79,6 @@ mp::Client::Client(ClientConfig& config)
stub{mp::Rpc::NewStub(rpc_channel)},
term{config.term}
{
add_command<cmd::CopyFiles>();
add_command<cmd::Launch>();
add_command<cmd::Purge>();
add_command<cmd::Exec>();
Expand All @@ -93,6 +92,7 @@ mp::Client::Client(ClientConfig& config)
add_command<cmd::Start>();
add_command<cmd::Stop>();
add_command<cmd::Suspend>();
add_command<cmd::Transfer>();
add_command<cmd::Restart>();
add_command<cmd::Delete>();
add_command<cmd::Umount>();
Expand Down
4 changes: 2 additions & 2 deletions src/client/cmd/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright © 2017-2018 Canonical Ltd.
# Copyright © 2017-2019 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
Expand All @@ -17,7 +17,6 @@
add_library(commands STATIC
animated_spinner.cpp
common_cli.cpp
copy_files.cpp
launch.cpp
purge.cpp
exec.cpp
Expand All @@ -33,6 +32,7 @@ add_library(commands STATIC
suspend.cpp
restart.cpp
delete.cpp
transfer.cpp
umount.cpp
version.cpp

Expand Down
31 changes: 18 additions & 13 deletions src/client/cmd/copy_files.cpp → src/client/cmd/transfer.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018 Canonical, Ltd.
* Copyright (C) 2018-2019 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
Expand All @@ -15,7 +15,7 @@
*
*/

#include "copy_files.h"
#include "transfer.h"
#include "common_cli.h"

#include <multipass/cli/argparser.h>
Expand All @@ -30,7 +30,7 @@ namespace cmd = multipass::cmd;
namespace mcp = multipass::cli::platform;
using RpcMethod = mp::Rpc::Stub;

mp::ReturnCode cmd::CopyFiles::run(mp::ArgParser* parser)
mp::ReturnCode cmd::Transfer::run(mp::ArgParser* parser)
{
auto ret = parse_args(parser);
if (ret != ParseCode::Ok)
Expand Down Expand Up @@ -70,7 +70,7 @@ mp::ReturnCode cmd::CopyFiles::run(mp::ArgParser* parser)
}
catch (const std::exception& e)
{
cerr << "copy-files failed: " << e.what() << "\n";
cerr << "transfer failed: " << e.what() << "\n";
return ReturnCode::CommandFail;
}
}
Expand All @@ -83,26 +83,31 @@ mp::ReturnCode cmd::CopyFiles::run(mp::ArgParser* parser)
return dispatch(&RpcMethod::ssh_info, request, on_success, on_failure);
}

std::string cmd::CopyFiles::name() const
std::string cmd::Transfer::name() const
{
return "copy-files";
return "transfer";
}

QString cmd::CopyFiles::short_help() const
std::vector<std::string> cmd::Transfer::aliases() const
{
return QStringLiteral("Copy files between the host and instances");
return {name(), "copy-files"};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice this is not reflected in the help, so the alias is hidden. Is that intended?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we've just left it here for muscle-memory purposes.

}

QString cmd::CopyFiles::description() const
QString cmd::Transfer::short_help() const
{
return QStringLiteral("Transfer files between the host and instances");
}

QString cmd::Transfer::description() const
{
// TODO: Don't mention directories until we support that
// return QStringLiteral("Copy files and directories between the host and instances.");
return QStringLiteral("Copy files between the host and instances.");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good choice leaving this as is (clarifies what is meant by transfer).

}

mp::ParseCode cmd::CopyFiles::parse_args(mp::ArgParser* parser)
mp::ParseCode cmd::Transfer::parse_args(mp::ArgParser* parser)
{
parser->addPositionalArgument("source", "One or more paths to copy, prefixed with <name:> "
parser->addPositionalArgument("source", "One or more paths to transfer, prefixed with <name:> "
"for paths inside the instance",
"<source> [<source> ...]");
parser->addPositionalArgument("destination", "The destination path, prefixed with <name:> for "
Expand All @@ -124,7 +129,7 @@ mp::ParseCode cmd::CopyFiles::parse_args(mp::ArgParser* parser)
auto source_entry = parser->positionalArguments().at(i);
QString source_path, instance_name;

mcp::parse_copy_files_entry(source_entry, source_path, instance_name);
mcp::parse_transfer_entry(source_entry, source_path, instance_name);

if (source_path.isEmpty())
{
Expand Down Expand Up @@ -165,7 +170,7 @@ mp::ParseCode cmd::CopyFiles::parse_args(mp::ArgParser* parser)
auto destination_entry = parser->positionalArguments().last();
QString destination_path, instance_name;

mcp::parse_copy_files_entry(destination_entry, destination_path, instance_name);
mcp::parse_transfer_entry(destination_entry, destination_path, instance_name);
if (instance_name.isEmpty())
{
QFileInfo destination(destination_path);
Expand Down
11 changes: 6 additions & 5 deletions src/client/cmd/copy_files.h → src/client/cmd/transfer.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018 Canonical, Ltd.
* Copyright (C) 2018-2019 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
Expand All @@ -15,8 +15,8 @@
*
*/

#ifndef MULTIPASS_COPY_FILES_H
#define MULTIPASS_COPY_FILES_H
#ifndef MULTIPASS_TRANSFER_H
#define MULTIPASS_TRANSFER_H

#include <multipass/cli/command.h>

Expand All @@ -27,13 +27,14 @@ namespace multipass
{
namespace cmd
{
class CopyFiles final : public Command
class Transfer final : public Command
{
public:
using Command::Command;
ReturnCode run(ArgParser* parser) override;

std::string name() const override;
std::vector<std::string> aliases() const override;
QString short_help() const override;
QString description() const override;

Expand All @@ -46,4 +47,4 @@ class CopyFiles final : public Command
};
}
}
#endif // MULTIPASS_COPY_FILES_H
#endif // MULTIPASS_TRANSFER_H
2 changes: 1 addition & 1 deletion src/platform/client/client_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

namespace mcp = multipass::cli::platform;

void mcp::parse_copy_files_entry(const QString& entry, QString& path, QString& instance_name)
void mcp::parse_transfer_entry(const QString& entry, QString& path, QString& instance_name)
{
auto colon_count = entry.count(":");

Expand Down
42 changes: 21 additions & 21 deletions tests/test_cli_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,61 +153,61 @@ TEST_F(Client, no_command_help_ok)
EXPECT_THAT(send_command({"-h"}), Eq(mp::ReturnCode::Ok));
}

// copy-files cli tests
TEST_F(Client, copy_files_cmd_good_source_remote)
// transfer cli tests
TEST_F(Client, transfer_cmd_good_source_remote)
{
EXPECT_CALL(mock_daemon, ssh_info(_, _, _));
EXPECT_THAT(send_command({"copy-files", "test-vm:foo", mpt::test_data_path().toStdString() + "good_index.json"}),
EXPECT_THAT(send_command({"transfer", "test-vm:foo", mpt::test_data_path().toStdString() + "good_index.json"}),
Eq(mp::ReturnCode::Ok));
}

TEST_F(Client, copy_files_cmd_good_destination_remote)
TEST_F(Client, transfer_cmd_good_destination_remote)
{
EXPECT_CALL(mock_daemon, ssh_info(_, _, _));
EXPECT_THAT(send_command({"copy-files", mpt::test_data_path().toStdString() + "good_index.json", "test-vm:bar"}),
EXPECT_THAT(send_command({"transfer", mpt::test_data_path().toStdString() + "good_index.json", "test-vm:bar"}),
Eq(mp::ReturnCode::Ok));
}

TEST_F(Client, copy_files_cmd_help_ok)
TEST_F(Client, transfer_cmd_help_ok)
{
EXPECT_THAT(send_command({"copy-files", "-h"}), Eq(mp::ReturnCode::Ok));
EXPECT_THAT(send_command({"transfer", "-h"}), Eq(mp::ReturnCode::Ok));
}

TEST_F(Client, copy_files_cmd_fails_invalid_source_file)
TEST_F(Client, transfer_cmd_fails_invalid_source_file)
{
EXPECT_THAT(send_command({"copy-files", "foo", "test-vm:bar"}), Eq(mp::ReturnCode::CommandLineError));
EXPECT_THAT(send_command({"transfer", "foo", "test-vm:bar"}), Eq(mp::ReturnCode::CommandLineError));
}

TEST_F(Client, copy_files_cmd_fails_source_is_dir)
TEST_F(Client, transfer_cmd_fails_source_is_dir)
{
EXPECT_THAT(send_command({"copy-files", mpt::test_data_path().toStdString(), "test-vm:bar"}),
EXPECT_THAT(send_command({"transfer", mpt::test_data_path().toStdString(), "test-vm:bar"}),
Eq(mp::ReturnCode::CommandLineError));
}

TEST_F(Client, copy_files_cmd_fails_no_instance)
TEST_F(Client, transfer_cmd_fails_no_instance)
{
EXPECT_THAT(send_command({"copy-files", mpt::test_data_path().toStdString() + "good_index.json", "."}),
EXPECT_THAT(send_command({"transfer", mpt::test_data_path().toStdString() + "good_index.json", "."}),
Eq(mp::ReturnCode::CommandLineError));
}

TEST_F(Client, copy_files_cmd_fails_instance_both_source_destination)
TEST_F(Client, transfer_cmd_fails_instance_both_source_destination)
{
EXPECT_THAT(send_command({"copy-files", "test-vm1:foo", "test-vm2:bar"}), Eq(mp::ReturnCode::CommandLineError));
EXPECT_THAT(send_command({"transfer", "test-vm1:foo", "test-vm2:bar"}), Eq(mp::ReturnCode::CommandLineError));
}

TEST_F(Client, copy_files_cmd_fails_too_few_args)
TEST_F(Client, transfer_cmd_fails_too_few_args)
{
EXPECT_THAT(send_command({"copy-files", "foo"}), Eq(mp::ReturnCode::CommandLineError));
EXPECT_THAT(send_command({"transfer", "foo"}), Eq(mp::ReturnCode::CommandLineError));
}

TEST_F(Client, copy_files_cmd_fails_source_path_empty)
TEST_F(Client, transfer_cmd_fails_source_path_empty)
{
EXPECT_THAT(send_command({"copy-files", "test-vm1:", "bar"}), Eq(mp::ReturnCode::CommandLineError));
EXPECT_THAT(send_command({"transfer", "test-vm1:", "bar"}), Eq(mp::ReturnCode::CommandLineError));
}

TEST_F(Client, copy_file_cmd_fails_multiple_sources_destination_file)
TEST_F(Client, transfer_cmd_fails_multiple_sources_destination_file)
{
EXPECT_THAT(send_command({"copy-files", "test-vm1:foo", "test-vm2:bar",
EXPECT_THAT(send_command({"transfer", "test-vm1:foo", "test-vm2:bar",
mpt::test_data_path().toStdString() + "good_index.json"}),
Eq(mp::ReturnCode::CommandLineError));
}
Expand Down