From cd6f466549ba8e4b138da4332b0831ab45ca8a2f Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Sat, 13 Jun 2020 10:01:27 -0700 Subject: Implement simplified command and improved backend integration --- src/WixToolset.Core/CommandLine/CommandLine.cs | 91 +++++++++++++++----------- 1 file changed, 53 insertions(+), 38 deletions(-) (limited to 'src/WixToolset.Core/CommandLine/CommandLine.cs') diff --git a/src/WixToolset.Core/CommandLine/CommandLine.cs b/src/WixToolset.Core/CommandLine/CommandLine.cs index 744e05b8..02bc32e9 100644 --- a/src/WixToolset.Core/CommandLine/CommandLine.cs +++ b/src/WixToolset.Core/CommandLine/CommandLine.cs @@ -21,30 +21,35 @@ namespace WixToolset.Core.CommandLine internal class CommandLine : ICommandLine { - public CommandLine(IWixToolsetServiceProvider serviceProvider) - { - this.ServiceProvider = serviceProvider; - - this.Messaging = this.ServiceProvider.GetService(); - } + public CommandLine(IWixToolsetServiceProvider serviceProvider) => this.ServiceProvider = serviceProvider; private IWixToolsetServiceProvider ServiceProvider { get; } - private IMessaging Messaging { get; set; } + public ICommandLineCommand CreateCommand(string[] args) + { + var arguments = this.ServiceProvider.GetService(); + arguments.Populate(args); - public IExtensionManager ExtensionManager { get; set; } + this.LoadExtensions(arguments.Extensions); - public ICommandLineArguments Arguments { get; set; } + return this.ParseStandardCommandLine(arguments); + } - public static string ExpectedArgument { get; } = "expected argument"; + public ICommandLineCommand CreateCommand(string commandLine) + { + var arguments = this.ServiceProvider.GetService(); + arguments.Populate(commandLine); - public bool ShowHelp { get; private set; } + this.LoadExtensions(arguments.Extensions); - public ICommandLineCommand ParseStandardCommandLine() + return this.ParseStandardCommandLine(arguments); + } + + public ICommandLineCommand ParseStandardCommandLine(ICommandLineArguments arguments) { var context = this.ServiceProvider.GetService(); - context.ExtensionManager = this.ExtensionManager ?? this.ServiceProvider.GetService(); - context.Arguments = this.Arguments; + context.ExtensionManager = this.ServiceProvider.GetService(); + context.Arguments = arguments; var command = this.Parse(context); @@ -56,9 +61,19 @@ namespace WixToolset.Core.CommandLine return command; } + private void LoadExtensions(string[] extensions) + { + var extensionManager = this.ServiceProvider.GetService(); + + foreach (var extension in extensions) + { + extensionManager.Load(extension); + } + } + private ICommandLineCommand Parse(ICommandLineContext context) { - var extensions = this.ExtensionManager.GetServices(); + var extensions = context.ExtensionManager.GetServices(); foreach (var extension in extensions) { @@ -80,7 +95,7 @@ namespace WixToolset.Core.CommandLine // First argument must be the command or global switch (that creates a command). if (command == null) { - if (!this.TryParseCommand(arg, parser, out command, extensions)) + if (!this.TryParseCommand(arg, parser, extensions, out command)) { parser.ErrorArgument = arg; } @@ -105,8 +120,8 @@ namespace WixToolset.Core.CommandLine return command ?? new HelpCommand(); } - - private bool TryParseCommand(string arg, ICommandLineParser parser, out ICommandLineCommand command, IEnumerable extensions) + + private bool TryParseCommand(string arg, ICommandLineParser parser, IEnumerable extensions, out ICommandLineCommand command) { command = null; @@ -115,17 +130,17 @@ namespace WixToolset.Core.CommandLine var parameter = arg.Substring(1); switch (parameter.ToLowerInvariant()) { - case "?": - case "h": - case "help": - case "-help": - command = new HelpCommand(); - break; - - case "version": - case "-version": - command = new VersionCommand(); - break; + case "?": + case "h": + case "help": + case "-help": + command = new HelpCommand(); + break; + + case "version": + case "-version": + command = new VersionCommand(); + break; } } else @@ -134,17 +149,17 @@ namespace WixToolset.Core.CommandLine { switch (commandType) { - case CommandTypes.Build: - command = new BuildCommand(this.ServiceProvider); - break; + case CommandTypes.Build: + command = new BuildCommand(this.ServiceProvider); + break; - case CommandTypes.Compile: - command = new CompileCommand(this.ServiceProvider); - break; + case CommandTypes.Compile: + command = new CompileCommand(this.ServiceProvider); + break; - case CommandTypes.Decompile: - command = new DecompileCommand(this.ServiceProvider); - break; + case CommandTypes.Decompile: + command = new DecompileCommand(this.ServiceProvider); + break; } } else -- cgit v1.2.3-55-g6feb