aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core/CommandLine/HelpCommand.cs
blob: 6a5ac183d203643b4154d0e4581346956bc29546 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// 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.

namespace WixToolset.Core.CommandLine
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading;
    using System.Threading.Tasks;
    using WixToolset.Extensibility;
    using WixToolset.Extensibility.Data;
    using WixToolset.Extensibility.Services;

    internal class HelpCommand : ICommandLineCommand
    {
        private static readonly ExtensionCommandLineSwitch[] BuiltInSwitches = new ExtensionCommandLineSwitch[]
        {
            new ExtensionCommandLineSwitch { Switch = "build", Description = "Build a wixlib, package or bundle." },
            new ExtensionCommandLineSwitch { Switch = "decompile", Description = "Decompile a package or bundle into source code." },
        };

        public HelpCommand(IEnumerable<IExtensionCommandLine> extensions, IWixBranding branding)
        {
            this.Extensions = extensions;
            this.Branding = branding;
        }

        public bool ShowLogo => true;

        public bool StopParsing => true;

        private IEnumerable<IExtensionCommandLine> Extensions { get; }

        private IWixBranding Branding { get; }

        public Task<int> ExecuteAsync(CancellationToken _)
        {
            var commandLineSwitches = new List<ExtensionCommandLineSwitch>(BuiltInSwitches);
            commandLineSwitches.AddRange(this.Extensions.SelectMany(e => e.CommandLineSwitches).OrderBy(s => s.Switch, StringComparer.Ordinal));

            Console.WriteLine();
            Console.WriteLine("Usage: wix [option]");
            Console.WriteLine("Usage: wix [command]");
            Console.WriteLine();
            Console.WriteLine("Options:");
            Console.WriteLine("  -h|--help         Show command line help.");
            Console.WriteLine("  --version         Display WiX Toolset version in use.");
            Console.WriteLine();

            Console.WriteLine("Commands:");
            foreach (var commandLineSwitch in commandLineSwitches)
            {
                Console.WriteLine("  {0,-17} {1}", commandLineSwitch.Switch, commandLineSwitch.Description);
            }

            Console.WriteLine();
            Console.WriteLine("Run 'wix [command] --help' for more information on a command.");
            Console.WriteLine();
            Console.WriteLine(this.Branding.ReplacePlaceholders("For more information see: [SupportUrl]"));

            return Task.FromResult(-1);
        }

        public bool TryParseArgument(ICommandLineParser parseHelper, string argument) => true; // eat any arguments
    }
}