aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Converters/ConvertCommand.cs
blob: e29b176e4f0302554aa1d2ea1db4d1be84d9607f (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
// 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.Converters
{
    using System;
    using System.Threading;
    using System.Threading.Tasks;
    using WixToolset.Extensibility.Services;

    internal class ConvertCommand : FixupCommandBase
    {
        private const string SettingsFileDefault = "wix.convert.settings.xml";

        public ConvertCommand(IWixToolsetServiceProvider serviceProvider)
        {
            this.Messaging = serviceProvider.GetService<IMessaging>();
        }

        private IMessaging Messaging { get; }

        public override Task<int> ExecuteAsync(CancellationToken cancellationToken)
        {
            if (this.ShowHelp)
            {
                DisplayHelp();
                return Task.FromResult(-1);
            }

            this.ParseSettings(SettingsFileDefault);

            var converter = new WixConverter(this.Messaging, this.IndentationAmount, this.ErrorsAsWarnings, this.IgnoreErrors);

            var errors = base.Inspect(Inspector, cancellationToken);

            return Task.FromResult(errors);

            int Inspector(string file, bool fix)
            {
                return converter.ConvertFile(file, fix);
            }
        }

        private static void DisplayHelp()
        {
            Console.WriteLine();
            Console.WriteLine("Usage: wix convert [options] sourceFile [sourceFile ...]");
            Console.WriteLine();
            Console.WriteLine("Options:");
            Console.WriteLine("  -h|--help         Show command line help.");
            Console.WriteLine("  --nologo          Suppress displaying the logo information.");
            Console.WriteLine("  -n|--dry-run      Only display errors, do not update files.");
            Console.WriteLine("  -r|--recurse      Search for matching files in current dir and subdirs.");
            Console.WriteLine("  -set1<file>       Primary settings file.");
            Console.WriteLine("  -set2<file>       Secondary settings file (overrides primary).");
            Console.WriteLine("  -indent:<n>       Indentation multiple (overrides default of 4).");
            Console.WriteLine();
            Console.WriteLine("  sourceFile may use wildcards like *.wxs");
        }
    }
}