diff options
Diffstat (limited to 'src/WixToolset.Core/CommandLine/CommandLine.cs')
| -rw-r--r-- | src/WixToolset.Core/CommandLine/CommandLine.cs | 91 |
1 files changed, 53 insertions, 38 deletions
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 | |||
| 21 | 21 | ||
| 22 | internal class CommandLine : ICommandLine | 22 | internal class CommandLine : ICommandLine |
| 23 | { | 23 | { |
| 24 | public CommandLine(IWixToolsetServiceProvider serviceProvider) | 24 | public CommandLine(IWixToolsetServiceProvider serviceProvider) => this.ServiceProvider = serviceProvider; |
| 25 | { | ||
| 26 | this.ServiceProvider = serviceProvider; | ||
| 27 | |||
| 28 | this.Messaging = this.ServiceProvider.GetService<IMessaging>(); | ||
| 29 | } | ||
| 30 | 25 | ||
| 31 | private IWixToolsetServiceProvider ServiceProvider { get; } | 26 | private IWixToolsetServiceProvider ServiceProvider { get; } |
| 32 | 27 | ||
| 33 | private IMessaging Messaging { get; set; } | 28 | public ICommandLineCommand CreateCommand(string[] args) |
| 29 | { | ||
| 30 | var arguments = this.ServiceProvider.GetService<ICommandLineArguments>(); | ||
| 31 | arguments.Populate(args); | ||
| 34 | 32 | ||
| 35 | public IExtensionManager ExtensionManager { get; set; } | 33 | this.LoadExtensions(arguments.Extensions); |
| 36 | 34 | ||
| 37 | public ICommandLineArguments Arguments { get; set; } | 35 | return this.ParseStandardCommandLine(arguments); |
| 36 | } | ||
| 38 | 37 | ||
| 39 | public static string ExpectedArgument { get; } = "expected argument"; | 38 | public ICommandLineCommand CreateCommand(string commandLine) |
| 39 | { | ||
| 40 | var arguments = this.ServiceProvider.GetService<ICommandLineArguments>(); | ||
| 41 | arguments.Populate(commandLine); | ||
| 40 | 42 | ||
| 41 | public bool ShowHelp { get; private set; } | 43 | this.LoadExtensions(arguments.Extensions); |
| 42 | 44 | ||
| 43 | public ICommandLineCommand ParseStandardCommandLine() | 45 | return this.ParseStandardCommandLine(arguments); |
| 46 | } | ||
| 47 | |||
| 48 | public ICommandLineCommand ParseStandardCommandLine(ICommandLineArguments arguments) | ||
| 44 | { | 49 | { |
| 45 | var context = this.ServiceProvider.GetService<ICommandLineContext>(); | 50 | var context = this.ServiceProvider.GetService<ICommandLineContext>(); |
| 46 | context.ExtensionManager = this.ExtensionManager ?? this.ServiceProvider.GetService<IExtensionManager>(); | 51 | context.ExtensionManager = this.ServiceProvider.GetService<IExtensionManager>(); |
| 47 | context.Arguments = this.Arguments; | 52 | context.Arguments = arguments; |
| 48 | 53 | ||
| 49 | var command = this.Parse(context); | 54 | var command = this.Parse(context); |
| 50 | 55 | ||
| @@ -56,9 +61,19 @@ namespace WixToolset.Core.CommandLine | |||
| 56 | return command; | 61 | return command; |
| 57 | } | 62 | } |
| 58 | 63 | ||
| 64 | private void LoadExtensions(string[] extensions) | ||
| 65 | { | ||
| 66 | var extensionManager = this.ServiceProvider.GetService<IExtensionManager>(); | ||
| 67 | |||
| 68 | foreach (var extension in extensions) | ||
| 69 | { | ||
| 70 | extensionManager.Load(extension); | ||
| 71 | } | ||
| 72 | } | ||
| 73 | |||
| 59 | private ICommandLineCommand Parse(ICommandLineContext context) | 74 | private ICommandLineCommand Parse(ICommandLineContext context) |
| 60 | { | 75 | { |
| 61 | var extensions = this.ExtensionManager.GetServices<IExtensionCommandLine>(); | 76 | var extensions = context.ExtensionManager.GetServices<IExtensionCommandLine>(); |
| 62 | 77 | ||
| 63 | foreach (var extension in extensions) | 78 | foreach (var extension in extensions) |
| 64 | { | 79 | { |
| @@ -80,7 +95,7 @@ namespace WixToolset.Core.CommandLine | |||
| 80 | // First argument must be the command or global switch (that creates a command). | 95 | // First argument must be the command or global switch (that creates a command). |
| 81 | if (command == null) | 96 | if (command == null) |
| 82 | { | 97 | { |
| 83 | if (!this.TryParseCommand(arg, parser, out command, extensions)) | 98 | if (!this.TryParseCommand(arg, parser, extensions, out command)) |
| 84 | { | 99 | { |
| 85 | parser.ErrorArgument = arg; | 100 | parser.ErrorArgument = arg; |
| 86 | } | 101 | } |
| @@ -105,8 +120,8 @@ namespace WixToolset.Core.CommandLine | |||
| 105 | 120 | ||
| 106 | return command ?? new HelpCommand(); | 121 | return command ?? new HelpCommand(); |
| 107 | } | 122 | } |
| 108 | 123 | ||
| 109 | private bool TryParseCommand(string arg, ICommandLineParser parser, out ICommandLineCommand command, IEnumerable<IExtensionCommandLine> extensions) | 124 | private bool TryParseCommand(string arg, ICommandLineParser parser, IEnumerable<IExtensionCommandLine> extensions, out ICommandLineCommand command) |
| 110 | { | 125 | { |
| 111 | command = null; | 126 | command = null; |
| 112 | 127 | ||
| @@ -115,17 +130,17 @@ namespace WixToolset.Core.CommandLine | |||
| 115 | var parameter = arg.Substring(1); | 130 | var parameter = arg.Substring(1); |
| 116 | switch (parameter.ToLowerInvariant()) | 131 | switch (parameter.ToLowerInvariant()) |
| 117 | { | 132 | { |
| 118 | case "?": | 133 | case "?": |
| 119 | case "h": | 134 | case "h": |
| 120 | case "help": | 135 | case "help": |
| 121 | case "-help": | 136 | case "-help": |
| 122 | command = new HelpCommand(); | 137 | command = new HelpCommand(); |
| 123 | break; | 138 | break; |
| 124 | 139 | ||
| 125 | case "version": | 140 | case "version": |
| 126 | case "-version": | 141 | case "-version": |
| 127 | command = new VersionCommand(); | 142 | command = new VersionCommand(); |
| 128 | break; | 143 | break; |
| 129 | } | 144 | } |
| 130 | } | 145 | } |
| 131 | else | 146 | else |
| @@ -134,17 +149,17 @@ namespace WixToolset.Core.CommandLine | |||
| 134 | { | 149 | { |
| 135 | switch (commandType) | 150 | switch (commandType) |
| 136 | { | 151 | { |
| 137 | case CommandTypes.Build: | 152 | case CommandTypes.Build: |
| 138 | command = new BuildCommand(this.ServiceProvider); | 153 | command = new BuildCommand(this.ServiceProvider); |
| 139 | break; | 154 | break; |
| 140 | 155 | ||
| 141 | case CommandTypes.Compile: | 156 | case CommandTypes.Compile: |
| 142 | command = new CompileCommand(this.ServiceProvider); | 157 | command = new CompileCommand(this.ServiceProvider); |
| 143 | break; | 158 | break; |
| 144 | 159 | ||
| 145 | case CommandTypes.Decompile: | 160 | case CommandTypes.Decompile: |
| 146 | command = new DecompileCommand(this.ServiceProvider); | 161 | command = new DecompileCommand(this.ServiceProvider); |
| 147 | break; | 162 | break; |
| 148 | } | 163 | } |
| 149 | } | 164 | } |
| 150 | else | 165 | else |
