2016-09-18 20:50:08 -07:00
|
|
|
#pragma once
|
|
|
|
|
2017-10-13 18:37:41 -07:00
|
|
|
#include <vcpkg/base/optional.h>
|
2017-10-13 20:58:00 -07:00
|
|
|
#include <vcpkg/base/span.h>
|
2018-01-17 19:39:46 -08:00
|
|
|
#include <vcpkg/base/stringliteral.h>
|
2017-10-13 18:37:41 -07:00
|
|
|
|
2016-09-18 20:50:08 -07:00
|
|
|
#include <memory>
|
2017-07-26 13:54:28 -07:00
|
|
|
#include <unordered_map>
|
2016-09-18 20:50:08 -07:00
|
|
|
#include <unordered_set>
|
2017-04-27 17:56:06 -07:00
|
|
|
#include <vector>
|
2016-09-18 20:50:08 -07:00
|
|
|
|
|
|
|
namespace vcpkg
|
|
|
|
{
|
2017-07-26 13:54:28 -07:00
|
|
|
struct ParsedArguments
|
|
|
|
{
|
|
|
|
std::unordered_set<std::string> switches;
|
|
|
|
std::unordered_map<std::string, std::string> settings;
|
2019-06-21 23:50:05 -07:00
|
|
|
std::unordered_map<std::string, std::vector<std::string>> multisettings;
|
2017-07-26 13:54:28 -07:00
|
|
|
};
|
|
|
|
|
2017-11-02 15:20:42 -07:00
|
|
|
struct VcpkgPaths;
|
|
|
|
|
|
|
|
struct CommandSwitch
|
|
|
|
{
|
2018-01-17 19:39:46 -08:00
|
|
|
constexpr CommandSwitch(const StringLiteral& name, const StringLiteral& short_help_text)
|
|
|
|
: name(name), short_help_text(short_help_text)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
StringLiteral name;
|
|
|
|
StringLiteral short_help_text;
|
2017-11-02 15:20:42 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct CommandSetting
|
2016-09-18 20:50:08 -07:00
|
|
|
{
|
2018-01-17 19:39:46 -08:00
|
|
|
constexpr CommandSetting(const StringLiteral& name, const StringLiteral& short_help_text)
|
|
|
|
: name(name), short_help_text(short_help_text)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
StringLiteral name;
|
|
|
|
StringLiteral short_help_text;
|
2017-11-02 15:20:42 -07:00
|
|
|
};
|
|
|
|
|
2019-06-21 23:50:05 -07:00
|
|
|
struct CommandMultiSetting
|
|
|
|
{
|
|
|
|
constexpr CommandMultiSetting(const StringLiteral& name, const StringLiteral& short_help_text)
|
|
|
|
: name(name), short_help_text(short_help_text)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
StringLiteral name;
|
|
|
|
StringLiteral short_help_text;
|
|
|
|
};
|
|
|
|
|
2017-11-02 15:20:42 -07:00
|
|
|
struct CommandOptionsStructure
|
|
|
|
{
|
|
|
|
Span<const CommandSwitch> switches;
|
|
|
|
Span<const CommandSetting> settings;
|
2019-06-21 23:50:05 -07:00
|
|
|
Span<const CommandMultiSetting> multisettings;
|
2017-11-02 15:20:42 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct CommandStructure
|
|
|
|
{
|
|
|
|
std::string example_text;
|
|
|
|
|
|
|
|
size_t minimum_arity;
|
|
|
|
size_t maximum_arity;
|
|
|
|
|
|
|
|
CommandOptionsStructure options;
|
|
|
|
|
|
|
|
std::vector<std::string> (*valid_arguments)(const VcpkgPaths& paths);
|
|
|
|
};
|
|
|
|
|
2017-11-02 18:17:21 -07:00
|
|
|
void display_usage(const CommandStructure& command_structure);
|
|
|
|
|
2017-10-16 11:44:04 -07:00
|
|
|
#if defined(_WIN32)
|
2017-11-02 15:20:42 -07:00
|
|
|
using CommandLineCharType = wchar_t;
|
2017-10-16 11:44:04 -07:00
|
|
|
#else
|
2017-11-02 15:20:42 -07:00
|
|
|
using CommandLineCharType = char;
|
2017-10-16 11:44:04 -07:00
|
|
|
#endif
|
2017-11-02 15:20:42 -07:00
|
|
|
|
|
|
|
struct VcpkgCmdArguments
|
|
|
|
{
|
|
|
|
static VcpkgCmdArguments create_from_command_line(const int argc, const CommandLineCharType* const* const argv);
|
2017-04-03 16:00:17 -07:00
|
|
|
static VcpkgCmdArguments create_from_arg_sequence(const std::string* arg_begin, const std::string* arg_end);
|
2016-09-18 20:50:08 -07:00
|
|
|
|
|
|
|
std::unique_ptr<std::string> vcpkg_root_dir;
|
2017-04-10 13:01:43 -07:00
|
|
|
std::unique_ptr<std::string> triplet;
|
2019-06-21 23:50:05 -07:00
|
|
|
std::unique_ptr<std::vector<std::string>> overlay_ports;
|
2017-04-28 17:27:07 -07:00
|
|
|
Optional<bool> debug = nullopt;
|
|
|
|
Optional<bool> sendmetrics = nullopt;
|
|
|
|
Optional<bool> printmetrics = nullopt;
|
2016-09-18 20:50:08 -07:00
|
|
|
|
2018-02-26 18:22:17 -08:00
|
|
|
// feature flags
|
|
|
|
Optional<bool> featurepackages = nullopt;
|
2018-02-26 18:38:25 -08:00
|
|
|
Optional<bool> binarycaching = nullopt;
|
|
|
|
|
2016-09-18 20:50:08 -07:00
|
|
|
std::string command;
|
|
|
|
std::vector<std::string> command_arguments;
|
2017-07-26 13:54:28 -07:00
|
|
|
|
2017-11-02 15:20:42 -07:00
|
|
|
ParsedArguments parse_arguments(const CommandStructure& command_structure) const;
|
2016-09-30 11:24:04 -07:00
|
|
|
|
2016-09-18 20:50:08 -07:00
|
|
|
private:
|
2019-06-21 23:50:05 -07:00
|
|
|
std::unordered_map<std::string, Optional<std::vector<std::string>>> optional_command_arguments;
|
2016-09-18 20:50:08 -07:00
|
|
|
};
|
|
|
|
}
|