summaryrefslogtreecommitdiff
path: root/src/tools/heat/HeatCommandLine.cs
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2022-07-26 17:20:39 -0700
committerRob Mensching <rob@firegiant.com>2022-08-01 20:25:19 -0700
commita627ca9b720047e633a8fe72003ab9bee31006c5 (patch)
tree2bc8a924bb4141ab718e74d08f6459a0ffe8d573 /src/tools/heat/HeatCommandLine.cs
parent521eb3c9cf38823a2c4019abb85dc0b3200b92cb (diff)
downloadwix-a627ca9b720047e633a8fe72003ab9bee31006c5.tar.gz
wix-a627ca9b720047e633a8fe72003ab9bee31006c5.tar.bz2
wix-a627ca9b720047e633a8fe72003ab9bee31006c5.zip
Create WixToolset.Heat.nupkg to distribute heat.exe and Heat targets
Moves Heat functionality to the "tools" layer and packages it all up in WixToolset.Heat.nupkg for distribution in WiX v4. Completes 6838
Diffstat (limited to 'src/tools/heat/HeatCommandLine.cs')
-rw-r--r--src/tools/heat/HeatCommandLine.cs91
1 files changed, 91 insertions, 0 deletions
diff --git a/src/tools/heat/HeatCommandLine.cs b/src/tools/heat/HeatCommandLine.cs
new file mode 100644
index 00000000..b11dda4e
--- /dev/null
+++ b/src/tools/heat/HeatCommandLine.cs
@@ -0,0 +1,91 @@
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
3namespace WixToolset.Harvesters
4{
5 using System;
6 using System.Collections.Generic;
7 using System.Linq;
8 using WixToolset.Data;
9 using WixToolset.Extensibility.Data;
10 using WixToolset.Extensibility.Services;
11 using WixToolset.Harvesters.Data;
12 using WixToolset.Harvesters.Extensibility;
13
14 internal class HeatCommandLine : IHeatCommandLine
15 {
16 private readonly List<IHeatExtension> extensions;
17 private readonly IMessaging messaging;
18 private readonly IServiceProvider serviceProvider;
19
20 public HeatCommandLine(IServiceProvider serviceProvider, IEnumerable<IHeatExtension> heatExtensions)
21 {
22 this.extensions = new List<IHeatExtension> { new IIsHeatExtension(), new UtilHeatExtension(serviceProvider), new VSHeatExtension() };
23 if (heatExtensions != null)
24 {
25 this.extensions.AddRange(heatExtensions);
26 }
27 this.messaging = serviceProvider.GetService<IMessaging>();
28 this.serviceProvider = serviceProvider;
29 }
30
31 public ICommandLineCommand ParseStandardCommandLine(ICommandLineArguments arguments)
32 {
33 ICommandLineCommand command = null;
34 var parser = arguments.Parse();
35
36 while (command?.StopParsing != true &&
37 String.IsNullOrEmpty(parser.ErrorArgument) &&
38 parser.TryGetNextSwitchOrArgument(out var arg))
39 {
40 if (String.IsNullOrWhiteSpace(arg)) // skip blank arguments.
41 {
42 continue;
43 }
44
45 // First argument must be the command or global switch (that creates a command).
46 if (command == null)
47 {
48 if (!this.TryParseUnknownCommandArg(arg, parser, out command))
49 {
50 parser.ReportErrorArgument(arg, ErrorMessages.HarvestTypeNotFound(arg));
51 }
52 }
53 else if (!command.TryParseArgument(parser, arg))
54 {
55 parser.ReportErrorArgument(arg);
56 }
57 }
58
59 return command ?? new HelpCommand(this.extensions);
60 }
61
62 public bool TryParseUnknownCommandArg(string arg, ICommandLineParser parser, out ICommandLineCommand command)
63 {
64 command = null;
65
66 if (parser.IsSwitch(arg))
67 {
68 var parameter = arg.Substring(1);
69 switch (parameter.ToLowerInvariant())
70 {
71 case "?":
72 case "h":
73 case "help":
74 command = new HelpCommand(this.extensions);
75 return true;
76 }
77 }
78
79 foreach (var heatExtension in this.extensions)
80 {
81 if (heatExtension.CommandLineTypes.Any(o => o.Option == arg))
82 {
83 command = new HeatCommand(arg, this.extensions, this.serviceProvider);
84 return true;
85 }
86 }
87
88 return false;
89 }
90 }
91}