aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src
diff options
context:
space:
mode:
Diffstat (limited to 'toolsrc/src')
-rw-r--r--toolsrc/src/commands_create.cpp10
-rw-r--r--toolsrc/src/commands_edit.cpp6
-rw-r--r--toolsrc/src/commands_help.cpp5
-rw-r--r--toolsrc/src/commands_import.cpp9
-rw-r--r--toolsrc/src/commands_installation.cpp16
-rw-r--r--toolsrc/src/commands_integration.cpp10
-rw-r--r--toolsrc/src/commands_list.cpp2
-rw-r--r--toolsrc/src/commands_other.cpp5
-rw-r--r--toolsrc/src/commands_owns.cpp10
-rw-r--r--toolsrc/src/commands_remove.cpp3
-rw-r--r--toolsrc/src/commands_search.cpp4
-rw-r--r--toolsrc/src/commands_update.cpp3
12 files changed, 37 insertions, 46 deletions
diff --git a/toolsrc/src/commands_create.cpp b/toolsrc/src/commands_create.cpp
index 2292581ee..d365dac70 100644
--- a/toolsrc/src/commands_create.cpp
+++ b/toolsrc/src/commands_create.cpp
@@ -7,13 +7,9 @@ namespace vcpkg
{
void create_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet)
{
- args.check_max_arg_count(3);
- if (args.command_arguments.size() < 2)
- {
- System::println(System::color::error, "Error: create requires the archive's URL as the second argument.");
- print_usage();
- exit(EXIT_FAILURE);
- }
+ static const std::string example = create_example_string(R"###(create zlib2 http://zlib.net/zlib128.zip "zlib128-2.zip")###");
+ args.check_max_arg_count(3, example.c_str());
+ args.check_min_arg_count(2, example.c_str());
expected<package_spec> current_spec = package_spec::from_string(args.command_arguments[0], default_target_triplet);
if (const package_spec* spec = current_spec.get())
diff --git a/toolsrc/src/commands_edit.cpp b/toolsrc/src/commands_edit.cpp
index 09de37545..d29d55a58 100644
--- a/toolsrc/src/commands_edit.cpp
+++ b/toolsrc/src/commands_edit.cpp
@@ -5,9 +5,9 @@ namespace vcpkg
{
void edit_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet)
{
- static auto example = create_example_string("edit zlib").c_str();
- args.check_max_arg_count(1, example);
- package_spec spec = args.parse_all_arguments_as_package_specs(default_target_triplet, example).at(0);
+ static const std::string example = create_example_string("edit zlib");
+ args.check_exact_arg_count(1, example.c_str());
+ package_spec spec = args.parse_all_arguments_as_package_specs(default_target_triplet, example.c_str()).at(0);
// Find editor
std::wstring env_EDITOR = System::wdupenv_str(L"EDITOR");
diff --git a/toolsrc/src/commands_help.cpp b/toolsrc/src/commands_help.cpp
index 69aabd9cc..27dc168a4 100644
--- a/toolsrc/src/commands_help.cpp
+++ b/toolsrc/src/commands_help.cpp
@@ -6,7 +6,7 @@ namespace vcpkg
{
void version_command(const vcpkg_cmd_arguments& args)
{
- args.check_max_arg_count(0);
+ args.check_exact_arg_count(0);
System::println("Vcpkg package management program version %s\n"
"\n"
"Vcpkg is provided \"as-is\" without warranty of any kind, express or implied.\n"
@@ -37,8 +37,9 @@ namespace vcpkg
exit(EXIT_SUCCESS);
}
- void contact_command(const vcpkg_cmd_arguments& /*args*/)
+ void contact_command(const vcpkg_cmd_arguments& args)
{
+ args.check_exact_arg_count(0);
System::println("Send an email to vcpkg@microsoft.com with any feedback.");
exit(EXIT_SUCCESS);
}
diff --git a/toolsrc/src/commands_import.cpp b/toolsrc/src/commands_import.cpp
index b1eae277c..9cfc53d6c 100644
--- a/toolsrc/src/commands_import.cpp
+++ b/toolsrc/src/commands_import.cpp
@@ -1,17 +1,12 @@
#include "vcpkg_Commands.h"
#include "vcpkg.h"
-#include "vcpkg_System.h"
namespace vcpkg
{
void import_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths)
{
- if (args.command_arguments.size() != 3)
- {
- System::println(System::color::error, "Error: %s requires 3 parameters", args.command);
- print_example(Strings::format(R"(%s C:\path\to\CONTROLfile C:\path\to\includedir C:\path\to\projectdir)", args.command).c_str());
- exit(EXIT_FAILURE);
- }
+ static const std::string example = create_example_string(R"(import C:\path\to\CONTROLfile C:\path\to\includedir C:\path\to\projectdir)");
+ args.check_exact_arg_count(3, example.c_str());
const fs::path control_file_path(args.command_arguments[0]);
const fs::path include_directory(args.command_arguments[1]);
diff --git a/toolsrc/src/commands_installation.cpp b/toolsrc/src/commands_installation.cpp
index 6604685c0..baa0e6951 100644
--- a/toolsrc/src/commands_installation.cpp
+++ b/toolsrc/src/commands_installation.cpp
@@ -65,6 +65,8 @@ namespace vcpkg
void install_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet)
{
+ static const std::string example = create_example_string("install zlib zlib:x64-windows curl boost");
+ args.check_min_arg_count(1, example.c_str());
StatusParagraphs status_db = database_load_check(paths);
std::vector<package_spec> specs = args.parse_all_arguments_as_package_specs(default_target_triplet);
@@ -120,10 +122,12 @@ namespace vcpkg
void build_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet)
{
+ static const std::string example = create_example_string("build zlib:x64-windows");
+
// Installing multiple packages leads to unintuitive behavior if one of them depends on another.
- // Allowing only 1 package for now.
- args.check_max_arg_count(1);
+ // Allowing only 1 package for now.
+ args.check_exact_arg_count(1, example.c_str());
StatusParagraphs status_db = database_load_check(paths);
const package_spec spec = args.parse_all_arguments_as_package_specs(default_target_triplet).at(0);
@@ -148,12 +152,8 @@ namespace vcpkg
void build_external_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet)
{
- if (args.command_arguments.size() != 2)
- {
- System::println(System::color::error, "Error: buildexternal requires the package name and the directory containing the CONTROL file");
- print_example(R"(buildexternal mylib C:\path\to\mylib\)");
- exit(EXIT_FAILURE);
- }
+ static const std::string example = create_example_string(R"(build_external zlib2 C:\path\to\dir\with\controlfile\)");
+ args.check_exact_arg_count(2, example.c_str());
expected<package_spec> current_spec = package_spec::from_string(args.command_arguments[0], default_target_triplet);
if (auto spec = current_spec.get())
diff --git a/toolsrc/src/commands_integration.cpp b/toolsrc/src/commands_integration.cpp
index 743a57a70..6a11d6ec4 100644
--- a/toolsrc/src/commands_integration.cpp
+++ b/toolsrc/src/commands_integration.cpp
@@ -297,13 +297,9 @@ With a project open, go to Tools->NuGet Package Manager->Package Manager Console
void integrate_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths)
{
- if (args.command_arguments.size() != 1)
- {
- std::cout << "Commands:\n" <<
- INTEGRATE_COMMAND_HELPSTRING <<
- "\n";
- exit(EXIT_FAILURE);
- }
+ static const std::string example = Strings::format("Commands:\n"
+ "%s", INTEGRATE_COMMAND_HELPSTRING);
+ args.check_exact_arg_count(1, example.c_str());
if (args.command_arguments[0] == "install")
{
diff --git a/toolsrc/src/commands_list.cpp b/toolsrc/src/commands_list.cpp
index ad34e76bf..194e4b435 100644
--- a/toolsrc/src/commands_list.cpp
+++ b/toolsrc/src/commands_list.cpp
@@ -6,7 +6,7 @@ namespace vcpkg
{
void list_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths)
{
- args.check_max_arg_count(0);
+ args.check_exact_arg_count(0);
std::vector<std::string> packages_output;
for (auto&& pgh : database_load_check(paths))
diff --git a/toolsrc/src/commands_other.cpp b/toolsrc/src/commands_other.cpp
index 63f7c52b2..4ba4112d4 100644
--- a/toolsrc/src/commands_other.cpp
+++ b/toolsrc/src/commands_other.cpp
@@ -43,8 +43,9 @@ namespace vcpkg
std::string create_example_string(const char* command_and_arguments)
{
- return Strings::format("Example:\n"
- " vcpkg %s", command_and_arguments);
+ std::string cs = Strings::format("Example:\n"
+ " vcpkg %s", command_and_arguments);
+ return cs;
}
void print_example(const char* command_and_arguments)
diff --git a/toolsrc/src/commands_owns.cpp b/toolsrc/src/commands_owns.cpp
index 36e853a58..b3dab2e44 100644
--- a/toolsrc/src/commands_owns.cpp
+++ b/toolsrc/src/commands_owns.cpp
@@ -6,13 +6,9 @@ namespace vcpkg
{
void owns_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths)
{
- args.check_max_arg_count(1);
- if (args.command_arguments.size() == 0)
- {
- System::println(System::color::error, "Error: owns requires a pattern to search for as the first argument.");
- print_example("owns .dll");
- exit(EXIT_FAILURE);
- }
+ static const std::string example = Strings::format("The argument should be a pattern to search for. %s", create_example_string("owns zlib.dll"));
+ args.check_exact_arg_count(1, example.c_str());
+
StatusParagraphs status_db = database_load_check(paths);
search_file(paths, args.command_arguments[0], status_db);
exit(EXIT_SUCCESS);
diff --git a/toolsrc/src/commands_remove.cpp b/toolsrc/src/commands_remove.cpp
index f5315ccb1..c2d6cced3 100644
--- a/toolsrc/src/commands_remove.cpp
+++ b/toolsrc/src/commands_remove.cpp
@@ -22,6 +22,9 @@ namespace vcpkg
void remove_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet)
{
+ static const std::string example = create_example_string("remove zlib zlib:x64-windows curl boost");
+ args.check_min_arg_count(1, example.c_str());
+
const std::unordered_set<std::string> options = args.check_and_get_optional_command_arguments({OPTION_PURGE});
auto status_db = database_load_check(paths);
diff --git a/toolsrc/src/commands_search.cpp b/toolsrc/src/commands_search.cpp
index 3cd6d2ff7..36926764b 100644
--- a/toolsrc/src/commands_search.cpp
+++ b/toolsrc/src/commands_search.cpp
@@ -38,7 +38,9 @@ namespace vcpkg
void search_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths)
{
- args.check_max_arg_count(1);
+ static const std::string example = Strings::format("The argument should be a substring to search for, or no argument to display all libraries.\n%s", create_example_string("search png"));
+ args.check_max_arg_count(1, example.c_str());
+
if (args.command_arguments.size() == 0)
{
do_print(paths, [](std::string&) -> bool
diff --git a/toolsrc/src/commands_update.cpp b/toolsrc/src/commands_update.cpp
index 3cd7af027..b34530f40 100644
--- a/toolsrc/src/commands_update.cpp
+++ b/toolsrc/src/commands_update.cpp
@@ -5,8 +5,9 @@
namespace vcpkg
{
- void update_command(const vcpkg_cmd_arguments& /*args*/, const vcpkg_paths& paths)
+ void update_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths)
{
+ args.check_exact_arg_count(0);
System::println("Using local portfile versions. To update the local portfiles, use `git pull`.");
auto status_db = database_load_check(paths);