aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2020-07-18 14:55:58 -0700
committerRob Mensching <rob@firegiant.com>2020-07-18 15:03:11 -0700
commitf4cefb9ac9a6911ee0a1ad035e6ee50b7f28e5c5 (patch)
tree7f06847dfdb75b5dd7720be4b4459adaa1fbf519 /src
parent6b21265e139513c1a242d8677b154fcc0e1dc7ef (diff)
downloadwix-f4cefb9ac9a6911ee0a1ad035e6ee50b7f28e5c5.tar.gz
wix-f4cefb9ac9a6911ee0a1ad035e6ee50b7f28e5c5.tar.bz2
wix-f4cefb9ac9a6911ee0a1ad035e6ee50b7f28e5c5.zip
Display command-line help from Core and extensions
Closes wixtoolset/issues#6211
Diffstat (limited to 'src')
-rw-r--r--src/WixToolset.Core.ExtensionCache/ExtensionCacheManagerCommand.cs21
-rw-r--r--src/WixToolset.Core.ExtensionCache/ExtensionCacheManagerExtensionCommandLine.cs6
-rw-r--r--src/WixToolset.Core/CommandLine/CommandLine.cs4
-rw-r--r--src/WixToolset.Core/CommandLine/CommandLineParser.cs36
-rw-r--r--src/WixToolset.Core/CommandLine/HelpCommand.cs43
-rw-r--r--src/WixToolset.Core/CommandLine/VersionCommand.cs3
-rw-r--r--src/WixToolset.Core/ExtensibilityServices/Messaging.cs22
7 files changed, 79 insertions, 56 deletions
diff --git a/src/WixToolset.Core.ExtensionCache/ExtensionCacheManagerCommand.cs b/src/WixToolset.Core.ExtensionCache/ExtensionCacheManagerCommand.cs
index 24f17d06..67c1504b 100644
--- a/src/WixToolset.Core.ExtensionCache/ExtensionCacheManagerCommand.cs
+++ b/src/WixToolset.Core.ExtensionCache/ExtensionCacheManagerCommand.cs
@@ -96,12 +96,15 @@ namespace WixToolset.Core.ExtensionCache
96 switch (parameter.ToLowerInvariant()) 96 switch (parameter.ToLowerInvariant())
97 { 97 {
98 case "?": 98 case "?":
99 case "h":
100 case "-help":
99 this.ShowHelp = true; 101 this.ShowHelp = true;
100 this.ShowLogo = true; 102 this.ShowLogo = true;
101 this.StopParsing = true; 103 this.StopParsing = true;
102 return true; 104 return true;
103 105
104 case "nologo": 106 case "nologo":
107 case "-nologo":
105 this.ShowLogo = false; 108 this.ShowLogo = false;
106 return true; 109 return true;
107 110
@@ -158,13 +161,21 @@ namespace WixToolset.Core.ExtensionCache
158 161
159 private static void DisplayHelp() 162 private static void DisplayHelp()
160 { 163 {
161 Console.WriteLine(" usage: wix.exe extension add|remove|list [extensionRef]");
162 Console.WriteLine(); 164 Console.WriteLine();
163 Console.WriteLine(" -g add/remove the extension for the current user"); 165 Console.WriteLine("Usage: wix extension add|remove|list [extensionRef]");
164 Console.WriteLine(" -nologo suppress displaying the logo information");
165 Console.WriteLine(" -? this help information");
166 Console.WriteLine(); 166 Console.WriteLine();
167 Console.WriteLine(" extensionRef format: extensionId/version (the version is optional)"); 167 Console.WriteLine("Options:");
168 Console.WriteLine(" -h|--help Show command line help.");
169 Console.WriteLine(" -g|--global Add/remove the extension for the current user.");
170 Console.WriteLine(" --nologo Suppress displaying the logo information.");
171 Console.WriteLine();
172 Console.WriteLine("Commands:");
173 Console.WriteLine();
174 Console.WriteLine(" add Add extension to the cache.");
175 Console.WriteLine(" list List extensions in the cache.");
176 Console.WriteLine(" remove Remove extension from the cache.");
177 Console.WriteLine();
178 Console.WriteLine(" extensionRef format: extensionId/version (the version is optional)");
168 } 179 }
169 } 180 }
170} 181}
diff --git a/src/WixToolset.Core.ExtensionCache/ExtensionCacheManagerExtensionCommandLine.cs b/src/WixToolset.Core.ExtensionCache/ExtensionCacheManagerExtensionCommandLine.cs
index 81e96718..a27e2a1f 100644
--- a/src/WixToolset.Core.ExtensionCache/ExtensionCacheManagerExtensionCommandLine.cs
+++ b/src/WixToolset.Core.ExtensionCache/ExtensionCacheManagerExtensionCommandLine.cs
@@ -21,8 +21,10 @@ namespace WixToolset.Core.ExtensionCache
21 21
22 private IWixToolsetServiceProvider ServiceProvider { get; } 22 private IWixToolsetServiceProvider ServiceProvider { get; }
23 23
24 // TODO: Do something with CommandLineSwitches 24 public override IEnumerable<ExtensionCommandLineSwitch> CommandLineSwitches => new ExtensionCommandLineSwitch[]
25 public override IEnumerable<ExtensionCommandLineSwitch> CommandLineSwitches => base.CommandLineSwitches; 25 {
26 new ExtensionCommandLineSwitch { Switch = "extension", Description = "Manage extension cache." },
27 };
26 28
27 public override bool TryParseCommand(ICommandLineParser parser, string argument, out ICommandLineCommand command) 29 public override bool TryParseCommand(ICommandLineParser parser, string argument, out ICommandLineCommand command)
28 { 30 {
diff --git a/src/WixToolset.Core/CommandLine/CommandLine.cs b/src/WixToolset.Core/CommandLine/CommandLine.cs
index 02bc32e9..5439eb39 100644
--- a/src/WixToolset.Core/CommandLine/CommandLine.cs
+++ b/src/WixToolset.Core/CommandLine/CommandLine.cs
@@ -118,7 +118,7 @@ namespace WixToolset.Core.CommandLine
118 extension.PostParse(); 118 extension.PostParse();
119 } 119 }
120 120
121 return command ?? new HelpCommand(); 121 return command ?? new HelpCommand(extensions);
122 } 122 }
123 123
124 private bool TryParseCommand(string arg, ICommandLineParser parser, IEnumerable<IExtensionCommandLine> extensions, out ICommandLineCommand command) 124 private bool TryParseCommand(string arg, ICommandLineParser parser, IEnumerable<IExtensionCommandLine> extensions, out ICommandLineCommand command)
@@ -134,7 +134,7 @@ namespace WixToolset.Core.CommandLine
134 case "h": 134 case "h":
135 case "help": 135 case "help":
136 case "-help": 136 case "-help":
137 command = new HelpCommand(); 137 command = new HelpCommand(extensions);
138 break; 138 break;
139 139
140 case "version": 140 case "version":
diff --git a/src/WixToolset.Core/CommandLine/CommandLineParser.cs b/src/WixToolset.Core/CommandLine/CommandLineParser.cs
index 11e5751d..2ee1e9ae 100644
--- a/src/WixToolset.Core/CommandLine/CommandLineParser.cs
+++ b/src/WixToolset.Core/CommandLine/CommandLineParser.cs
@@ -27,7 +27,7 @@ namespace WixToolset.Core.CommandLine
27 27
28 public bool IsSwitch(string arg) 28 public bool IsSwitch(string arg)
29 { 29 {
30 return !String.IsNullOrEmpty(arg) && ('/' == arg[0] || '-' == arg[0]); 30 return !String.IsNullOrEmpty(arg) && '-' == arg[0];
31 } 31 }
32 32
33 public string GetArgumentAsFilePathOrError(string argument, string fileType) 33 public string GetArgumentAsFilePathOrError(string argument, string fileType)
@@ -74,7 +74,7 @@ namespace WixToolset.Core.CommandLine
74 74
75 public string GetNextArgumentAsDirectoryOrError(string commandLineSwitch) 75 public string GetNextArgumentAsDirectoryOrError(string commandLineSwitch)
76 { 76 {
77 if (this.TryGetNextNonSwitchArgumentOrError(out var arg) && this.TryGetDirectory(commandLineSwitch, this.Messaging, arg, out var directory)) 77 if (this.TryGetNextNonSwitchArgumentOrError(out var arg) && this.TryGetDirectory(commandLineSwitch, arg, out var directory))
78 { 78 {
79 return directory; 79 return directory;
80 } 80 }
@@ -85,7 +85,7 @@ namespace WixToolset.Core.CommandLine
85 85
86 public bool GetNextArgumentAsDirectoryOrError(string commandLineSwitch, IList<string> directories) 86 public bool GetNextArgumentAsDirectoryOrError(string commandLineSwitch, IList<string> directories)
87 { 87 {
88 if (this.TryGetNextNonSwitchArgumentOrError(out var arg) && this.TryGetDirectory(commandLineSwitch, this.Messaging, arg, out var directory)) 88 if (this.TryGetNextNonSwitchArgumentOrError(out var arg) && this.TryGetDirectory(commandLineSwitch, arg, out var directory))
89 { 89 {
90 directories.Add(directory); 90 directories.Add(directory);
91 return true; 91 return true;
@@ -124,7 +124,14 @@ namespace WixToolset.Core.CommandLine
124 124
125 public bool TryGetNextSwitchOrArgument(out string arg) 125 public bool TryGetNextSwitchOrArgument(out string arg)
126 { 126 {
127 return TryDequeue(this.RemainingArguments, out arg); 127 if (this.RemainingArguments.Count > 0)
128 {
129 arg = this.RemainingArguments.Dequeue();
130 return true;
131 }
132
133 arg = null;
134 return false;
128 } 135 }
129 136
130 private bool TryGetNextNonSwitchArgumentOrError(out string arg) 137 private bool TryGetNextNonSwitchArgumentOrError(out string arg)
@@ -139,24 +146,7 @@ namespace WixToolset.Core.CommandLine
139 return result; 146 return result;
140 } 147 }
141 148
142 private static bool IsValidArg(string arg) 149 private bool TryGetDirectory(string commandlineSwitch, string arg, out string directory)
143 {
144 return !(String.IsNullOrEmpty(arg) || '/' == arg[0] || '-' == arg[0]);
145 }
146
147 private static bool TryDequeue(Queue<string> q, out string arg)
148 {
149 if (q.Count > 0)
150 {
151 arg = q.Dequeue();
152 return true;
153 }
154
155 arg = null;
156 return false;
157 }
158
159 private bool TryGetDirectory(string commandlineSwitch, IMessaging messageHandler, string arg, out string directory)
160 { 150 {
161 directory = null; 151 directory = null;
162 152
@@ -174,7 +164,7 @@ namespace WixToolset.Core.CommandLine
174 { 164 {
175 path = null; 165 path = null;
176 166
177 if (!IsValidArg(arg)) 167 if (String.IsNullOrEmpty(arg) || '-' == arg[0])
178 { 168 {
179 this.Messaging.Write(ErrorMessages.FilePathRequired(commandlineSwitch)); 169 this.Messaging.Write(ErrorMessages.FilePathRequired(commandlineSwitch));
180 } 170 }
diff --git a/src/WixToolset.Core/CommandLine/HelpCommand.cs b/src/WixToolset.Core/CommandLine/HelpCommand.cs
index 78845189..3af442aa 100644
--- a/src/WixToolset.Core/CommandLine/HelpCommand.cs
+++ b/src/WixToolset.Core/CommandLine/HelpCommand.cs
@@ -3,27 +3,60 @@
3namespace WixToolset.Core.CommandLine 3namespace WixToolset.Core.CommandLine
4{ 4{
5 using System; 5 using System;
6 using System.Collections.Generic;
7 using System.Linq;
6 using System.Threading; 8 using System.Threading;
7 using System.Threading.Tasks; 9 using System.Threading.Tasks;
10 using WixToolset.Extensibility;
8 using WixToolset.Extensibility.Data; 11 using WixToolset.Extensibility.Data;
9 using WixToolset.Extensibility.Services; 12 using WixToolset.Extensibility.Services;
10 13
11 internal class HelpCommand : ICommandLineCommand 14 internal class HelpCommand : ICommandLineCommand
12 { 15 {
16 private static readonly ExtensionCommandLineSwitch[] BuiltInSwitches = new ExtensionCommandLineSwitch[]
17 {
18 new ExtensionCommandLineSwitch { Switch = "build", Description = "Build a wixlib, package or bundle." },
19 new ExtensionCommandLineSwitch { Switch = "decompile", Description = "Decompile a package or bundle into source code." },
20 };
21
22 public HelpCommand(IEnumerable<IExtensionCommandLine> extensions)
23 {
24 this.Extensions = extensions;
25 }
26
13 public bool ShowLogo => true; 27 public bool ShowLogo => true;
14 28
15 public bool StopParsing => true; 29 public bool StopParsing => true;
16 30
31 private IEnumerable<IExtensionCommandLine> Extensions { get; }
32
17 public Task<int> ExecuteAsync(CancellationToken _) 33 public Task<int> ExecuteAsync(CancellationToken _)
18 { 34 {
19 Console.WriteLine("TODO: Show list of available commands"); 35 var commandLineSwitches = new List<ExtensionCommandLineSwitch>(BuiltInSwitches);
36 commandLineSwitches.AddRange(this.Extensions.SelectMany(e => e.CommandLineSwitches).OrderBy(s => s.Switch, StringComparer.Ordinal));
37
38 Console.WriteLine();
39 Console.WriteLine("Usage: wix [option]");
40 Console.WriteLine("Usage: wix [command]");
41 Console.WriteLine();
42 Console.WriteLine("Options:");
43 Console.WriteLine(" -h|--help Show command line help.");
44 Console.WriteLine(" --version Display WiX Toolset version in use.");
45 Console.WriteLine();
46
47 Console.WriteLine("Commands:");
48 foreach (var commandLineSwitch in commandLineSwitches)
49 {
50 Console.WriteLine(" {0,-17} {1}", commandLineSwitch.Switch, commandLineSwitch.Description);
51 }
52
53 Console.WriteLine();
54 Console.WriteLine("Run 'wix [command] --help' for more information on a command.");
55 AppCommon.DisplayToolFooter();
20 56
21 return Task.FromResult(-1); 57 return Task.FromResult(-1);
22 } 58 }
23 59
24 public bool TryParseArgument(ICommandLineParser parseHelper, string argument) 60 public bool TryParseArgument(ICommandLineParser parseHelper, string argument) => true; // eat any arguments
25 {
26 return true; // eat any arguments
27 }
28 } 61 }
29} 62}
diff --git a/src/WixToolset.Core/CommandLine/VersionCommand.cs b/src/WixToolset.Core/CommandLine/VersionCommand.cs
index 6ce2a89d..01a7d0e6 100644
--- a/src/WixToolset.Core/CommandLine/VersionCommand.cs
+++ b/src/WixToolset.Core/CommandLine/VersionCommand.cs
@@ -16,8 +16,7 @@ namespace WixToolset.Core.CommandLine
16 16
17 public Task<int> ExecuteAsync(CancellationToken cancellationToken) 17 public Task<int> ExecuteAsync(CancellationToken cancellationToken)
18 { 18 {
19 Console.WriteLine("wix version {0}", ThisAssembly.AssemblyInformationalVersion); 19 Console.WriteLine(ThisAssembly.AssemblyInformationalVersion);
20 Console.WriteLine();
21 20
22 return Task.FromResult(0); 21 return Task.FromResult(0);
23 } 22 }
diff --git a/src/WixToolset.Core/ExtensibilityServices/Messaging.cs b/src/WixToolset.Core/ExtensibilityServices/Messaging.cs
index 266d842a..afcd9244 100644
--- a/src/WixToolset.Core/ExtensibilityServices/Messaging.cs
+++ b/src/WixToolset.Core/ExtensibilityServices/Messaging.cs
@@ -2,10 +2,7 @@
2 2
3namespace WixToolset.Core.ExtensibilityServices 3namespace WixToolset.Core.ExtensibilityServices
4{ 4{
5 using System;
6 using System.Collections.Generic; 5 using System.Collections.Generic;
7 using System.Globalization;
8 using System.Text;
9 using WixToolset.Data; 6 using WixToolset.Data;
10 using WixToolset.Extensibility; 7 using WixToolset.Extensibility;
11 using WixToolset.Extensibility.Services; 8 using WixToolset.Extensibility.Services;
@@ -13,8 +10,8 @@ namespace WixToolset.Core.ExtensibilityServices
13 internal class Messaging : IMessaging 10 internal class Messaging : IMessaging
14 { 11 {
15 private IMessageListener listener; 12 private IMessageListener listener;
16 private HashSet<int> suppressedWarnings = new HashSet<int>(); 13 private readonly HashSet<int> suppressedWarnings = new HashSet<int>();
17 private HashSet<int> warningsAsErrors = new HashSet<int>(); 14 private readonly HashSet<int> warningsAsErrors = new HashSet<int>();
18 15
19 public bool EncounteredError { get; private set; } 16 public bool EncounteredError { get; private set; }
20 17
@@ -26,20 +23,11 @@ namespace WixToolset.Core.ExtensibilityServices
26 23
27 public bool WarningsAsError { get; set; } 24 public bool WarningsAsError { get; set; }
28 25
29 public void ElevateWarningMessage(int warningNumber) 26 public void ElevateWarningMessage(int warningNumber) => this.warningsAsErrors.Add(warningNumber);
30 {
31 this.warningsAsErrors.Add(warningNumber);
32 }
33 27
34 public void SetListener(IMessageListener listener) 28 public void SetListener(IMessageListener listener) => this.listener = listener;
35 {
36 this.listener = listener;
37 }
38 29
39 public void SuppressWarningMessage(int warningNumber) 30 public void SuppressWarningMessage(int warningNumber) => this.suppressedWarnings.Add(warningNumber);
40 {
41 this.suppressedWarnings.Add(warningNumber);
42 }
43 31
44 public void Write(Message message) 32 public void Write(Message message)
45 { 33 {