@joebigelow / wix-1 / commits / b86e235e

Re-organize command-line processing and add support for custom commands

Rob Mensching committed Oct 24, 2018 at 15:03 UTC b86e235ef4f9423624fc93e1c417484e938245df
7 files changed +87 -42
src/WixToolset.Extensibility/BaseExtensionCommandLine.cs new
+33
@@ -0,0 +1,33 @@
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
4 +{
5 + using System.Collections.Generic;
6 + using System.Linq;
7 + using WixToolset.Extensibility.Data;
8 + using WixToolset.Extensibility.Services;
9 +
10 + public abstract class BaseExtensionCommandLine : IExtensionCommandLine
11 + {
12 + public IEnumerable<ExtensionCommandLineSwitch> CommandLineSwitches => Enumerable.Empty<ExtensionCommandLineSwitch>();
13 +
14 + public virtual void PostParse()
15 + {
16 + }
17 +
18 + public virtual void PreParse(ICommandLineContext context)
19 + {
20 + }
21 +
22 + public virtual bool TryParseArgument(ICommandLineParser parser, string argument)
23 + {
24 + return false;
25 + }
26 +
27 + public virtual bool TryParseCommand(ICommandLineParser parser, out ICommandLineCommand command)
28 + {
29 + command = null;
30 + return false;
31 + }
32 + }
33 +}
src/WixToolset.Extensibility/Data/ICommandLineArguments.cs
+1 -1
@@ -18,6 +18,6 @@ namespace WixToolset.Extensibility.Data
18
19 void Populate(string[] args);
20
21 - IParseCommandLine Parse();
21 + ICommandLineParser Parse();
22 }
23 }
src/WixToolset.Extensibility/Data/ICommandLineCommand.cs
+9 -1
@@ -1,9 +1,17 @@
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.
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.Data
4 {
5 + using WixToolset.Extensibility.Services;
6 +
7 public interface ICommandLineCommand
8 {
9 + bool ShowLogo { get; }
10 +
11 + bool StopParsing { get; }
12 +
13 int Execute();
14 +
15 + bool TryParseArgument(ICommandLineParser parser, string argument);
16 }
17 }
src/WixToolset.Extensibility/IExtensionCommandLine.cs
+3 -1
@@ -19,7 +19,9 @@ namespace WixToolset.Extensibility
19
20 void PreParse(ICommandLineContext context);
21
22 - bool TryParseArgument(IParseCommandLine parseCommandLine, string arg);
22 + bool TryParseArgument(ICommandLineParser parser, string argument);
23 +
24 + bool TryParseCommand(ICommandLineParser parser, out ICommandLineCommand command);
25
26 void PostParse();
27 }
src/WixToolset.Extensibility/Services/ICommandLine.cs new
+15
@@ -0,0 +1,15 @@
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 WixToolset.Extensibility.Data;
6 +
7 + public interface ICommandLine
8 + {
9 + IExtensionManager ExtensionManager { get; set; }
10 +
11 + ICommandLineArguments Arguments { get; set; }
12 +
13 + ICommandLineCommand ParseStandardCommandLine();
14 + }
15 +}
src/WixToolset.Extensibility/Services/ICommandLineParser.cs
+26 -5
@@ -1,15 +1,36 @@
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.
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 WixToolset.Extensibility.Data;
5 + using System.Collections.Generic;
6
7 public interface ICommandLineParser
8 {
9 - IExtensionManager ExtensionManager { get; set; }
9 + string ErrorArgument { get; set; }
10
11 - ICommandLineArguments Arguments { get; set; }
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
13 - ICommandLineCommand ParseStandardCommandLine();
18 + string GetArgumentAsFilePathOrError(string argument, string fileType);
19 +
20 + void GetArgumentAsFilePathOrError(string argument, string fileType, IList<string> paths);
21 +
22 + string GetNextArgumentOrError(string commandLineSwitch);
23 +
24 + bool GetNextArgumentOrError(string commandLineSwitch, IList<string> argument);
25 +
26 + string GetNextArgumentAsDirectoryOrError(string commandLineSwitch);
27 +
28 + bool GetNextArgumentAsDirectoryOrError(string commandLineSwitch, IList<string> directories);
29 +
30 + string GetNextArgumentAsFilePathOrError(string commandLineSwitch);
31 +
32 + bool GetNextArgumentAsFilePathOrError(string commandLineSwitch, string fileType, IList<string> paths);
33 +
34 + bool TryGetNextSwitchOrArgument(out string arg);
35 }
36 }
src/WixToolset.Extensibility/Services/IParseCommandLine.cs deleted
-34
@@ -1,34 +0,0 @@
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 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 -
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 -
26 - bool GetNextArgumentAsDirectoryOrError(string commandLineSwitch, IList<string> directories);
27 -
28 - string GetNextArgumentAsFilePathOrError(string commandLineSwitch);
29 -
30 - bool GetNextArgumentAsFilePathOrError(string commandLineSwitch, string fileType, IList<string> paths);
31 -
32 - bool TryGetNextSwitchOrArgument(out string arg);
33 - }
34 -}