diff options
| author | Alexander Karatarakis <alkarata@microsoft.com> | 2018-01-17 19:39:46 -0800 |
|---|---|---|
| committer | Alexander Karatarakis <alkarata@microsoft.com> | 2018-01-17 19:39:46 -0800 |
| commit | f563d2b58849d8ae6a04be0ad531cb2e20313fe0 (patch) | |
| tree | 1d07e985214ed26f2b821131d1789d9303ebb154 | |
| parent | 458dafc812a1bc4f3290397601457e93f53b2dea (diff) | |
| download | vcpkg-f563d2b58849d8ae6a04be0ad531cb2e20313fe0.tar.gz vcpkg-f563d2b58849d8ae6a04be0ad531cb2e20313fe0.zip | |
Use StringLiteral and constexpr for options/switches
| -rw-r--r-- | toolsrc/include/vcpkg/vcpkgcmdarguments.h | 19 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg/build.cpp | 5 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg/commands.autocomplete.cpp | 6 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg/commands.ci.cpp | 7 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg/commands.edit.cpp | 4 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg/commands.list.cpp | 5 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg/commands.search.cpp | 7 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg/commands.upgrade.cpp | 6 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg/export.cpp | 40 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg/install.cpp | 18 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg/remove.cpp | 12 |
11 files changed, 72 insertions, 57 deletions
diff --git a/toolsrc/include/vcpkg/vcpkgcmdarguments.h b/toolsrc/include/vcpkg/vcpkgcmdarguments.h index 93eeb6ef5..d84be9c22 100644 --- a/toolsrc/include/vcpkg/vcpkgcmdarguments.h +++ b/toolsrc/include/vcpkg/vcpkgcmdarguments.h @@ -3,6 +3,7 @@ #include <vcpkg/base/cstringview.h> #include <vcpkg/base/optional.h> #include <vcpkg/base/span.h> +#include <vcpkg/base/stringliteral.h> #include <memory> #include <unordered_map> @@ -21,14 +22,24 @@ namespace vcpkg struct CommandSwitch { - std::string name; - CStringView short_help_text; + constexpr CommandSwitch(const StringLiteral& name, const StringLiteral& short_help_text) + : name(name), short_help_text(short_help_text) + { + } + + StringLiteral name; + StringLiteral short_help_text; }; struct CommandSetting { - std::string name; - CStringView short_help_text; + constexpr CommandSetting(const StringLiteral& name, const StringLiteral& short_help_text) + : name(name), short_help_text(short_help_text) + { + } + + StringLiteral name; + StringLiteral short_help_text; }; struct CommandOptionsStructure diff --git a/toolsrc/src/vcpkg/build.cpp b/toolsrc/src/vcpkg/build.cpp index f43d8788e..960ba0400 100644 --- a/toolsrc/src/vcpkg/build.cpp +++ b/toolsrc/src/vcpkg/build.cpp @@ -4,6 +4,7 @@ #include <vcpkg/base/chrono.h> #include <vcpkg/base/enums.h> #include <vcpkg/base/optional.h> +#include <vcpkg/base/stringliteral.h> #include <vcpkg/base/system.h> #include <vcpkg/build.h> #include <vcpkg/commands.h> @@ -26,7 +27,7 @@ namespace vcpkg::Build::Command using Dependencies::InstallPlanAction; using Dependencies::InstallPlanType; - static const std::string OPTION_CHECKS_ONLY = "--checks-only"; + static constexpr StringLiteral OPTION_CHECKS_ONLY = "--checks-only"; void perform_and_exit_ex(const FullPackageSpec& full_spec, const fs::path& port_dir, @@ -97,7 +98,7 @@ namespace vcpkg::Build::Command Checks::exit_success(VCPKG_LINE_INFO); } - static const std::array<CommandSwitch, 1> BUILD_SWITCHES = {{ + static constexpr std::array<CommandSwitch, 1> BUILD_SWITCHES = {{ {OPTION_CHECKS_ONLY, "Only run checks, do not rebuild package"}, }}; diff --git a/toolsrc/src/vcpkg/commands.autocomplete.cpp b/toolsrc/src/vcpkg/commands.autocomplete.cpp index 0df7ec5eb..564404421 100644 --- a/toolsrc/src/vcpkg/commands.autocomplete.cpp +++ b/toolsrc/src/vcpkg/commands.autocomplete.cpp @@ -136,8 +136,8 @@ namespace vcpkg::Commands::Autocomplete const bool is_option = Strings::case_insensitive_ascii_starts_with(prefix, "-"); if (is_option) { - results = - Util::fmap(command.structure.options.switches, [](const CommandSwitch& s) { return s.name; }); + results = Util::fmap(command.structure.options.switches, + [](const CommandSwitch& s) -> std::string { return s.name; }); auto settings = Util::fmap(command.structure.options.settings, [](auto&& s) { return s.name; }); results.insert(results.end(), settings.begin(), settings.end()); @@ -145,7 +145,9 @@ namespace vcpkg::Commands::Autocomplete else { if (command.structure.valid_arguments != nullptr) + { results = command.structure.valid_arguments(paths); + } } Util::unstable_keep_if(results, [&](const std::string& s) { diff --git a/toolsrc/src/vcpkg/commands.ci.cpp b/toolsrc/src/vcpkg/commands.ci.cpp index 1a2f9b47f..4636a5738 100644 --- a/toolsrc/src/vcpkg/commands.ci.cpp +++ b/toolsrc/src/vcpkg/commands.ci.cpp @@ -1,6 +1,7 @@ #include "pch.h" #include <vcpkg/base/files.h> +#include <vcpkg/base/stringliteral.h> #include <vcpkg/base/system.h> #include <vcpkg/base/util.h> #include <vcpkg/build.h> @@ -62,10 +63,10 @@ namespace vcpkg::Commands::CI Install::InstallSummary summary; }; - static const std::string OPTION_EXCLUDE = "--exclude"; - static const std::string OPTION_XUNIT = "--x-xunit"; + static constexpr StringLiteral OPTION_EXCLUDE = "--exclude"; + static constexpr StringLiteral OPTION_XUNIT = "--x-xunit"; - static const std::array<CommandSetting, 2> CI_SETTINGS = {{ + static constexpr std::array<CommandSetting, 2> CI_SETTINGS = {{ {OPTION_EXCLUDE, "Comma separated list of ports to skip"}, {OPTION_XUNIT, "File to output results in XUnit format (internal)"}, }}; diff --git a/toolsrc/src/vcpkg/commands.edit.cpp b/toolsrc/src/vcpkg/commands.edit.cpp index e40e394fb..3e5d08956 100644 --- a/toolsrc/src/vcpkg/commands.edit.cpp +++ b/toolsrc/src/vcpkg/commands.edit.cpp @@ -32,7 +32,7 @@ namespace vcpkg::Commands::Edit return output; } - static const std::string OPTION_BUILDTREES = "--buildtrees"; + static constexpr StringLiteral OPTION_BUILDTREES = "--buildtrees"; static std::vector<std::string> valid_arguments(const VcpkgPaths& paths) { @@ -42,7 +42,7 @@ namespace vcpkg::Commands::Edit [](auto&& pgh) -> std::string { return pgh->core_paragraph->name; }); } - static const std::array<CommandSwitch, 1> EDIT_SWITCHES = {{ + static constexpr std::array<CommandSwitch, 1> EDIT_SWITCHES = {{ {OPTION_BUILDTREES, "Open editor into the port-specific buildtree subfolder"}, }}; diff --git a/toolsrc/src/vcpkg/commands.list.cpp b/toolsrc/src/vcpkg/commands.list.cpp index 960c57225..2570c8a6d 100644 --- a/toolsrc/src/vcpkg/commands.list.cpp +++ b/toolsrc/src/vcpkg/commands.list.cpp @@ -7,7 +7,8 @@ namespace vcpkg::Commands::List { - static const std::string OPTION_FULLDESC = "--x-full-desc"; // TODO: This should find a better home, eventually + static constexpr StringLiteral OPTION_FULLDESC = + "--x-full-desc"; // TODO: This should find a better home, eventually static void do_print(const StatusParagraph& pgh, bool full_desc) { @@ -24,7 +25,7 @@ namespace vcpkg::Commands::List } } - static const std::array<CommandSwitch, 1> LIST_SWITCHES = {{ + static constexpr std::array<CommandSwitch, 1> LIST_SWITCHES = {{ {OPTION_FULLDESC, "Do not truncate long text"}, }}; diff --git a/toolsrc/src/vcpkg/commands.search.cpp b/toolsrc/src/vcpkg/commands.search.cpp index 01291ddfb..33a642e40 100644 --- a/toolsrc/src/vcpkg/commands.search.cpp +++ b/toolsrc/src/vcpkg/commands.search.cpp @@ -10,8 +10,9 @@ namespace vcpkg::Commands::Search { - static const std::string OPTION_GRAPH = "--graph"; // TODO: This should find a better home, eventually - static const std::string OPTION_FULLDESC = "--x-full-desc"; // TODO: This should find a better home, eventually + static constexpr StringLiteral OPTION_GRAPH = "--graph"; // TODO: This should find a better home, eventually + static constexpr StringLiteral OPTION_FULLDESC = + "--x-full-desc"; // TODO: This should find a better home, eventually static std::string replace_dashes_with_underscore(const std::string& input) { @@ -79,7 +80,7 @@ namespace vcpkg::Commands::Search } } - static std::array<CommandSwitch, 2> SEARCH_SWITCHES = {{ + static constexpr std::array<CommandSwitch, 2> SEARCH_SWITCHES = {{ {OPTION_GRAPH, "Open editor into the port-specific buildtree subfolder"}, {OPTION_FULLDESC, "Do not truncate long text"}, }}; diff --git a/toolsrc/src/vcpkg/commands.upgrade.cpp b/toolsrc/src/vcpkg/commands.upgrade.cpp index d2c868870..bb26dc735 100644 --- a/toolsrc/src/vcpkg/commands.upgrade.cpp +++ b/toolsrc/src/vcpkg/commands.upgrade.cpp @@ -15,10 +15,10 @@ namespace vcpkg::Commands::Upgrade using Install::KeepGoing; using Install::to_keep_going; - static const std::string OPTION_NO_DRY_RUN = "--no-dry-run"; - static const std::string OPTION_KEEP_GOING = "--keep-going"; + static constexpr StringLiteral OPTION_NO_DRY_RUN = "--no-dry-run"; + static constexpr StringLiteral OPTION_KEEP_GOING = "--keep-going"; - static const std::array<CommandSwitch, 2> INSTALL_SWITCHES = {{ + static constexpr std::array<CommandSwitch, 2> INSTALL_SWITCHES = {{ {OPTION_NO_DRY_RUN, "Actually upgrade"}, {OPTION_KEEP_GOING, "Continue installing packages on failure"}, }}; diff --git a/toolsrc/src/vcpkg/export.cpp b/toolsrc/src/vcpkg/export.cpp index d15df95d2..64cb3c804 100644 --- a/toolsrc/src/vcpkg/export.cpp +++ b/toolsrc/src/vcpkg/export.cpp @@ -1,5 +1,6 @@ #include "pch.h" +#include <vcpkg/base/stringliteral.h> #include <vcpkg/base/system.h> #include <vcpkg/base/util.h> #include <vcpkg/commands.h> @@ -260,22 +261,22 @@ namespace vcpkg::Export std::vector<PackageSpec> specs; }; - static const std::string OPTION_OUTPUT = "--output"; - static const std::string OPTION_DRY_RUN = "--dry-run"; - static const std::string OPTION_RAW = "--raw"; - static const std::string OPTION_NUGET = "--nuget"; - static const std::string OPTION_IFW = "--ifw"; - static const std::string OPTION_ZIP = "--zip"; - static const std::string OPTION_SEVEN_ZIP = "--7zip"; - static const std::string OPTION_NUGET_ID = "--nuget-id"; - static const std::string OPTION_NUGET_VERSION = "--nuget-version"; - static const std::string OPTION_IFW_REPOSITORY_URL = "--ifw-repository-url"; - static const std::string OPTION_IFW_PACKAGES_DIR_PATH = "--ifw-packages-directory-path"; - static const std::string OPTION_IFW_REPOSITORY_DIR_PATH = "--ifw-repository-directory-path"; - static const std::string OPTION_IFW_CONFIG_FILE_PATH = "--ifw-configuration-file-path"; - static const std::string OPTION_IFW_INSTALLER_FILE_PATH = "--ifw-installer-file-path"; - - static const std::array<CommandSwitch, 6> EXPORT_SWITCHES = {{ + static constexpr StringLiteral OPTION_OUTPUT = "--output"; + static constexpr StringLiteral OPTION_DRY_RUN = "--dry-run"; + static constexpr StringLiteral OPTION_RAW = "--raw"; + static constexpr StringLiteral OPTION_NUGET = "--nuget"; + static constexpr StringLiteral OPTION_IFW = "--ifw"; + static constexpr StringLiteral OPTION_ZIP = "--zip"; + static constexpr StringLiteral OPTION_SEVEN_ZIP = "--7zip"; + static constexpr StringLiteral OPTION_NUGET_ID = "--nuget-id"; + static constexpr StringLiteral OPTION_NUGET_VERSION = "--nuget-version"; + static constexpr StringLiteral OPTION_IFW_REPOSITORY_URL = "--ifw-repository-url"; + static constexpr StringLiteral OPTION_IFW_PACKAGES_DIR_PATH = "--ifw-packages-directory-path"; + static constexpr StringLiteral OPTION_IFW_REPOSITORY_DIR_PATH = "--ifw-repository-directory-path"; + static constexpr StringLiteral OPTION_IFW_CONFIG_FILE_PATH = "--ifw-configuration-file-path"; + static constexpr StringLiteral OPTION_IFW_INSTALLER_FILE_PATH = "--ifw-installer-file-path"; + + static constexpr std::array<CommandSwitch, 6> EXPORT_SWITCHES = {{ {OPTION_DRY_RUN, "Do not actually export"}, {OPTION_RAW, "Export to an uncompressed directory"}, {OPTION_NUGET, "Export a NuGet package"}, @@ -284,12 +285,9 @@ namespace vcpkg::Export {OPTION_SEVEN_ZIP, "Export to a 7zip (.7z) file"}, }}; - static const std::string EXPORT_SETTINGS_NUGET_ID_HELP_TEXT = - Strings::format("Specify the id for the exported NuGet package (overrides %s)", OPTION_OUTPUT); - - static const std::array<CommandSetting, 8> EXPORT_SETTINGS = {{ + static constexpr std::array<CommandSetting, 8> EXPORT_SETTINGS = {{ {OPTION_OUTPUT, "Specify the output name (used to construct filename)"}, - {OPTION_NUGET_ID, EXPORT_SETTINGS_NUGET_ID_HELP_TEXT}, + {OPTION_NUGET_ID, "Specify the id for the exported NuGet package (overrides --output)"}, {OPTION_NUGET_VERSION, "Specify the version for the exported NuGet package"}, {OPTION_IFW_REPOSITORY_URL, "Specify the remote repository URL for the online installer"}, {OPTION_IFW_PACKAGES_DIR_PATH, "Specify the temporary directory path for the repacked packages"}, diff --git a/toolsrc/src/vcpkg/install.cpp b/toolsrc/src/vcpkg/install.cpp index dcc130be3..d6a28d57c 100644 --- a/toolsrc/src/vcpkg/install.cpp +++ b/toolsrc/src/vcpkg/install.cpp @@ -413,21 +413,21 @@ namespace vcpkg::Install return InstallSummary{std::move(results), timer.to_string()}; } - static const std::string OPTION_DRY_RUN = "--dry-run"; - static const std::string OPTION_USE_HEAD_VERSION = "--head"; - static const std::string OPTION_NO_DOWNLOADS = "--no-downloads"; - static const std::string OPTION_RECURSE = "--recurse"; - static const std::string OPTION_KEEP_GOING = "--keep-going"; - static const std::string OPTION_XUNIT = "--x-xunit"; - - static const std::array<CommandSwitch, 5> INSTALL_SWITCHES = {{ + static constexpr StringLiteral OPTION_DRY_RUN = "--dry-run"; + static constexpr StringLiteral OPTION_USE_HEAD_VERSION = "--head"; + static constexpr StringLiteral OPTION_NO_DOWNLOADS = "--no-downloads"; + static constexpr StringLiteral OPTION_RECURSE = "--recurse"; + static constexpr StringLiteral OPTION_KEEP_GOING = "--keep-going"; + static constexpr StringLiteral OPTION_XUNIT = "--x-xunit"; + + static constexpr std::array<CommandSwitch, 5> INSTALL_SWITCHES = {{ {OPTION_DRY_RUN, "Do not actually build or install"}, {OPTION_USE_HEAD_VERSION, "Install the libraries on the command line using the latest upstream sources"}, {OPTION_NO_DOWNLOADS, "Do not download new sources"}, {OPTION_RECURSE, "Allow removal of packages as part of installation"}, {OPTION_KEEP_GOING, "Continue installing packages on failure"}, }}; - static const std::array<CommandSetting, 1> INSTALL_SETTINGS = {{ + static constexpr std::array<CommandSetting, 1> INSTALL_SETTINGS = {{ {OPTION_XUNIT, "File to output results in XUnit format (Internal use)"}, }}; diff --git a/toolsrc/src/vcpkg/remove.cpp b/toolsrc/src/vcpkg/remove.cpp index 4079d60c1..e03df2ed2 100644 --- a/toolsrc/src/vcpkg/remove.cpp +++ b/toolsrc/src/vcpkg/remove.cpp @@ -164,13 +164,13 @@ namespace vcpkg::Remove } } - static const std::string OPTION_PURGE = "--purge"; - static const std::string OPTION_NO_PURGE = "--no-purge"; - static const std::string OPTION_RECURSE = "--recurse"; - static const std::string OPTION_DRY_RUN = "--dry-run"; - static const std::string OPTION_OUTDATED = "--outdated"; + static constexpr StringLiteral OPTION_PURGE = "--purge"; + static constexpr StringLiteral OPTION_NO_PURGE = "--no-purge"; + static constexpr StringLiteral OPTION_RECURSE = "--recurse"; + static constexpr StringLiteral OPTION_DRY_RUN = "--dry-run"; + static constexpr StringLiteral OPTION_OUTDATED = "--outdated"; - static const std::array<CommandSwitch, 5> SWITCHES = {{ + static constexpr std::array<CommandSwitch, 5> SWITCHES = {{ {OPTION_PURGE, "Remove the cached copy of the package (default)"}, {OPTION_NO_PURGE, "Do not remove the cached copy of the package"}, {OPTION_RECURSE, "Allow removal of packages not explicitly specified on the command line"}, |
