зеркало из https://github.com/microsoft/vcpkg.git
Rename check_max_args to check_max_arg_count and introduce min/exact variants
This commit is contained in:
Родитель
0fdd57983a
Коммит
fc1e55173b
|
@ -26,7 +26,13 @@ namespace vcpkg
|
|||
std::vector<std::string> command_arguments;
|
||||
std::unordered_set<std::string> check_and_get_optional_command_arguments(const std::vector<std::string>& valid_options) const;
|
||||
|
||||
void check_max_args(size_t arg_count, const char* example_text = nullptr) const;
|
||||
void check_max_arg_count(const size_t expected_arg_count) const;
|
||||
void check_max_arg_count(const size_t expected_arg_count, const char* example_text) const;
|
||||
void check_min_arg_count(const size_t expected_arg_count) const;
|
||||
void check_min_arg_count(const size_t expected_arg_count, const char* example_text) const;
|
||||
void check_exact_arg_count(const size_t expected_arg_count) const;
|
||||
void check_exact_arg_count(const size_t expected_arg_count, const char* example_text) const;
|
||||
|
||||
std::vector<package_spec> parse_all_arguments_as_package_specs(const triplet& default_target_triplet, const char* example_text = nullptr) const;
|
||||
|
||||
private:
|
||||
|
|
|
@ -7,7 +7,7 @@ namespace vcpkg
|
|||
{
|
||||
void cache_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths)
|
||||
{
|
||||
args.check_max_args(0);
|
||||
args.check_exact_arg_count(0);
|
||||
|
||||
auto begin_it = fs::directory_iterator(paths.packages);
|
||||
auto end_it = fs::directory_iterator();
|
||||
|
|
|
@ -7,7 +7,7 @@ namespace vcpkg
|
|||
{
|
||||
void create_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet)
|
||||
{
|
||||
args.check_max_args(3);
|
||||
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.");
|
||||
|
|
|
@ -5,8 +5,8 @@ namespace vcpkg
|
|||
{
|
||||
void edit_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet)
|
||||
{
|
||||
static auto example = "edit zlib";
|
||||
args.check_max_args(1, example);
|
||||
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);
|
||||
|
||||
// Find editor
|
||||
|
|
|
@ -6,7 +6,7 @@ namespace vcpkg
|
|||
{
|
||||
void version_command(const vcpkg_cmd_arguments& args)
|
||||
{
|
||||
args.check_max_args(0);
|
||||
args.check_max_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"
|
||||
|
@ -17,7 +17,7 @@ namespace vcpkg
|
|||
|
||||
void help_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths)
|
||||
{
|
||||
args.check_max_args(1);
|
||||
args.check_max_arg_count(1);
|
||||
if (args.command_arguments.empty())
|
||||
{
|
||||
print_usage();
|
||||
|
|
|
@ -122,7 +122,7 @@ namespace vcpkg
|
|||
{
|
||||
// Installing multiple packages leads to unintuitive behavior if one of them depends on another.
|
||||
// Allowing only 1 package for now.
|
||||
args.check_max_args(1);
|
||||
args.check_max_arg_count(1);
|
||||
|
||||
StatusParagraphs status_db = database_load_check(paths);
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ namespace vcpkg
|
|||
{
|
||||
void list_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths)
|
||||
{
|
||||
args.check_max_args(0);
|
||||
args.check_max_arg_count(0);
|
||||
|
||||
std::vector<std::string> packages_output;
|
||||
for (auto&& pgh : database_load_check(paths))
|
||||
|
|
|
@ -6,7 +6,7 @@ namespace vcpkg
|
|||
{
|
||||
void owns_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths)
|
||||
{
|
||||
args.check_max_args(1);
|
||||
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.");
|
||||
|
|
|
@ -38,7 +38,7 @@ namespace vcpkg
|
|||
|
||||
void search_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths)
|
||||
{
|
||||
args.check_max_args(1);
|
||||
args.check_max_arg_count(1);
|
||||
if (args.command_arguments.size() == 0)
|
||||
{
|
||||
do_print(paths, [](std::string&) -> bool
|
||||
|
|
|
@ -166,15 +166,50 @@ namespace vcpkg
|
|||
return output;
|
||||
}
|
||||
|
||||
void vcpkg_cmd_arguments::check_max_args(size_t arg_count, const char* example_text) const
|
||||
void vcpkg_cmd_arguments::check_max_arg_count(const size_t expected_arg_count) const
|
||||
{
|
||||
if (command_arguments.size() > arg_count)
|
||||
return check_max_arg_count(expected_arg_count, "");
|
||||
}
|
||||
|
||||
void vcpkg_cmd_arguments::check_min_arg_count(const size_t expected_arg_count) const
|
||||
{
|
||||
return check_min_arg_count(expected_arg_count, "");
|
||||
}
|
||||
|
||||
void vcpkg_cmd_arguments::check_exact_arg_count(const size_t expected_arg_count) const
|
||||
{
|
||||
return check_exact_arg_count(expected_arg_count, "");
|
||||
}
|
||||
|
||||
void vcpkg_cmd_arguments::check_max_arg_count(const size_t expected_arg_count, const char* example_text) const
|
||||
{
|
||||
const size_t actual_arg_count = command_arguments.size();
|
||||
if (actual_arg_count > expected_arg_count)
|
||||
{
|
||||
System::println(System::color::error, "Error: too many arguments to command %s", command);
|
||||
if (example_text != nullptr)
|
||||
print_example(example_text);
|
||||
else
|
||||
print_usage();
|
||||
System::println(System::color::error, "Error: %s requires at most %u arguments, but %u were provided", this->command, expected_arg_count, actual_arg_count);
|
||||
System::print(example_text);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
void vcpkg_cmd_arguments::check_min_arg_count(const size_t expected_arg_count, const char* example_text) const
|
||||
{
|
||||
const size_t actual_arg_count = command_arguments.size();
|
||||
if (actual_arg_count < expected_arg_count)
|
||||
{
|
||||
System::println(System::color::error, "Error: %s requires at least %u arguments, but %u were provided", this->command, expected_arg_count, actual_arg_count);
|
||||
System::print(example_text);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
void vcpkg_cmd_arguments::check_exact_arg_count(const size_t expected_arg_count, const char* example_text) const
|
||||
{
|
||||
const size_t actual_arg_count = command_arguments.size();
|
||||
if (actual_arg_count != expected_arg_count)
|
||||
{
|
||||
System::println(System::color::error, "Error: %s requires %u arguments, but %u were provided", this->command, expected_arg_count, actual_arg_count);
|
||||
System::print(example_text);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче