Improve command line processing interfaces for extensions
Partial fix for wixtoolset/issues#5845
Rob Mensching committed
Jul 12, 2018 at 21:15 UTC
ce026a4a61336aec750510f501e943027e033934
3 files changed
+42
-8
src/WixToolset.Extensibility/Services/ICommandLineArguments.cs
new
+23
@@ -0,0 +1,23 @@
1
+// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
+
3
+namespace WixToolset.Extensibility.Services
4
+{
5
+ using System.Collections.Generic;
6
+
7
+ public interface ICommandLineArguments
8
+ {
9
+ string[] OriginalArguments { get; set; }
10
+
11
+ string[] Arguments { get; set; }
12
+
13
+ string[] Extensions { get; set; }
14
+
15
+ string ErrorArgument { get; set; }
16
+
17
+ void Populate(string commandLine);
18
+
19
+ void Populate(string[] args);
20
+
21
+ IParseCommandLine Parse();
22
+ }
23
+}
src/WixToolset.Extensibility/Services/ICommandLineContext.cs
+1
-3
@@ -12,8 +12,6 @@ namespace WixToolset.Extensibility.Services
12
13
IExtensionManager ExtensionManager { get; set; }
14
15
- string Arguments { get; set; }
16
-
17
- string[] ParsedArguments { get; set; }
15
+ ICommandLineArguments Arguments { get; set; }
16
}
17
}
src/WixToolset.Extensibility/Services/IParseCommandLine.cs
+18
-5
@@ -6,16 +6,29 @@ namespace WixToolset.Extensibility.Services
6
7
public interface IParseCommandLine
8
{
9
+ string ErrorArgument { get; set; }
10
+
11
+ /// <summary>
12
+ /// Validates that a valid switch (starts with "/" or "-"), and returns a bool indicating its validity
13
+ /// </summary>
14
+ /// <param name="arg">The string check.</param>
15
+ /// <returns>True if a valid switch, otherwise false.</returns>
16
bool IsSwitch(string arg);
17
11
- bool IsSwitchAt(IEnumerable<string> args, int index);
18
+ void GetArgumentAsFilePathOrError(string argument, string fileType, IList<string> paths);
19
+
20
+ string GetNextArgumentOrError(string commandLineSwitch);
21
+
22
+ bool GetNextArgumentOrError(string commandLineSwitch, IList<string> argument);
23
+
24
+ string GetNextArgumentAsDirectoryOrError(string commandLineSwitch);
25
13
- void GetNextArgumentOrError(ref string arg);
26
+ bool GetNextArgumentAsDirectoryOrError(string commandLineSwitch, IList<string> directories);
27
15
- void GetNextArgumentOrError(IList<string> args);
28
+ string GetNextArgumentAsFilePathOrError(string commandLineSwitch);
29
17
- void GetNextArgumentAsFilePathOrError(IList<string> args, string fileType);
30
+ bool GetNextArgumentAsFilePathOrError(string commandLineSwitch, string fileType, IList<string> paths);
31
19
- bool TryGetNextArgumentOrError(out string arg);
32
+ bool TryGetNextSwitchOrArgument(out string arg);
33
}
34
}