| 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 | |
| 3 | namespace WixToolset.Harvesters |
| 4 | { |
| 5 | using System; |
| 6 | using System.Collections; |
| 7 | using System.Collections.Generic; |
| 8 | using System.Diagnostics; |
| 9 | using System.Threading; |
| 10 | using System.Threading.Tasks; |
| 11 | using WixToolset.Extensibility; |
| 12 | using WixToolset.Extensibility.Data; |
| 13 | using WixToolset.Extensibility.Services; |
| 14 | using WixToolset.Harvesters.Data; |
| 15 | using WixToolset.Harvesters.Extensibility; |
| 16 | |
| 17 | internal class HelpCommand : BaseCommandLineCommand |
| 18 | { |
| 19 | const string HelpMessageOptionFormat = " {0,-7} {1}"; |
| 20 | |
| 21 | public HelpCommand(IList<IHeatExtension> extensions) |
| 22 | { |
| 23 | this.Extensions = extensions; |
| 24 | } |
| 25 | |
| 26 | private IList<IHeatExtension> Extensions { get; } |
| 27 | |
| 28 | public override CommandLineHelp GetCommandLineHelp() |
| 29 | { |
| 30 | return null; |
| 31 | } |
| 32 | |
| 33 | public override Task<int> ExecuteAsync(CancellationToken cancellationToken) |
| 34 | { |
| 35 | var exitCode = this.DisplayHelp(); |
| 36 | return Task.FromResult(exitCode); |
| 37 | } |
| 38 | |
| 39 | public static void DisplayToolHeader() |
| 40 | { |
| 41 | var wixcopAssembly = typeof(HelpCommand).Assembly; |
| 42 | var fv = FileVersionInfo.GetVersionInfo(wixcopAssembly.Location); |
| 43 | |
| 44 | Console.WriteLine("WiX Toolset Harvester version {0}", fv.ProductVersion); |
| 45 | Console.WriteLine("Copyright (C) .NET Foundation and contributors. All rights reserved."); |
| 46 | Console.WriteLine(); |
| 47 | } |
| 48 | |
| 49 | public override bool TryParseArgument(ICommandLineParser parser, string argument) |
| 50 | { |
| 51 | this.StopParsing = true; |
| 52 | return true; |
| 53 | } |
| 54 | |
| 55 | private int DisplayHelp() |
| 56 | { |
| 57 | DisplayToolHeader(); |
| 58 | |
| 59 | // output the harvest types alphabetically |
| 60 | SortedList harvestOptions = new SortedList(); |
| 61 | foreach (var heatExtension in this.Extensions) |
| 62 | { |
| 63 | foreach (HeatCommandLineOption commandLineOption in heatExtension.CommandLineTypes) |
| 64 | { |
| 65 | harvestOptions.Add(commandLineOption.Option, commandLineOption); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | harvestOptions.Add("-nologo", new HeatCommandLineOption("-nologo", "skip printing heat logo information")); |
| 70 | harvestOptions.Add("-indent <N>", new HeatCommandLineOption("-indent <N>", "indentation multiple (overrides default of 4)")); |
| 71 | harvestOptions.Add("-o[ut]", new HeatCommandLineOption("-out", "specify output file (default: write to current directory)")); |
| 72 | harvestOptions.Add("-sw<N>", new HeatCommandLineOption("-sw<N>", "suppress all warnings or a specific message ID\r\n (example: -sw1011 -sw1012)")); |
| 73 | harvestOptions.Add("-swall", new HeatCommandLineOption("-swall", "suppress all warnings (deprecated)")); |
| 74 | harvestOptions.Add("-v", new HeatCommandLineOption("-v", "verbose output")); |
| 75 | harvestOptions.Add("-wx[N]", new HeatCommandLineOption("-wx[N]", "treat all warnings or a specific message ID as an error\r\n (example: -wx1011 -wx1012)")); |
| 76 | harvestOptions.Add("-wxall", new HeatCommandLineOption("-wxall", "treat all warnings as errors (deprecated)")); |
| 77 | |
| 78 | foreach (HeatCommandLineOption commandLineOption in harvestOptions.Values) |
| 79 | { |
| 80 | if (!commandLineOption.Option.StartsWith("-")) |
| 81 | { |
| 82 | Console.WriteLine(HelpMessageOptionFormat, commandLineOption.Option, commandLineOption.Description); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | Console.WriteLine(); |
| 87 | Console.WriteLine("Options:"); |
| 88 | |
| 89 | foreach (HeatCommandLineOption commandLineOption in harvestOptions.Values) |
| 90 | { |
| 91 | if (commandLineOption.Option.StartsWith("-")) |
| 92 | { |
| 93 | Console.WriteLine(HelpMessageOptionFormat, commandLineOption.Option, commandLineOption.Description); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | Console.WriteLine(HelpMessageOptionFormat, "-? | -help", "this help information"); |
| 98 | Console.WriteLine("For more information see: https://wixtoolset.org/"); |
| 99 | |
| 100 | return 1; |
| 101 | } |
| 102 | } |
| 103 | } |