-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathInstallPkgParams.cs
More file actions
132 lines (113 loc) · 4.95 KB
/
InstallPkgParams.cs
File metadata and controls
132 lines (113 loc) · 4.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using Microsoft.PowerShell.PSResourceGet.UtilClasses;
using NuGet.Versioning;
using System;
using System.Management.Automation;
public class InstallPkgParams
{
public string Name { get; set; }
public VersionRange Version { get; set; }
public string Repository { get; set; }
public bool? AcceptLicense { get; set; }
public bool Prerelease { get; set; }
public ScopeType? Scope { get; set; }
public bool? Quiet { get; set; }
public bool? Reinstall { get; set; }
public bool Force { get; set; }
public bool? TrustRepository { get; set; }
public bool? NoClobber { get; set; }
public bool? SkipDependencyCheck { get; set; }
#region Private methods
public void SetProperty(string propertyName, string propertyValue, out ErrorRecord ParameterParsingError)
{
ParameterParsingError = null;
if (String.IsNullOrEmpty(propertyName.Trim()))
{
ParameterParsingError = new ErrorRecord(
new ArgumentException("Argument for parameter cannot be null or whitespace."),
"EmptyOrWhitespaceParameterKey",
ErrorCategory.InvalidArgument,
this);
}
switch (propertyName.ToLower())
{
case "name":
Name = propertyValue.Trim();
break;
case "version":
// If no Version specified, install latest version for the package.
// Otherwise validate Version can be parsed out successfully.
VersionRange versionTmp = VersionRange.None;
if (string.IsNullOrWhiteSpace(propertyValue))
{
Version = VersionRange.All;
}
else if (!Utils.TryParseVersionOrVersionRange(propertyValue, out versionTmp))
{
ParameterParsingError = new ErrorRecord(
new ArgumentException("Argument for Version parameter is not in the proper format."),
"IncorrectVersionFormat",
ErrorCategory.InvalidArgument,
this);
}
Version = versionTmp;
break;
case "repository":
Repository = propertyValue.Trim();
break;
case "acceptlicense":
if (!string.IsNullOrWhiteSpace(propertyValue) && bool.TryParse(propertyValue, out bool acceptLicenseTmp))
{
AcceptLicense = acceptLicenseTmp;
}
break;
case "prerelease":
bool.TryParse(propertyValue, out bool prereleaseTmp);
Prerelease = prereleaseTmp;
break;
case "scope":
ScopeType scope = (ScopeType)Enum.Parse(typeof(ScopeType), propertyValue, ignoreCase: true);
Scope = scope;
break;
case "quiet":
if (!string.IsNullOrWhiteSpace(propertyValue) && bool.TryParse(propertyValue, out bool quietTmp))
{
Quiet = quietTmp;
}
break;
case "reinstall":
if (!string.IsNullOrWhiteSpace(propertyValue) && bool.TryParse(propertyValue, out bool reinstallTmp))
{
Reinstall = reinstallTmp;
}
break;
case "trustrepository":
if (!string.IsNullOrWhiteSpace(propertyValue) && bool.TryParse(propertyValue, out bool trustRepositoryTmp))
{
TrustRepository = trustRepositoryTmp;
}
break;
case "noclobber":
if (!string.IsNullOrWhiteSpace(propertyValue) && bool.TryParse(propertyValue, out bool noClobberTmp))
{
NoClobber = noClobberTmp;
}
break;
case "skipdependencycheck":
if (!string.IsNullOrWhiteSpace(propertyValue) && bool.TryParse(propertyValue, out bool skipDependencyCheckTmp))
{
SkipDependencyCheck = skipDependencyCheckTmp;
}
break;
default:
ParameterParsingError = new ErrorRecord(
new ArgumentException($"The parameter '{propertyName}' provided is not a recognized or valid parameter. Allowed values include: Name, Version, Repository, AcceptLicense, Prerelease, Scope, Quiet, Reinstall, TrustRepository, NoClobber, and SkipDependencyCheck."),
"IncorrectParameterError",
ErrorCategory.InvalidArgument,
this);
break;
}
}
#endregion
}