aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core/CommandLine
diff options
context:
space:
mode:
Diffstat (limited to 'src/WixToolset.Core/CommandLine')
-rw-r--r--src/WixToolset.Core/CommandLine/CommandLine.cs38
-rw-r--r--src/WixToolset.Core/CommandLine/CommandLineArguments.cs53
-rw-r--r--src/WixToolset.Core/CommandLine/VersionCommand.cs7
3 files changed, 31 insertions, 67 deletions
diff --git a/src/WixToolset.Core/CommandLine/CommandLine.cs b/src/WixToolset.Core/CommandLine/CommandLine.cs
index 79f5d5bc..744e05b8 100644
--- a/src/WixToolset.Core/CommandLine/CommandLine.cs
+++ b/src/WixToolset.Core/CommandLine/CommandLine.cs
@@ -54,35 +54,6 @@ namespace WixToolset.Core.CommandLine
54 } 54 }
55 55
56 return command; 56 return command;
57 //switch (commandType)
58 //{
59 //case CommandTypes.Build:
60 //{
61 // var sourceFiles = GatherSourceFiles(files, outputFolder);
62 // var variables = this.GatherPreprocessorVariables(defines);
63 // var bindPathList = this.GatherBindPaths(bindPaths);
64 // var filterCultures = CalculateFilterCultures(cultures);
65 // var type = CalculateOutputType(outputType, outputFile);
66 // var platform = CalculatePlatform(platformType);
67 // return new BuildCommand(this.ServiceProvider, sourceFiles, variables, locFiles, libraryFiles, filterCultures, outputFile, type, platform, cabCachePath, bindFiles, bindPathList, includePaths, intermediateFolder, contentsFile, outputsFile, builtOutputsFile);
68 //}
69
70 //case CommandTypes.Compile:
71 //{
72 // var sourceFiles = GatherSourceFiles(files, outputFolder);
73 // var variables = this.GatherPreprocessorVariables(defines);
74 // var platform = CalculatePlatform(platformType);
75 // return new CompileCommand(this.ServiceProvider, sourceFiles, variables, platform);
76 //}
77
78 //case CommandTypes.Decompile:
79 //{
80 // var sourceFiles = GatherSourceFiles(files, outputFolder);
81 // return new DecompileCommand(this.ServiceProvider, sourceFiles, outputFile);
82 //}
83 //}
84
85 //return null;
86 } 57 }
87 58
88 private ICommandLineCommand Parse(ICommandLineContext context) 59 private ICommandLineCommand Parse(ICommandLineContext context)
@@ -109,7 +80,7 @@ namespace WixToolset.Core.CommandLine
109 // First argument must be the command or global switch (that creates a command). 80 // First argument must be the command or global switch (that creates a command).
110 if (command == null) 81 if (command == null)
111 { 82 {
112 if (!this.TryParseUnknownCommandArg(arg, parser, out command, extensions)) 83 if (!this.TryParseCommand(arg, parser, out command, extensions))
113 { 84 {
114 parser.ErrorArgument = arg; 85 parser.ErrorArgument = arg;
115 } 86 }
@@ -121,7 +92,7 @@ namespace WixToolset.Core.CommandLine
121 parser.ErrorArgument = arg; 92 parser.ErrorArgument = arg;
122 } 93 }
123 } 94 }
124 else if (!TryParseCommandLineArgumentWithExtension(arg, parser, extensions) && command?.TryParseArgument(parser, arg) == false) 95 else if (!TryParseCommandLineArgumentWithExtension(arg, parser, extensions) && !command.TryParseArgument(parser, arg))
125 { 96 {
126 parser.ErrorArgument = arg; 97 parser.ErrorArgument = arg;
127 } 98 }
@@ -135,7 +106,7 @@ namespace WixToolset.Core.CommandLine
135 return command ?? new HelpCommand(); 106 return command ?? new HelpCommand();
136 } 107 }
137 108
138 private bool TryParseUnknownCommandArg(string arg, ICommandLineParser parser, out ICommandLineCommand command, IEnumerable<IExtensionCommandLine> extensions) 109 private bool TryParseCommand(string arg, ICommandLineParser parser, out ICommandLineCommand command, IEnumerable<IExtensionCommandLine> extensions)
139 { 110 {
140 command = null; 111 command = null;
141 112
@@ -147,6 +118,7 @@ namespace WixToolset.Core.CommandLine
147 case "?": 118 case "?":
148 case "h": 119 case "h":
149 case "help": 120 case "help":
121 case "-help":
150 command = new HelpCommand(); 122 command = new HelpCommand();
151 break; 123 break;
152 124
@@ -179,7 +151,7 @@ namespace WixToolset.Core.CommandLine
179 { 151 {
180 foreach (var extension in extensions) 152 foreach (var extension in extensions)
181 { 153 {
182 if (extension.TryParseCommand(parser, out command)) 154 if (extension.TryParseCommand(parser, arg, out command))
183 { 155 {
184 break; 156 break;
185 } 157 }
diff --git a/src/WixToolset.Core/CommandLine/CommandLineArguments.cs b/src/WixToolset.Core/CommandLine/CommandLineArguments.cs
index 3f412611..456e19d7 100644
--- a/src/WixToolset.Core/CommandLine/CommandLineArguments.cs
+++ b/src/WixToolset.Core/CommandLine/CommandLineArguments.cs
@@ -12,6 +12,11 @@ namespace WixToolset.Core.CommandLine
12 12
13 internal class CommandLineArguments : ICommandLineArguments 13 internal class CommandLineArguments : ICommandLineArguments
14 { 14 {
15 public CommandLineArguments(IWixToolsetServiceProvider serviceProvider)
16 {
17 this.Messaging = serviceProvider.GetService<IMessaging>();
18 }
19
15 public string[] OriginalArguments { get; set; } 20 public string[] OriginalArguments { get; set; }
16 21
17 public string[] Arguments { get; set; } 22 public string[] Arguments { get; set; }
@@ -20,12 +25,7 @@ namespace WixToolset.Core.CommandLine
20 25
21 public string ErrorArgument { get; set; } 26 public string ErrorArgument { get; set; }
22 27
23 private IWixToolsetServiceProvider ServiceProvider { get; } 28 private IMessaging Messaging { get; }
24
25 public CommandLineArguments(IWixToolsetServiceProvider serviceProvider)
26 {
27 this.ServiceProvider = serviceProvider;
28 }
29 29
30 public void Populate(string commandLine) 30 public void Populate(string commandLine)
31 { 31 {
@@ -41,27 +41,25 @@ namespace WixToolset.Core.CommandLine
41 this.ProcessArgumentsAndParseExtensions(this.OriginalArguments); 41 this.ProcessArgumentsAndParseExtensions(this.OriginalArguments);
42 } 42 }
43 43
44 public ICommandLineParser Parse() 44 public ICommandLineParser Parse() => new CommandLineParser(this.Messaging, this.Arguments, this.ErrorArgument);
45 {
46 var messaging = this.ServiceProvider.GetService<IMessaging>();
47
48 return new CommandLineParser(messaging, this.Arguments, this.ErrorArgument);
49 }
50 45
51 private void FlattenArgumentsWithResponseFilesIntoOriginalArguments(string[] commandLineArguments) 46 private void FlattenArgumentsWithResponseFilesIntoOriginalArguments(string[] commandLineArguments)
52 { 47 {
53 List<string> args = new List<string>(); 48 var args = new List<string>();
54 49
55 foreach (var arg in commandLineArguments) 50 foreach (var arg in commandLineArguments)
56 { 51 {
57 if ('@' == arg[0]) 52 if (arg != null)
58 { 53 {
59 var responseFileArguments = CommandLineArguments.ParseResponseFile(arg.Substring(1)); 54 if ('@' == arg[0])
60 args.AddRange(responseFileArguments); 55 {
61 } 56 var responseFileArguments = CommandLineArguments.ParseResponseFile(arg.Substring(1));
62 else 57 args.AddRange(responseFileArguments);
63 { 58 }
64 args.Add(arg); 59 else
60 {
61 args.Add(arg);
62 }
65 } 63 }
66 } 64 }
67 65
@@ -103,7 +101,7 @@ namespace WixToolset.Core.CommandLine
103 { 101 {
104 string arguments; 102 string arguments;
105 103
106 using (StreamReader reader = new StreamReader(responseFile)) 104 using (var reader = new StreamReader(responseFile))
107 { 105 {
108 arguments = reader.ReadToEnd(); 106 arguments = reader.ReadToEnd();
109 } 107 }
@@ -131,7 +129,7 @@ namespace WixToolset.Core.CommandLine
131 // The current argument string being built; when completed it will be added to the list. 129 // The current argument string being built; when completed it will be added to the list.
132 var arg = new StringBuilder(); 130 var arg = new StringBuilder();
133 131
134 for (int i = 0; i <= arguments.Length; i++) 132 for (var i = 0; i <= arguments.Length; i++)
135 { 133 {
136 if (i == arguments.Length || (Char.IsWhiteSpace(arguments[i]) && !insideQuote)) 134 if (i == arguments.Length || (Char.IsWhiteSpace(arguments[i]) && !insideQuote))
137 { 135 {
@@ -182,10 +180,10 @@ namespace WixToolset.Core.CommandLine
182 var id = Environment.GetEnvironmentVariables(); 180 var id = Environment.GetEnvironmentVariables();
183 181
184 var regex = new Regex("(?<=\\%)(?:[\\w\\.]+)(?=\\%)"); 182 var regex = new Regex("(?<=\\%)(?:[\\w\\.]+)(?=\\%)");
185 MatchCollection matches = regex.Matches(arguments); 183 var matches = regex.Matches(arguments);
186 184
187 string value = String.Empty; 185 var value = String.Empty;
188 for (int i = 0; i <= (matches.Count - 1); i++) 186 for (var i = 0; i <= (matches.Count - 1); i++)
189 { 187 {
190 try 188 try
191 { 189 {
@@ -204,9 +202,6 @@ namespace WixToolset.Core.CommandLine
204 return arguments; 202 return arguments;
205 } 203 }
206 204
207 private static bool IsSwitchAt(string[] args, int index) 205 private static bool IsSwitchAt(string[] args, int index) => args.Length > index && !String.IsNullOrEmpty(args[index]) && ('/' == args[index][0] || '-' == args[index][0]);
208 {
209 return args.Length > index && !String.IsNullOrEmpty(args[index]) && ('/' == args[index][0] || '-' == args[index][0]);
210 }
211 } 206 }
212} 207}
diff --git a/src/WixToolset.Core/CommandLine/VersionCommand.cs b/src/WixToolset.Core/CommandLine/VersionCommand.cs
index 1baee72d..50e90a93 100644
--- a/src/WixToolset.Core/CommandLine/VersionCommand.cs
+++ b/src/WixToolset.Core/CommandLine/VersionCommand.cs
@@ -1,4 +1,4 @@
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
3namespace WixToolset.Core.CommandLine 3namespace WixToolset.Core.CommandLine
4{ 4{
@@ -20,9 +20,6 @@ namespace WixToolset.Core.CommandLine
20 return 0; 20 return 0;
21 } 21 }
22 22
23 public bool TryParseArgument(ICommandLineParser parseHelper, string argument) 23 public bool TryParseArgument(ICommandLineParser parseHelper, string argument) => true; // eat any arguments
24 {
25 return true; // eat any arguments
26 }
27 } 24 }
28} 25}