Skip to content

Commit

Permalink
[vcpkg] Refactor commands 2: Electric Boogaloo (#12641)
Browse files Browse the repository at this point in the history
* Add BasicCommand and VersionCommand

* Add ContactCommand

* test get_available_commands_type_c

* Change get_available_commands_type_c to return objects

* Add TripletCommand & InstallCommand

* Add SetInstalledCommand

* add linking tests

* Add CICommand

* Add remaining *Command objects

* Add tests for commands_type_a

* Move over to using const TripletCommand* for commands_type_a

* Add PathsCommand

* Add SearchCommand

* add test for commands_type_b

* add *Command for all type b commands

* Switch from function pointers to PathsCommand for everything

* format

* rename get_available_commands

also remove CommandType* types
  • Loading branch information
strega-nil authored Aug 1, 2020
1 parent 00e4436 commit 54ec974
Show file tree
Hide file tree
Showing 63 changed files with 555 additions and 115 deletions.
8 changes: 8 additions & 0 deletions toolsrc/include/vcpkg/build.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <vcpkg/base/system.process.h>

#include <vcpkg/cmakevars.h>
#include <vcpkg/commands.integrate.h>
#include <vcpkg/packagespec.h>
#include <vcpkg/statusparagraphs.h>
#include <vcpkg/triplet.h>
Expand Down Expand Up @@ -346,4 +347,11 @@ namespace vcpkg::Build

bool m_compiler_tracking;
};

struct BuildCommand : Commands::TripletCommand
{
virtual void perform_and_exit(const VcpkgCmdArguments& args,
const VcpkgPaths& paths,
Triplet default_triplet) const override;
};
}
5 changes: 5 additions & 0 deletions toolsrc/include/vcpkg/commands.autocomplete.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@
namespace vcpkg::Commands::Autocomplete
{
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths);

struct AutocompleteCommand : PathsCommand
{
virtual void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) const override;
};
}
7 changes: 7 additions & 0 deletions toolsrc/include/vcpkg/commands.buildexternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,11 @@
namespace vcpkg::Commands::BuildExternal
{
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, Triplet default_triplet);

struct BuildExternalCommand : TripletCommand
{
virtual void perform_and_exit(const VcpkgCmdArguments& args,
const VcpkgPaths& paths,
Triplet default_triplet) const override;
};
}
5 changes: 5 additions & 0 deletions toolsrc/include/vcpkg/commands.cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@
namespace vcpkg::Commands::Cache
{
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths);

struct CacheCommand : PathsCommand
{
virtual void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) const override;
};
}
7 changes: 7 additions & 0 deletions toolsrc/include/vcpkg/commands.ci.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@ namespace vcpkg::Commands::CI
{
extern const CommandStructure COMMAND_STRUCTURE;
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, Triplet default_triplet);

struct CICommand : TripletCommand
{
virtual void perform_and_exit(const VcpkgCmdArguments& args,
const VcpkgPaths& paths,
Triplet default_triplet) const override;
};
}
5 changes: 5 additions & 0 deletions toolsrc/include/vcpkg/commands.ciclean.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@
namespace vcpkg::Commands::CIClean
{
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths);

struct CICleanCommand : PathsCommand
{
virtual void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) const override;
};
}
5 changes: 5 additions & 0 deletions toolsrc/include/vcpkg/commands.contact.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@ namespace vcpkg::Commands::Contact
extern const CommandStructure COMMAND_STRUCTURE;
const std::string& email();
void perform_and_exit(const VcpkgCmdArguments& args, Files::Filesystem& fs);

struct ContactCommand : BasicCommand
{
virtual void perform_and_exit(const VcpkgCmdArguments& args, Files::Filesystem& fs) const override;
};
}
5 changes: 5 additions & 0 deletions toolsrc/include/vcpkg/commands.create.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@ namespace vcpkg::Commands::Create
extern const CommandStructure COMMAND_STRUCTURE;
int perform(const VcpkgCmdArguments& args, const VcpkgPaths& paths);
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths);

struct CreateCommand : PathsCommand
{
virtual void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) const override;
};
}
7 changes: 7 additions & 0 deletions toolsrc/include/vcpkg/commands.dependinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@ namespace vcpkg::Commands::DependInfo
{
extern const CommandStructure COMMAND_STRUCTURE;
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, Triplet default_triplet);

struct DependInfoCommand : TripletCommand
{
virtual void perform_and_exit(const VcpkgCmdArguments& args,
const VcpkgPaths& paths,
Triplet default_triplet) const override;
};
}
5 changes: 5 additions & 0 deletions toolsrc/include/vcpkg/commands.edit.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@ namespace vcpkg::Commands::Edit
{
extern const CommandStructure COMMAND_STRUCTURE;
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths);

struct EditCommand : PathsCommand
{
virtual void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) const override;
};
}
7 changes: 7 additions & 0 deletions toolsrc/include/vcpkg/commands.env.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@ namespace vcpkg::Commands::Env
{
extern const CommandStructure COMMAND_STRUCTURE;
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, Triplet default_triplet);

struct EnvCommand : TripletCommand
{
virtual void perform_and_exit(const VcpkgCmdArguments& args,
const VcpkgPaths& paths,
Triplet default_triplet) const override;
};
}
5 changes: 5 additions & 0 deletions toolsrc/include/vcpkg/commands.fetch.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@
namespace vcpkg::Commands::Fetch
{
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths);

struct FetchCommand : PathsCommand
{
virtual void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) const override;
};
}
5 changes: 5 additions & 0 deletions toolsrc/include/vcpkg/commands.format-manifest.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@ namespace vcpkg::Commands::FormatManifest
{
extern const CommandStructure COMMAND_STRUCTURE;
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths);

struct FormatManifestCommand : PathsCommand
{
virtual void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) const override;
};
}
12 changes: 4 additions & 8 deletions toolsrc/include/vcpkg/commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,19 @@

namespace vcpkg::Commands
{
using CommandTypeA = void (*)(const VcpkgCmdArguments& args, const VcpkgPaths& paths, Triplet default_triplet);
using CommandTypeB = void (*)(const VcpkgCmdArguments& args, const VcpkgPaths& paths);
using CommandTypeC = void (*)(const VcpkgCmdArguments& args, Files::Filesystem& fs);

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(const std::string& command_name, const std::vector<PackageNameAndFunction<T>> available_commands)
T find(StringView command_name, Span<const PackageNameAndFunction<T>> available_commands)
{
for (const PackageNameAndFunction<T>& cmd : available_commands)
{
Expand Down
5 changes: 5 additions & 0 deletions toolsrc/include/vcpkg/commands.hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@
namespace vcpkg::Commands::Hash
{
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths);

struct HashCommand : PathsCommand
{
virtual void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) const override;
};
}
5 changes: 5 additions & 0 deletions toolsrc/include/vcpkg/commands.integrate.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@ namespace vcpkg::Commands::Integrate
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths);
void append_helpstring(HelpTableFormatter& table);
std::string get_helpstring();

struct IntegrateCommand : PathsCommand
{
virtual void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) const override;
};
}
20 changes: 20 additions & 0 deletions toolsrc/include/vcpkg/commands.interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,24 @@ namespace vcpkg::Commands
No,
Yes,
};

struct BasicCommand
{
virtual void perform_and_exit(const VcpkgCmdArguments& args, Files::Filesystem& fs) const = 0;
virtual ~BasicCommand() = default;
};

struct PathsCommand
{
virtual void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) const = 0;
virtual ~PathsCommand() = default;
};

struct TripletCommand
{
virtual void perform_and_exit(const VcpkgCmdArguments& args,
const VcpkgPaths& paths,
Triplet default_triplet) const = 0;
virtual ~TripletCommand() = default;
};
}
5 changes: 5 additions & 0 deletions toolsrc/include/vcpkg/commands.list.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@ namespace vcpkg::Commands::List
{
extern const CommandStructure COMMAND_STRUCTURE;
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths);

struct ListCommand : PathsCommand
{
virtual void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) const override;
};
}
5 changes: 5 additions & 0 deletions toolsrc/include/vcpkg/commands.owns.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@ namespace vcpkg::Commands::Owns
{
extern const CommandStructure COMMAND_STRUCTURE;
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths);

struct OwnsCommand : PathsCommand
{
virtual void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) const override;
};
}
5 changes: 5 additions & 0 deletions toolsrc/include/vcpkg/commands.porthistory.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@
namespace vcpkg::Commands::PortHistory
{
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths);

struct PortHistoryCommand : PathsCommand
{
virtual void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) const override;
};
}
5 changes: 5 additions & 0 deletions toolsrc/include/vcpkg/commands.portsdiff.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@
namespace vcpkg::Commands::PortsDiff
{
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths);

struct PortsDiffCommand : PathsCommand
{
virtual void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) const override;
};
}
5 changes: 5 additions & 0 deletions toolsrc/include/vcpkg/commands.search.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@ namespace vcpkg::Commands::Search
{
extern const CommandStructure COMMAND_STRUCTURE;
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths);

struct SearchCommand : PathsCommand
{
virtual void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) const override;
};
}
7 changes: 7 additions & 0 deletions toolsrc/include/vcpkg/commands.setinstalled.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,11 @@ namespace vcpkg::Commands::SetInstalled
DryRun dry_run,
const Optional<fs::path>& pkgsconfig_path);
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, Triplet default_triplet);

struct SetInstalledCommand : TripletCommand
{
virtual void perform_and_exit(const VcpkgCmdArguments& args,
const VcpkgPaths& paths,
Triplet default_triplet) const override;
};
}
7 changes: 7 additions & 0 deletions toolsrc/include/vcpkg/commands.upgrade.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@ namespace vcpkg::Commands::Upgrade
{
extern const CommandStructure COMMAND_STRUCTURE;
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, Triplet default_triplet);

struct UpgradeCommand : TripletCommand
{
virtual void perform_and_exit(const VcpkgCmdArguments& args,
const VcpkgPaths& paths,
Triplet default_triplet) const override;
};
}
5 changes: 5 additions & 0 deletions toolsrc/include/vcpkg/commands.version.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@ namespace vcpkg::Commands::Version
const std::string& version();
void warn_if_vcpkg_version_mismatch(const VcpkgPaths& paths);
void perform_and_exit(const VcpkgCmdArguments& args, Files::Filesystem& fs);

struct VersionCommand : BasicCommand
{
virtual void perform_and_exit(const VcpkgCmdArguments& args, Files::Filesystem& fs) const override;
};
}
12 changes: 7 additions & 5 deletions toolsrc/include/vcpkg/commands.xvsinstances.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

#include <vcpkg/commands.interface.h>

namespace vcpkg::Commands
namespace vcpkg::Commands::X_VSInstances
{
namespace X_VSInstances
extern const CommandStructure COMMAND_STRUCTURE;
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths);

struct VSInstancesCommand : PathsCommand
{
extern const CommandStructure COMMAND_STRUCTURE;
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths);
}
virtual void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) const override;
};
}
9 changes: 8 additions & 1 deletion toolsrc/include/vcpkg/export.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <vcpkg/vcpkgpaths.h>
#include <vcpkg/commands.interface.h>

namespace vcpkg::Export
{
Expand All @@ -9,4 +9,11 @@ namespace vcpkg::Export
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, Triplet default_triplet);

void export_integration_files(const fs::path& raw_exported_dir_path, const VcpkgPaths& paths);

struct ExportCommand : Commands::TripletCommand
{
virtual void perform_and_exit(const VcpkgCmdArguments& args,
const VcpkgPaths& paths,
Triplet default_triplet) const override;
};
}
8 changes: 6 additions & 2 deletions toolsrc/include/vcpkg/help.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include <vcpkg/vcpkgcmdarguments.h>
#include <vcpkg/vcpkgpaths.h>
#include <vcpkg/commands.interface.h>

#include <string>

Expand All @@ -12,4 +11,9 @@ namespace vcpkg::Help
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths);

void help_topic_valid_triplet(const VcpkgPaths& paths);

struct HelpCommand : Commands::PathsCommand
{
virtual void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) const override;
};
}
7 changes: 7 additions & 0 deletions toolsrc/include/vcpkg/install.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,11 @@ namespace vcpkg::Install
extern const CommandStructure COMMAND_STRUCTURE;

void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, Triplet default_triplet);

struct InstallCommand : Commands::TripletCommand
{
virtual void perform_and_exit(const VcpkgCmdArguments& args,
const VcpkgPaths& paths,
Triplet default_triplet) const override;
};
}
10 changes: 8 additions & 2 deletions toolsrc/include/vcpkg/remove.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#pragma once

#include <vcpkg/commands.interface.h>
#include <vcpkg/dependencies.h>
#include <vcpkg/vcpkgcmdarguments.h>
#include <vcpkg/vcpkgpaths.h>

namespace vcpkg::Remove
{
Expand All @@ -23,4 +22,11 @@ namespace vcpkg::Remove

void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, Triplet default_triplet);
void remove_package(const VcpkgPaths& paths, const PackageSpec& spec, StatusParagraphs* status_db);

struct RemoveCommand : Commands::TripletCommand
{
virtual void perform_and_exit(const VcpkgCmdArguments& args,
const VcpkgPaths& paths,
Triplet default_triplet) const override;
};
}
Loading

0 comments on commit 54ec974

Please sign in to comment.