@joebigelow / wix / commits / f4cefb9a

Display command-line help from Core and extensions

Closes wixtoolset/issues#6211

Rob Mensching committed Jul 18, 2020 at 14:55 UTC f4cefb9ac9a6911ee0a1ad035e6ee50b7f28e5c5
7 files changed +79 -56
src/WixToolset.Core.ExtensionCache/ExtensionCacheManagerCommand.cs
+16 -5
@@ -96,12 +96,15 @@ namespace WixToolset.Core.ExtensionCache
96 switch (parameter.ToLowerInvariant())
97 {
98 case "?":
99 + case "h":
100 + case "-help":
101 this.ShowHelp = true;
102 this.ShowLogo = true;
103 this.StopParsing = true;
104 return true;
105
106 case "nologo":
107 + case "-nologo":
108 this.ShowLogo = false;
109 return true;
110
@@ -158,13 +161,21 @@ namespace WixToolset.Core.ExtensionCache
161
162 private static void DisplayHelp()
163 {
161 - Console.WriteLine(" usage: wix.exe extension add|remove|list [extensionRef]");
164 Console.WriteLine();
163 - Console.WriteLine(" -g add/remove the extension for the current user");
164 - Console.WriteLine(" -nologo suppress displaying the logo information");
165 - Console.WriteLine(" -? this help information");
165 + Console.WriteLine("Usage: wix extension add|remove|list [extensionRef]");
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)");
179 }
180 }
181 }
src/WixToolset.Core.ExtensionCache/ExtensionCacheManagerExtensionCommandLine.cs
+4 -2
@@ -21,8 +21,10 @@ namespace WixToolset.Core.ExtensionCache
21
22 private IWixToolsetServiceProvider ServiceProvider { get; }
23
24 - // TODO: Do something with CommandLineSwitches
25 - public override IEnumerable<ExtensionCommandLineSwitch> CommandLineSwitches => base.CommandLineSwitches;
24 + public override IEnumerable<ExtensionCommandLineSwitch> CommandLineSwitches => new ExtensionCommandLineSwitch[]
25 + {
26 + new ExtensionCommandLineSwitch { Switch = "extension", Description = "Manage extension cache." },
27 + };
28
29 public override bool TryParseCommand(ICommandLineParser parser, string argument, out ICommandLineCommand command)
30 {
src/WixToolset.Core/CommandLine/CommandLine.cs
+2 -2
@@ -118,7 +118,7 @@ namespace WixToolset.Core.CommandLine
118 extension.PostParse();
119 }
120
121 - return command ?? new HelpCommand();
121 + return command ?? new HelpCommand(extensions);
122 }
123
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":
135 case "help":
136 case "-help":
137 - command = new HelpCommand();
137 + command = new HelpCommand(extensions);
138 break;
139
140 case "version":
src/WixToolset.Core/CommandLine/CommandLineParser.cs
+13 -23
@@ -27,7 +27,7 @@ namespace WixToolset.Core.CommandLine
27
28 public bool IsSwitch(string arg)
29 {
30 - return !String.IsNullOrEmpty(arg) && ('/' == arg[0] || '-' == arg[0]);
30 + return !String.IsNullOrEmpty(arg) && '-' == arg[0];
31 }
32
33 public string GetArgumentAsFilePathOrError(string argument, string fileType)
@@ -74,7 +74,7 @@ namespace WixToolset.Core.CommandLine
74
75 public string GetNextArgumentAsDirectoryOrError(string commandLineSwitch)
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 {
79 return directory;
80 }
@@ -85,7 +85,7 @@ namespace WixToolset.Core.CommandLine
85
86 public bool GetNextArgumentAsDirectoryOrError(string commandLineSwitch, IList<string> directories)
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 {
90 directories.Add(directory);
91 return true;
@@ -124,7 +124,14 @@ namespace WixToolset.Core.CommandLine
124
125 public bool TryGetNextSwitchOrArgument(out string arg)
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;
135 }
136
137 private bool TryGetNextNonSwitchArgumentOrError(out string arg)
@@ -139,24 +146,7 @@ namespace WixToolset.Core.CommandLine
146 return result;
147 }
148
142 - private static bool IsValidArg(string arg)
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)
149 + private bool TryGetDirectory(string commandlineSwitch, string arg, out string directory)
150 {
151 directory = null;
152
@@ -174,7 +164,7 @@ namespace WixToolset.Core.CommandLine
164 {
165 path = null;
166
177 - if (!IsValidArg(arg))
167 + if (String.IsNullOrEmpty(arg) || '-' == arg[0])
168 {
169 this.Messaging.Write(ErrorMessages.FilePathRequired(commandlineSwitch));
170 }
src/WixToolset.Core/CommandLine/HelpCommand.cs
+38 -5
@@ -3,27 +3,60 @@
3 namespace WixToolset.Core.CommandLine
4 {
5 using System;
6 + using System.Collections.Generic;
7 + using System.Linq;
8 using System.Threading;
9 using System.Threading.Tasks;
10 + using WixToolset.Extensibility;
11 using WixToolset.Extensibility.Data;
12 using WixToolset.Extensibility.Services;
13
14 internal class HelpCommand : ICommandLineCommand
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 +
27 public bool ShowLogo => true;
28
29 public bool StopParsing => true;
30
31 + private IEnumerable<IExtensionCommandLine> Extensions { get; }
32 +
33 public Task<int> ExecuteAsync(CancellationToken _)
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();
56
57 return Task.FromResult(-1);
58 }
59
24 - public bool TryParseArgument(ICommandLineParser parseHelper, string argument)
25 - {
26 - return true; // eat any arguments
27 - }
60 + public bool TryParseArgument(ICommandLineParser parseHelper, string argument) => true; // eat any arguments
61 }
62 }
src/WixToolset.Core/CommandLine/VersionCommand.cs
+1 -2
@@ -16,8 +16,7 @@ namespace WixToolset.Core.CommandLine
16
17 public Task<int> ExecuteAsync(CancellationToken cancellationToken)
18 {
19 - Console.WriteLine("wix version {0}", ThisAssembly.AssemblyInformationalVersion);
20 - Console.WriteLine();
19 + Console.WriteLine(ThisAssembly.AssemblyInformationalVersion);
20
21 return Task.FromResult(0);
22 }
src/WixToolset.Core/ExtensibilityServices/Messaging.cs
+5 -17
@@ -2,10 +2,7 @@
2
3 namespace WixToolset.Core.ExtensibilityServices
4 {
5 - using System;
5 using System.Collections.Generic;
7 - using System.Globalization;
8 - using System.Text;
6 using WixToolset.Data;
7 using WixToolset.Extensibility;
8 using WixToolset.Extensibility.Services;
@@ -13,8 +10,8 @@ namespace WixToolset.Core.ExtensibilityServices
10 internal class Messaging : IMessaging
11 {
12 private IMessageListener listener;
16 - private HashSet<int> suppressedWarnings = new HashSet<int>();
17 - private HashSet<int> warningsAsErrors = new HashSet<int>();
13 + private readonly HashSet<int> suppressedWarnings = new HashSet<int>();
14 + private readonly HashSet<int> warningsAsErrors = new HashSet<int>();
15
16 public bool EncounteredError { get; private set; }
17
@@ -26,20 +23,11 @@ namespace WixToolset.Core.ExtensibilityServices
23
24 public bool WarningsAsError { get; set; }
25
29 - public void ElevateWarningMessage(int warningNumber)
30 - {
31 - this.warningsAsErrors.Add(warningNumber);
32 - }
26 + public void ElevateWarningMessage(int warningNumber) => this.warningsAsErrors.Add(warningNumber);
27
34 - public void SetListener(IMessageListener listener)
35 - {
36 - this.listener = listener;
37 - }
28 + public void SetListener(IMessageListener listener) => this.listener = listener;
29
39 - public void SuppressWarningMessage(int warningNumber)
40 - {
41 - this.suppressedWarnings.Add(warningNumber);
42 - }
30 + public void SuppressWarningMessage(int warningNumber) => this.suppressedWarnings.Add(warningNumber);
31
32 public void Write(Message message)
33 {