[vcpkg_cmd_arguments] Use std::string instead of char*

This commit is contained in:
Alexander Karatarakis 2016-12-12 15:03:36 -08:00
parent d02fe9bdae
commit b629cd9044
14 changed files with 23 additions and 23 deletions

View File

@ -24,11 +24,11 @@ namespace vcpkg
std::unordered_set<std::string> check_and_get_optional_command_arguments(const std::vector<std::string>& valid_options) 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_max_arg_count(const size_t expected_arg_count, const std::string& 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_min_arg_count(const size_t expected_arg_count, const std::string& 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;
void check_exact_arg_count(const size_t expected_arg_count, const std::string& example_text) const;
private:
std::unordered_set<std::string> optional_command_arguments;

View File

@ -38,7 +38,7 @@ namespace vcpkg
{
static const std::string example = Strings::format(
"The argument should be a substring to search for, or no argument to display all cached libraries.\n%s", create_example_string("cache png"));
args.check_max_arg_count(1, example.c_str());
args.check_max_arg_count(1, example);
const std::vector<BinaryParagraph> binary_paragraphs = read_all_binary_paragraphs(paths);
if (binary_paragraphs.empty())

View File

@ -9,8 +9,8 @@ namespace vcpkg
void create_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths)
{
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());
args.check_max_arg_count(3, example);
args.check_min_arg_count(2, example);
const std::string port_name = args.command_arguments.at(0);
Environment::ensure_utilities_on_path(paths);

View File

@ -7,7 +7,7 @@ namespace vcpkg
void edit_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths)
{
static const std::string example = create_example_string("edit zlib");
args.check_exact_arg_count(1, example.c_str());
args.check_exact_arg_count(1, example);
const std::string port_name = args.command_arguments.at(0);
const fs::path portpath = paths.ports / port_name;

View File

@ -27,8 +27,8 @@ namespace vcpkg
{
static const std::string example = Strings::format(
"The argument should be a file path\n%s", create_example_string("hash boost_1_62_0.tar.bz2"));
args.check_min_arg_count(1, example.c_str());
args.check_max_arg_count(2, example.c_str());
args.check_min_arg_count(1, example);
args.check_max_arg_count(2, example);
if (args.command_arguments.size() == 1)
{

View File

@ -78,7 +78,7 @@ namespace vcpkg
void import_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths)
{
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());
args.check_exact_arg_count(3, example);
const fs::path control_file_path(args.command_arguments[0]);
const fs::path include_directory(args.command_arguments[1]);

View File

@ -216,7 +216,7 @@ 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());
args.check_min_arg_count(1, example);
StatusParagraphs status_db = database_load_check(paths);
std::vector<package_spec> specs = Input::check_and_get_package_specs(args.command_arguments, default_target_triplet, example.c_str());
@ -276,7 +276,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_exact_arg_count(1, example.c_str());
args.check_exact_arg_count(1, example);
StatusParagraphs status_db = database_load_check(paths);
@ -332,7 +332,7 @@ namespace vcpkg
void build_external_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet)
{
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());
args.check_exact_arg_count(2, example);
expected<package_spec> maybe_current_spec = package_spec::from_string(args.command_arguments[0], default_target_triplet);
if (auto spec = maybe_current_spec.get())

View File

@ -297,7 +297,7 @@ With a project open, go to Tools->NuGet Package Manager->Package Manager Console
{
static const std::string example = Strings::format("Commands:\n"
"%s", INTEGRATE_COMMAND_HELPSTRING);
args.check_exact_arg_count(1, example.c_str());
args.check_exact_arg_count(1, example);
if (args.command_arguments[0] == "install")
{

View File

@ -17,7 +17,7 @@ namespace vcpkg
{
static const std::string example = Strings::format(
"The argument should be a substring to search for, or no argument to display all installed libraries.\n%s", create_example_string("list png"));
args.check_max_arg_count(1, example.c_str());
args.check_max_arg_count(1, example);
const StatusParagraphs status_paragraphs = database_load_check(paths);
std::vector<StatusParagraph> installed_packages;

View File

@ -24,7 +24,7 @@ namespace vcpkg
void owns_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths)
{
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());
args.check_exact_arg_count(1, example);
StatusParagraphs status_db = database_load_check(paths);
search_file(paths, args.command_arguments[0], status_db);

View File

@ -100,8 +100,8 @@ namespace vcpkg
void portsdiff_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths)
{
static const std::string example = Strings::format("The argument should be a branch/tag/hash to checkout.\n%s", create_example_string("portsdiff mybranchname"));
args.check_min_arg_count(1, example.c_str());
args.check_max_arg_count(2, example.c_str());
args.check_min_arg_count(1, example);
args.check_max_arg_count(2, example);
Environment::ensure_git_on_path(paths);
const std::wstring git_commit_id_for_previous_snapshot = Strings::utf8_to_utf16(args.command_arguments.at(0));

View File

@ -169,7 +169,7 @@ 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());
args.check_min_arg_count(1, example);
const std::unordered_set<std::string> options = args.check_and_get_optional_command_arguments({OPTION_PURGE});
auto status_db = database_load_check(paths);

View File

@ -43,7 +43,7 @@ namespace vcpkg
void search_command(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths)
{
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());
args.check_max_arg_count(1, example);
const std::vector<SourceParagraph> source_paragraphs = read_all_source_paragraphs(paths);

View File

@ -179,7 +179,7 @@ namespace vcpkg
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
void vcpkg_cmd_arguments::check_max_arg_count(const size_t expected_arg_count, const std::string& example_text) const
{
const size_t actual_arg_count = command_arguments.size();
if (actual_arg_count > expected_arg_count)
@ -190,7 +190,7 @@ namespace vcpkg
}
}
void vcpkg_cmd_arguments::check_min_arg_count(const size_t expected_arg_count, const char* example_text) const
void vcpkg_cmd_arguments::check_min_arg_count(const size_t expected_arg_count, const std::string& example_text) const
{
const size_t actual_arg_count = command_arguments.size();
if (actual_arg_count < expected_arg_count)
@ -201,7 +201,7 @@ namespace vcpkg
}
}
void vcpkg_cmd_arguments::check_exact_arg_count(const size_t expected_arg_count, const char* example_text) const
void vcpkg_cmd_arguments::check_exact_arg_count(const size_t expected_arg_count, const std::string& example_text) const
{
const size_t actual_arg_count = command_arguments.size();
if (actual_arg_count != expected_arg_count)