From b86e235ef4f9423624fc93e1c417484e938245df Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Wed, 24 Oct 2018 15:03:23 -0700 Subject: Re-organize command-line processing and add support for custom commands --- .../BaseExtensionCommandLine.cs | 33 +++++++++++++++++++++ .../Data/ICommandLineArguments.cs | 2 +- .../Data/ICommandLineCommand.cs | 10 ++++++- .../IExtensionCommandLine.cs | 4 ++- .../Services/ICommandLine.cs | 15 ++++++++++ .../Services/ICommandLineParser.cs | 31 ++++++++++++++++---- .../Services/IParseCommandLine.cs | 34 ---------------------- 7 files changed, 87 insertions(+), 42 deletions(-) create mode 100644 src/WixToolset.Extensibility/BaseExtensionCommandLine.cs create mode 100644 src/WixToolset.Extensibility/Services/ICommandLine.cs delete mode 100644 src/WixToolset.Extensibility/Services/IParseCommandLine.cs (limited to 'src') 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 @@ +// 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. + +namespace WixToolset.Extensibility +{ + using System.Collections.Generic; + using System.Linq; + using WixToolset.Extensibility.Data; + using WixToolset.Extensibility.Services; + + public abstract class BaseExtensionCommandLine : IExtensionCommandLine + { + public IEnumerable CommandLineSwitches => Enumerable.Empty(); + + public virtual void PostParse() + { + } + + public virtual void PreParse(ICommandLineContext context) + { + } + + public virtual bool TryParseArgument(ICommandLineParser parser, string argument) + { + return false; + } + + public virtual bool TryParseCommand(ICommandLineParser parser, out ICommandLineCommand command) + { + command = null; + return false; + } + } +} 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 void Populate(string[] args); - IParseCommandLine Parse(); + ICommandLineParser Parse(); } } 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 @@ -// 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. +// 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. namespace WixToolset.Extensibility.Data { + using WixToolset.Extensibility.Services; + public interface ICommandLineCommand { + bool ShowLogo { get; } + + bool StopParsing { get; } + int Execute(); + + bool TryParseArgument(ICommandLineParser parser, string argument); } } 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 void PreParse(ICommandLineContext context); - bool TryParseArgument(IParseCommandLine parseCommandLine, string arg); + bool TryParseArgument(ICommandLineParser parser, string argument); + + bool TryParseCommand(ICommandLineParser parser, out ICommandLineCommand command); void PostParse(); } 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 @@ +// 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. + +namespace WixToolset.Extensibility.Services +{ + using WixToolset.Extensibility.Data; + + public interface ICommandLine + { + IExtensionManager ExtensionManager { get; set; } + + ICommandLineArguments Arguments { get; set; } + + ICommandLineCommand ParseStandardCommandLine(); + } +} 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 @@ -// 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. +// 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. namespace WixToolset.Extensibility.Services { - using WixToolset.Extensibility.Data; + using System.Collections.Generic; public interface ICommandLineParser { - IExtensionManager ExtensionManager { get; set; } + string ErrorArgument { get; set; } - ICommandLineArguments Arguments { get; set; } + /// + /// Validates that a valid switch (starts with "/" or "-"), and returns a bool indicating its validity + /// + /// The string check. + /// True if a valid switch, otherwise false. + bool IsSwitch(string arg); - ICommandLineCommand ParseStandardCommandLine(); + string GetArgumentAsFilePathOrError(string argument, string fileType); + + void GetArgumentAsFilePathOrError(string argument, string fileType, IList paths); + + string GetNextArgumentOrError(string commandLineSwitch); + + bool GetNextArgumentOrError(string commandLineSwitch, IList argument); + + string GetNextArgumentAsDirectoryOrError(string commandLineSwitch); + + bool GetNextArgumentAsDirectoryOrError(string commandLineSwitch, IList directories); + + string GetNextArgumentAsFilePathOrError(string commandLineSwitch); + + bool GetNextArgumentAsFilePathOrError(string commandLineSwitch, string fileType, IList paths); + + bool TryGetNextSwitchOrArgument(out string arg); } } 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 @@ -// 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. - -namespace WixToolset.Extensibility.Services -{ - using System.Collections.Generic; - - public interface IParseCommandLine - { - string ErrorArgument { get; set; } - - /// - /// Validates that a valid switch (starts with "/" or "-"), and returns a bool indicating its validity - /// - /// The string check. - /// True if a valid switch, otherwise false. - bool IsSwitch(string arg); - - void GetArgumentAsFilePathOrError(string argument, string fileType, IList paths); - - string GetNextArgumentOrError(string commandLineSwitch); - - bool GetNextArgumentOrError(string commandLineSwitch, IList argument); - - string GetNextArgumentAsDirectoryOrError(string commandLineSwitch); - - bool GetNextArgumentAsDirectoryOrError(string commandLineSwitch, IList directories); - - string GetNextArgumentAsFilePathOrError(string commandLineSwitch); - - bool GetNextArgumentAsFilePathOrError(string commandLineSwitch, string fileType, IList paths); - - bool TryGetNextSwitchOrArgument(out string arg); - } -} -- cgit v1.2.3-55-g6feb