diff options
| author | Rob Mensching <rob@firegiant.com> | 2018-10-24 15:03:23 -0700 |
|---|---|---|
| committer | Rob Mensching <rob@robmensching.com> | 2018-10-24 21:11:31 -0700 |
| commit | b86e235ef4f9423624fc93e1c417484e938245df (patch) | |
| tree | b8cb21285a24334aa236bd294b5b3ddf573503b2 /src | |
| parent | 780fd42d094e7d9f020bf08b4be55b150b9957e4 (diff) | |
| download | wix-b86e235ef4f9423624fc93e1c417484e938245df.tar.gz wix-b86e235ef4f9423624fc93e1c417484e938245df.tar.bz2 wix-b86e235ef4f9423624fc93e1c417484e938245df.zip | |
Re-organize command-line processing and add support for custom commands
Diffstat (limited to 'src')
7 files changed, 87 insertions, 42 deletions
diff --git a/src/WixToolset.Extensibility/BaseExtensionCommandLine.cs b/src/WixToolset.Extensibility/BaseExtensionCommandLine.cs new file mode 100644 index 00000000..77e8a5bd --- /dev/null +++ b/src/WixToolset.Extensibility/BaseExtensionCommandLine.cs | |||
| @@ -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 | } | ||
diff --git a/src/WixToolset.Extensibility/Data/ICommandLineArguments.cs b/src/WixToolset.Extensibility/Data/ICommandLineArguments.cs index 5729ff36..dfa81762 100644 --- a/src/WixToolset.Extensibility/Data/ICommandLineArguments.cs +++ b/src/WixToolset.Extensibility/Data/ICommandLineArguments.cs | |||
| @@ -18,6 +18,6 @@ namespace WixToolset.Extensibility.Data | |||
| 18 | 18 | ||
| 19 | void Populate(string[] args); | 19 | void Populate(string[] args); |
| 20 | 20 | ||
| 21 | IParseCommandLine Parse(); | 21 | ICommandLineParser Parse(); |
| 22 | } | 22 | } |
| 23 | } | 23 | } |
diff --git a/src/WixToolset.Extensibility/Data/ICommandLineCommand.cs b/src/WixToolset.Extensibility/Data/ICommandLineCommand.cs index 1146d40a..1c6de205 100644 --- a/src/WixToolset.Extensibility/Data/ICommandLineCommand.cs +++ b/src/WixToolset.Extensibility/Data/ICommandLineCommand.cs | |||
| @@ -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 | 2 | ||
| 3 | namespace WixToolset.Extensibility.Data | 3 | namespace WixToolset.Extensibility.Data |
| 4 | { | 4 | { |
| 5 | using WixToolset.Extensibility.Services; | ||
| 6 | |||
| 5 | public interface ICommandLineCommand | 7 | public interface ICommandLineCommand |
| 6 | { | 8 | { |
| 9 | bool ShowLogo { get; } | ||
| 10 | |||
| 11 | bool StopParsing { get; } | ||
| 12 | |||
| 7 | int Execute(); | 13 | int Execute(); |
| 14 | |||
| 15 | bool TryParseArgument(ICommandLineParser parser, string argument); | ||
| 8 | } | 16 | } |
| 9 | } | 17 | } |
diff --git a/src/WixToolset.Extensibility/IExtensionCommandLine.cs b/src/WixToolset.Extensibility/IExtensionCommandLine.cs index 5c6f578d..0cbf84d9 100644 --- a/src/WixToolset.Extensibility/IExtensionCommandLine.cs +++ b/src/WixToolset.Extensibility/IExtensionCommandLine.cs | |||
| @@ -19,7 +19,9 @@ namespace WixToolset.Extensibility | |||
| 19 | 19 | ||
| 20 | void PreParse(ICommandLineContext context); | 20 | void PreParse(ICommandLineContext context); |
| 21 | 21 | ||
| 22 | bool TryParseArgument(IParseCommandLine parseCommandLine, string arg); | 22 | bool TryParseArgument(ICommandLineParser parser, string argument); |
| 23 | |||
| 24 | bool TryParseCommand(ICommandLineParser parser, out ICommandLineCommand command); | ||
| 23 | 25 | ||
| 24 | void PostParse(); | 26 | void PostParse(); |
| 25 | } | 27 | } |
diff --git a/src/WixToolset.Extensibility/Services/ICommandLine.cs b/src/WixToolset.Extensibility/Services/ICommandLine.cs new file mode 100644 index 00000000..48f3620f --- /dev/null +++ b/src/WixToolset.Extensibility/Services/ICommandLine.cs | |||
| @@ -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 | } | ||
diff --git a/src/WixToolset.Extensibility/Services/ICommandLineParser.cs b/src/WixToolset.Extensibility/Services/ICommandLineParser.cs index 60507c6c..f7e2a28f 100644 --- a/src/WixToolset.Extensibility/Services/ICommandLineParser.cs +++ b/src/WixToolset.Extensibility/Services/ICommandLineParser.cs | |||
| @@ -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 | 2 | ||
| 3 | namespace WixToolset.Extensibility.Services | 3 | namespace WixToolset.Extensibility.Services |
| 4 | { | 4 | { |
| 5 | using WixToolset.Extensibility.Data; | 5 | using System.Collections.Generic; |
| 6 | 6 | ||
| 7 | public interface ICommandLineParser | 7 | public interface ICommandLineParser |
| 8 | { | 8 | { |
| 9 | IExtensionManager ExtensionManager { get; set; } | 9 | string ErrorArgument { get; set; } |
| 10 | 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); | ||
| 12 | 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); | ||
| 14 | } | 35 | } |
| 15 | } | 36 | } |
diff --git a/src/WixToolset.Extensibility/Services/IParseCommandLine.cs b/src/WixToolset.Extensibility/Services/IParseCommandLine.cs deleted file mode 100644 index 3753b4f2..00000000 --- a/src/WixToolset.Extensibility/Services/IParseCommandLine.cs +++ /dev/null | |||
| @@ -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 | } | ||
