vcpkg/toolsrc/src/vcpkg_Input.cpp

38 lines
1.3 KiB
C++
Raw Normal View History

2017-01-28 04:49:09 +08:00
#include "pch.h"
2017-04-28 09:08:52 +08:00
2016-10-01 07:54:07 +08:00
#include "metrics.h"
#include "vcpkg_Commands.h"
2017-04-28 09:08:52 +08:00
#include "vcpkg_Input.h"
#include "vcpkg_System.h"
2017-01-06 06:14:11 +08:00
namespace vcpkg::Input
{
2017-04-28 09:08:52 +08:00
PackageSpec check_and_get_package_spec(const std::string& package_spec_as_string,
const Triplet& default_triplet,
CStringView example_text)
{
const std::string as_lowercase = Strings::ascii_to_lowercase(package_spec_as_string);
Expected<PackageSpec> expected_spec = PackageSpec::from_string(as_lowercase, default_triplet);
if (auto spec = expected_spec.get())
{
return *spec;
}
// Intentionally show the lowercased string
2017-04-04 07:31:00 +08:00
System::println(System::Color::error, "Error: %s: %s", expected_spec.error_code().message(), as_lowercase);
System::print(example_text);
Checks::exit_fail(VCPKG_LINE_INFO);
}
2017-04-04 07:29:11 +08:00
void check_triplet(const Triplet& t, const VcpkgPaths& paths)
2016-10-01 07:54:07 +08:00
{
if (!paths.is_valid_triplet(t))
{
System::println(System::Color::error, "Error: invalid triplet: %s", t);
Metrics::track_property("error", "invalid triplet: " + t.to_string());
Commands::Help::help_topic_valid_triplet(paths);
Checks::exit_fail(VCPKG_LINE_INFO);
2016-10-01 07:54:07 +08:00
}
}
2017-01-06 06:14:11 +08:00
}