Skip to content

Commit

Permalink
rename get_available_commands
Browse files Browse the repository at this point in the history
also remove CommandType* types
  • Loading branch information
strega-nil committed Jul 31, 2020
1 parent 94578a3 commit cd2586d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 46 deletions.
10 changes: 3 additions & 7 deletions toolsrc/include/vcpkg/commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,16 @@

namespace vcpkg::Commands
{
using CommandTypeA = const TripletCommand*;
using CommandTypeB = const PathsCommand*;
using CommandTypeC = const BasicCommand*;

template<class T>
struct PackageNameAndFunction
{
std::string name;
T function;
};

Span<const PackageNameAndFunction<CommandTypeA>> get_available_commands_type_a();
Span<const PackageNameAndFunction<CommandTypeB>> get_available_commands_type_b();
Span<const PackageNameAndFunction<CommandTypeC>> get_available_commands_type_c();
Span<const PackageNameAndFunction<const BasicCommand*>> get_available_basic_commands();
Span<const PackageNameAndFunction<const PathsCommand*>> get_available_paths_commands();
Span<const PackageNameAndFunction<const TripletCommand*>> get_available_triplet_commands();

template<typename T>
T find(StringView command_name, Span<const PackageNameAndFunction<T>> available_commands)
Expand Down
10 changes: 5 additions & 5 deletions toolsrc/src/vcpkg-test/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ TEST_CASE ("test commands are constructible", "[commands]")
Commands::Version::VersionCommand version{};
}

TEST_CASE ("get_available_commands_type_c works", "[commands]")
TEST_CASE ("get_available_basic_commands works", "[commands]")
{
auto commands_list = Commands::get_available_commands_type_c();
auto commands_list = Commands::get_available_basic_commands();
CHECK(commands_list.size() == 2);
CHECK(Commands::find("version", commands_list) != nullptr);
CHECK(Commands::find("contact", commands_list) != nullptr);
CHECK(Commands::find("aang", commands_list) == nullptr);
}

TEST_CASE ("get_available_commands_type_b works", "[commands]")
TEST_CASE ("get_available_paths_commands works", "[commands]")
{
auto commands_list = Commands::get_available_commands_type_b();
auto commands_list = Commands::get_available_paths_commands();
CHECK(commands_list.size() == 18);

CHECK(Commands::find("/?", commands_list) != nullptr);
Expand All @@ -50,7 +50,7 @@ TEST_CASE ("get_available_commands_type_b works", "[commands]")

TEST_CASE ("get_available_commands_type_a works", "[commands]")
{
auto commands_list = Commands::get_available_commands_type_a();
auto commands_list = Commands::get_available_triplet_commands();
CHECK(commands_list.size() == 10);

CHECK(Commands::find("install", commands_list) != nullptr);
Expand Down
6 changes: 3 additions & 3 deletions toolsrc/src/vcpkg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static void inner(vcpkg::Files::Filesystem& fs, const VcpkgCmdArguments& args)
}
};

if (const auto command_function = find_command(Commands::get_available_commands_type_c()))
if (const auto command_function = find_command(Commands::get_available_basic_commands()))
{
return command_function->function->perform_and_exit(args, fs);
}
Expand Down Expand Up @@ -104,15 +104,15 @@ static void inner(vcpkg::Files::Filesystem& fs, const VcpkgCmdArguments& args)
}
}

if (const auto command_function = find_command(Commands::get_available_commands_type_b()))
if (const auto command_function = find_command(Commands::get_available_paths_commands()))
{
return command_function->function->perform_and_exit(args, paths);
}

Triplet default_triplet = vcpkg::default_triplet(args);
Input::check_triplet(default_triplet, paths);

if (const auto command_function = find_command(Commands::get_available_commands_type_a()))
if (const auto command_function = find_command(Commands::get_available_triplet_commands()))
{
return command_function->function->perform_and_exit(args, paths, default_triplet);
}
Expand Down
62 changes: 31 additions & 31 deletions toolsrc/src/vcpkg/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,35 +35,18 @@

namespace vcpkg::Commands
{
Span<const PackageNameAndFunction<CommandTypeA>> get_available_commands_type_a()
Span<const PackageNameAndFunction<const BasicCommand*>> get_available_basic_commands()
{
static const Install::InstallCommand install{};
static const SetInstalled::SetInstalledCommand set_installed{};
static const CI::CICommand ci{};
static const Remove::RemoveCommand remove{};
static const Upgrade::UpgradeCommand upgrade{};
static const Build::BuildCommand build{};
static const Env::EnvCommand env{};
static const BuildExternal::BuildExternalCommand build_external{};
static const Export::ExportCommand export_command{};
static const DependInfo::DependInfoCommand depend_info{};

static std::vector<PackageNameAndFunction<CommandTypeA>> t = {
{"install", &install},
{"x-set-installed", &set_installed},
{"ci", &ci},
{"remove", &remove},
{"upgrade", &upgrade},
{"build", &build},
{"env", &env},
{"build-external", &build_external},
{"export", &export_command},
{"depend-info", &depend_info},
static const Version::VersionCommand version{};
static const Contact::ContactCommand contact{};
static std::vector<PackageNameAndFunction<const BasicCommand*>> t = {
{"version", &version},
{"contact", &contact},
};
return t;
}

Span<const PackageNameAndFunction<CommandTypeB>> get_available_commands_type_b()
Span<const PackageNameAndFunction<const PathsCommand*>> get_available_paths_commands()
{
static const Help::HelpCommand help{};
static const Search::SearchCommand search{};
Expand All @@ -83,7 +66,7 @@ namespace vcpkg::Commands
static const X_VSInstances::VSInstancesCommand vsinstances{};
static const FormatManifest::FormatManifestCommand format_manifest{};

static std::vector<PackageNameAndFunction<CommandTypeB>> t = {
static std::vector<PackageNameAndFunction<const PathsCommand*>> t = {
{"/?", &help},
{"help", &help},
{"search", &search},
Expand All @@ -106,13 +89,30 @@ namespace vcpkg::Commands
return t;
}

Span<const PackageNameAndFunction<CommandTypeC>> get_available_commands_type_c()
Span<const PackageNameAndFunction<const TripletCommand*>> get_available_triplet_commands()
{
static const Version::VersionCommand version{};
static const Contact::ContactCommand contact{};
static std::vector<PackageNameAndFunction<CommandTypeC>> t = {
{"version", &version},
{"contact", &contact},
static const Install::InstallCommand install{};
static const SetInstalled::SetInstalledCommand set_installed{};
static const CI::CICommand ci{};
static const Remove::RemoveCommand remove{};
static const Upgrade::UpgradeCommand upgrade{};
static const Build::BuildCommand build{};
static const Env::EnvCommand env{};
static const BuildExternal::BuildExternalCommand build_external{};
static const Export::ExportCommand export_command{};
static const DependInfo::DependInfoCommand depend_info{};

static std::vector<PackageNameAndFunction<const TripletCommand*>> t = {
{"install", &install},
{"x-set-installed", &set_installed},
{"ci", &ci},
{"remove", &remove},
{"upgrade", &upgrade},
{"build", &build},
{"env", &env},
{"build-external", &build_external},
{"export", &export_command},
{"depend-info", &depend_info},
};
return t;
}
Expand Down

0 comments on commit cd2586d

Please sign in to comment.