|
4 | 4 | using System.Collections.Generic; |
5 | 5 | using System.CommandLine.Parsing; |
6 | 6 | using System.Diagnostics.CodeAnalysis; |
7 | | -using System.IO; |
8 | | - |
9 | 7 | namespace System.CommandLine |
10 | 8 | { |
11 | 9 | /// <inheritdoc cref="Argument" /> |
@@ -84,85 +82,6 @@ public Argument(string name) : base(name) |
84 | 82 | return DefaultValueFactory.Invoke(argumentResult); |
85 | 83 | } |
86 | 84 |
|
87 | | - /// <summary> |
88 | | - /// Configures the argument to accept only the specified values, and to suggest them as command line completions. |
89 | | - /// </summary> |
90 | | - /// <param name="values">The values that are allowed for the argument.</param> |
91 | | - public void AcceptOnlyFromAmong(params string[] values) |
92 | | - { |
93 | | - if (values is not null && values.Length > 0) |
94 | | - { |
95 | | - Validators.Clear(); |
96 | | - Validators.Add(UnrecognizedArgumentError); |
97 | | - CompletionSources.Clear(); |
98 | | - CompletionSources.Add(values); |
99 | | - } |
100 | | - |
101 | | - void UnrecognizedArgumentError(ArgumentResult argumentResult) |
102 | | - { |
103 | | - for (var i = 0; i < argumentResult.Tokens.Count; i++) |
104 | | - { |
105 | | - var token = argumentResult.Tokens[i]; |
106 | | - |
107 | | - if (token.Symbol is null || token.Symbol == this) |
108 | | - { |
109 | | - if (Array.IndexOf(values, token.Value) < 0) |
110 | | - { |
111 | | - argumentResult.AddError(LocalizationResources.UnrecognizedArgument(token.Value, values)); |
112 | | - } |
113 | | - } |
114 | | - } |
115 | | - } |
116 | | - } |
117 | | - |
118 | | - /// <summary> |
119 | | - /// Configures the argument to accept only values representing legal file paths. |
120 | | - /// </summary> |
121 | | - public void AcceptLegalFilePathsOnly() |
122 | | - { |
123 | | - Validators.Add(static result => |
124 | | - { |
125 | | - var invalidPathChars = Path.GetInvalidPathChars(); |
126 | | - |
127 | | - for (var i = 0; i < result.Tokens.Count; i++) |
128 | | - { |
129 | | - var token = result.Tokens[i]; |
130 | | - |
131 | | - // File class no longer check invalid character |
132 | | - // https://blogs.msdn.microsoft.com/jeremykuhne/2018/03/09/custom-directory-enumeration-in-net-core-2-1/ |
133 | | - var invalidCharactersIndex = token.Value.IndexOfAny(invalidPathChars); |
134 | | - |
135 | | - if (invalidCharactersIndex >= 0) |
136 | | - { |
137 | | - result.AddError(LocalizationResources.InvalidCharactersInPath(token.Value[invalidCharactersIndex])); |
138 | | - } |
139 | | - } |
140 | | - }); |
141 | | - } |
142 | | - |
143 | | - /// <summary> |
144 | | - /// Configures the argument to accept only values representing legal file names. |
145 | | - /// </summary> |
146 | | - /// <remarks>A parse error will result, for example, if file path separators are found in the parsed value.</remarks> |
147 | | - public void AcceptLegalFileNamesOnly() |
148 | | - { |
149 | | - Validators.Add(static result => |
150 | | - { |
151 | | - var invalidFileNameChars = Path.GetInvalidFileNameChars(); |
152 | | - |
153 | | - for (var i = 0; i < result.Tokens.Count; i++) |
154 | | - { |
155 | | - var token = result.Tokens[i]; |
156 | | - var invalidCharactersIndex = token.Value.IndexOfAny(invalidFileNameChars); |
157 | | - |
158 | | - if (invalidCharactersIndex >= 0) |
159 | | - { |
160 | | - result.AddError(LocalizationResources.InvalidCharactersInFileName(token.Value[invalidCharactersIndex])); |
161 | | - } |
162 | | - } |
163 | | - }); |
164 | | - } |
165 | | - |
166 | 85 | [UnconditionalSuppressMessage("ReflectionAnalysis", "IL3050", Justification = "https://github.com/dotnet/command-line-api/issues/1638")] |
167 | 86 | [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2091", Justification = "https://github.com/dotnet/command-line-api/issues/1638")] |
168 | 87 | internal static T? CreateDefaultValue() |
|
0 commit comments