Commit e6b6bb06 authored by wahikihiki's avatar wahikihiki Committed by Kyle Edwards

cmInstallCommand: Port to cmArgumentParser

parent 4336a29e
This diff is collapsed.
......@@ -4,6 +4,7 @@
#include "cmRange.h"
#include "cmSystemTools.h"
#include "cm_static_string_view.hxx"
#include <utility>
......@@ -18,20 +19,19 @@ const std::string cmInstallCommandArguments::EmptyString;
cmInstallCommandArguments::cmInstallCommandArguments(
std::string defaultComponent)
: Destination(&Parser, "DESTINATION", &ArgumentGroup)
, Component(&Parser, "COMPONENT", &ArgumentGroup)
, NamelinkComponent(&Parser, "NAMELINK_COMPONENT", &ArgumentGroup)
, ExcludeFromAll(&Parser, "EXCLUDE_FROM_ALL", &ArgumentGroup)
, Rename(&Parser, "RENAME", &ArgumentGroup)
, Permissions(&Parser, "PERMISSIONS", &ArgumentGroup)
, Configurations(&Parser, "CONFIGURATIONS", &ArgumentGroup)
, Optional(&Parser, "OPTIONAL", &ArgumentGroup)
, NamelinkOnly(&Parser, "NAMELINK_ONLY", &ArgumentGroup)
, NamelinkSkip(&Parser, "NAMELINK_SKIP", &ArgumentGroup)
, Type(&Parser, "TYPE", &ArgumentGroup)
, GenericArguments(nullptr)
, DefaultComponentName(std::move(defaultComponent))
: DefaultComponentName(std::move(defaultComponent))
{
this->Bind("DESTINATION"_s, this->Destination);
this->Bind("COMPONENT"_s, this->Component);
this->Bind("NAMELINK_COMPONENT"_s, this->NamelinkComponent);
this->Bind("EXCLUDE_FROM_ALL"_s, this->ExcludeFromAll);
this->Bind("RENAME"_s, this->Rename);
this->Bind("PERMISSIONS"_s, this->Permissions);
this->Bind("CONFIGURATIONS"_s, this->Configurations);
this->Bind("OPTIONAL"_s, this->Optional);
this->Bind("NAMELINK_ONLY"_s, this->NamelinkOnly);
this->Bind("NAMELINK_SKIP"_s, this->NamelinkSkip);
this->Bind("TYPE"_s, this->Type);
}
const std::string& cmInstallCommandArguments::GetDestination() const
......@@ -47,8 +47,8 @@ const std::string& cmInstallCommandArguments::GetDestination() const
const std::string& cmInstallCommandArguments::GetComponent() const
{
if (!this->Component.GetString().empty()) {
return this->Component.GetString();
if (!this->Component.empty()) {
return this->Component;
}
if (this->GenericArguments != nullptr) {
return this->GenericArguments->GetComponent();
......@@ -62,16 +62,16 @@ const std::string& cmInstallCommandArguments::GetComponent() const
const std::string& cmInstallCommandArguments::GetNamelinkComponent() const
{
if (!this->NamelinkComponent.GetString().empty()) {
return this->NamelinkComponent.GetString();
if (!this->NamelinkComponent.empty()) {
return this->NamelinkComponent;
}
return this->GetComponent();
}
const std::string& cmInstallCommandArguments::GetRename() const
{
if (!this->Rename.GetString().empty()) {
return this->Rename.GetString();
if (!this->Rename.empty()) {
return this->Rename;
}
if (this->GenericArguments != nullptr) {
return this->GenericArguments->GetRename();
......@@ -92,7 +92,7 @@ const std::string& cmInstallCommandArguments::GetPermissions() const
bool cmInstallCommandArguments::GetOptional() const
{
if (this->Optional.IsEnabled()) {
if (this->Optional) {
return true;
}
if (this->GenericArguments != nullptr) {
......@@ -103,7 +103,7 @@ bool cmInstallCommandArguments::GetOptional() const
bool cmInstallCommandArguments::GetExcludeFromAll() const
{
if (this->ExcludeFromAll.IsEnabled()) {
if (this->ExcludeFromAll) {
return true;
}
if (this->GenericArguments != nullptr) {
......@@ -114,7 +114,7 @@ bool cmInstallCommandArguments::GetExcludeFromAll() const
bool cmInstallCommandArguments::GetNamelinkOnly() const
{
if (this->NamelinkOnly.IsEnabled()) {
if (this->NamelinkOnly) {
return true;
}
if (this->GenericArguments != nullptr) {
......@@ -125,7 +125,7 @@ bool cmInstallCommandArguments::GetNamelinkOnly() const
bool cmInstallCommandArguments::GetNamelinkSkip() const
{
if (this->NamelinkSkip.IsEnabled()) {
if (this->NamelinkSkip) {
return true;
}
if (this->GenericArguments != nullptr) {
......@@ -136,7 +136,7 @@ bool cmInstallCommandArguments::GetNamelinkSkip() const
bool cmInstallCommandArguments::HasNamelinkComponent() const
{
if (!this->NamelinkComponent.GetString().empty()) {
if (!this->NamelinkComponent.empty()) {
return true;
}
if (this->GenericArguments != nullptr) {
......@@ -147,19 +147,19 @@ bool cmInstallCommandArguments::HasNamelinkComponent() const
const std::string& cmInstallCommandArguments::GetType() const
{
return this->Type.GetString();
return this->Type;
}
const std::vector<std::string>& cmInstallCommandArguments::GetConfigurations()
const
{
if (!this->Configurations.GetVector().empty()) {
return this->Configurations.GetVector();
if (!this->Configurations.empty()) {
return this->Configurations;
}
if (this->GenericArguments != nullptr) {
return this->GenericArguments->GetConfigurations();
}
return this->Configurations.GetVector();
return this->Configurations;
}
bool cmInstallCommandArguments::Finalize()
......@@ -167,21 +167,15 @@ bool cmInstallCommandArguments::Finalize()
if (!this->CheckPermissions()) {
return false;
}
this->DestinationString = this->Destination.GetString();
this->DestinationString = this->Destination;
cmSystemTools::ConvertToUnixSlashes(this->DestinationString);
return true;
}
void cmInstallCommandArguments::Parse(const std::vector<std::string>* args,
std::vector<std::string>* unconsumedArgs)
{
this->Parser.Parse(args, unconsumedArgs);
}
bool cmInstallCommandArguments::CheckPermissions()
{
this->PermissionsString.clear();
for (std::string const& perm : this->Permissions.GetVector()) {
for (std::string const& perm : this->Permissions) {
if (!cmInstallCommandArguments::CheckPermissions(
perm, this->PermissionsString)) {
return false;
......
......@@ -8,9 +8,9 @@
#include <string>
#include <vector>
#include "cmCommandArgumentsHelper.h"
#include "cmArgumentParser.h"
class cmInstallCommandArguments
class cmInstallCommandArguments : public cmArgumentParser<void>
{
public:
cmInstallCommandArguments(std::string defaultComponent);
......@@ -18,8 +18,6 @@ public:
{
this->GenericArguments = args;
}
void Parse(const std::vector<std::string>* args,
std::vector<std::string>* unconsumedArgs);
// Compute destination path.and check permissions
bool Finalize();
......@@ -37,30 +35,25 @@ public:
bool HasNamelinkComponent() const;
const std::string& GetType() const;
// once HandleDirectoryMode() is also switched to using
// cmInstallCommandArguments then these two functions can become non-static
// private member functions without arguments
static bool CheckPermissions(const std::string& onePerm, std::string& perm);
cmCommandArgumentsHelper Parser;
cmCommandArgumentGroup ArgumentGroup;
private:
cmCAString Destination;
cmCAString Component;
cmCAString NamelinkComponent;
cmCAEnabler ExcludeFromAll;
cmCAString Rename;
cmCAStringVector Permissions;
cmCAStringVector Configurations;
cmCAEnabler Optional;
cmCAEnabler NamelinkOnly;
cmCAEnabler NamelinkSkip;
cmCAString Type;
std::string Destination;
std::string Component;
std::string NamelinkComponent;
bool ExcludeFromAll = false;
std::string Rename;
std::vector<std::string> Permissions;
std::vector<std::string> Configurations;
bool Optional = false;
bool NamelinkOnly = false;
bool NamelinkSkip = false;
std::string Type;
std::string DestinationString;
std::string PermissionsString;
cmInstallCommandArguments* GenericArguments;
cmInstallCommandArguments* GenericArguments = nullptr;
static const char* PermissionsTable[];
static const std::string EmptyString;
std::string DefaultComponentName;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment