diff options
| author | Rob Mensching <rob@firegiant.com> | 2020-07-18 14:55:58 -0700 |
|---|---|---|
| committer | Rob Mensching <rob@firegiant.com> | 2020-07-18 15:03:11 -0700 |
| commit | f4cefb9ac9a6911ee0a1ad035e6ee50b7f28e5c5 (patch) | |
| tree | 7f06847dfdb75b5dd7720be4b4459adaa1fbf519 /src/WixToolset.Core/CommandLine | |
| parent | 6b21265e139513c1a242d8677b154fcc0e1dc7ef (diff) | |
| download | wix-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/WixToolset.Core/CommandLine')
| -rw-r--r-- | src/WixToolset.Core/CommandLine/CommandLine.cs | 4 | ||||
| -rw-r--r-- | src/WixToolset.Core/CommandLine/CommandLineParser.cs | 36 | ||||
| -rw-r--r-- | src/WixToolset.Core/CommandLine/HelpCommand.cs | 43 | ||||
| -rw-r--r-- | src/WixToolset.Core/CommandLine/VersionCommand.cs | 3 |
4 files changed, 54 insertions, 32 deletions
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 @@ | |||
| 3 | namespace WixToolset.Core.CommandLine | 3 | namespace 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 | } |
