|
2 | 2 | // The .NET Foundation licenses this file to you under the MIT license.
|
3 | 3 | // See the LICENSE file in the project root for more information.
|
4 | 4 |
|
| 5 | +using System; |
5 | 6 | using System.Collections.Generic;
|
6 | 7 | using System.CommandLine;
|
7 | 8 | using System.CommandLine.Builder;
|
8 | 9 | using System.CommandLine.Invocation;
|
9 | 10 | using System.IO;
|
| 11 | +using System.Linq; |
10 | 12 |
|
11 | 13 | namespace Microsoft.ML.CLI.Commands
|
12 | 14 | {
|
@@ -97,20 +99,47 @@ Option Name() =>
|
97 | 99 |
|
98 | 100 | Option OutputPath() =>
|
99 | 101 | new Option(new List<string>() { "--output-path" }, "Location folder to place the generated output. The default is the current directory.",
|
100 |
| - new Argument<DirectoryInfo>(defaultValue:new DirectoryInfo("."))); |
| 102 | + new Argument<DirectoryInfo>(defaultValue: new DirectoryInfo("."))); |
101 | 103 |
|
102 | 104 | Option HasHeader() =>
|
103 |
| - new Option(new List<string>() {"--has-header" }, "Specify true/false depending if the dataset file(s) have a header row.", |
| 105 | + new Option(new List<string>() { "--has-header" }, "Specify true/false depending if the dataset file(s) have a header row.", |
104 | 106 | new Argument<bool>(defaultValue: true));
|
105 | 107 |
|
106 | 108 | Option Cache() =>
|
107 | 109 | new Option(new List<string>() { "--cache" }, "Specify on/off/auto if you want cache to be turned on, off or auto determined.",
|
108 | 110 | new Argument<string>(defaultValue: "auto").FromAmong(GetCacheSuggestions()));
|
109 | 111 |
|
| 112 | + // This is a temporary hack to work around having comma separated values for argument. This feature needs to be enabled in the parser itself. |
110 | 113 | Option IgnoreColumns() =>
|
111 |
| - new Option(new List<string>() { "--ignore-columns" }, "Specify the columns that needs to be ignored in the given dataset.", |
112 |
| - new Argument<List<string>>(defaultValue: new List<string>())); |
113 |
| - |
| 114 | + new Option(new List<string>() { "--ignore-columns" }, "Specify the columns that needs to be ignored in the given dataset.", |
| 115 | + new Argument<List<string>>(symbolResult => |
| 116 | + { |
| 117 | + try |
| 118 | + { |
| 119 | + List<string> valuesList = new List<string>(); |
| 120 | + foreach (var argument in symbolResult.Arguments) |
| 121 | + { |
| 122 | + if (!string.IsNullOrWhiteSpace(argument)) |
| 123 | + { |
| 124 | + var values = argument.Split(",", StringSplitOptions.RemoveEmptyEntries); |
| 125 | + valuesList.AddRange(values); |
| 126 | + } |
| 127 | + } |
| 128 | + if (valuesList.Count > 0) |
| 129 | + return ArgumentResult.Success(valuesList); |
| 130 | + |
| 131 | + } |
| 132 | + catch (Exception) |
| 133 | + { |
| 134 | + return ArgumentResult.Failure($"Unknown exception occured while parsing argument for --ignore-columns :{string.Join(' ', symbolResult.Arguments.ToArray())}"); |
| 135 | + } |
| 136 | + |
| 137 | + //This shouldn't be hit. |
| 138 | + return ArgumentResult.Failure($"Unknown error while parsing argument for --ignore-columns"); |
| 139 | + }) |
| 140 | + { |
| 141 | + Arity = ArgumentArity.OneOrMore |
| 142 | + }); |
114 | 143 | }
|
115 | 144 |
|
116 | 145 | private static string[] GetMlTaskSuggestions()
|
|
0 commit comments