| 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.Converters |
| 4 | { |
| 5 | using System; |
| 6 | using System.Threading; |
| 7 | using System.Threading.Tasks; |
| 8 | using WixToolset.Extensibility.Data; |
| 9 | |
| 10 | internal class FormatCommand : FixupCommandBase |
| 11 | { |
| 12 | private const string SettingsFileDefault = "wix.format.settings.xml"; |
| 13 | |
| 14 | public FormatCommand(IServiceProvider serviceProvider) : base(serviceProvider) |
| 15 | { |
| 16 | } |
| 17 | |
| 18 | public override CommandLineHelp GetCommandLineHelp() |
| 19 | { |
| 20 | return new CommandLineHelp("Ensure consistent formatting of source code.", "format [options] sourceFile [sourceFile ...]") |
| 21 | { |
| 22 | Switches = new[] |
| 23 | { |
| 24 | new CommandLineHelpSwitch("--dry-run", "-n", "Only display errors, do not update files."), |
| 25 | new CommandLineHelpSwitch("--recurse", "-r", "Search for matching files in current dir and subdirs."), |
| 26 | new CommandLineHelpSwitch("-set1<file>", "Primary settings file."), |
| 27 | new CommandLineHelpSwitch("-set2<file>", "Secondary settings file (overrides primary)."), |
| 28 | new CommandLineHelpSwitch("-indent:<n>", "Indentation multiple (overrides default of 4)."), |
| 29 | }, |
| 30 | Notes = " sourceFile may use wildcards like *.wxs" |
| 31 | }; |
| 32 | } |
| 33 | |
| 34 | public override Task<int> ExecuteAsync(CancellationToken cancellationToken) |
| 35 | { |
| 36 | this.ParseSettings(SettingsFileDefault); |
| 37 | |
| 38 | var converter = new WixConverter(this.Messaging, this.IndentationAmount, this.ErrorsAsWarnings, this.IgnoreErrors); |
| 39 | |
| 40 | var errors = base.Inspect(Inspector, cancellationToken); |
| 41 | |
| 42 | return Task.FromResult(errors); |
| 43 | |
| 44 | int Inspector(string file, bool fix) |
| 45 | { |
| 46 | return converter.FormatFile(file, fix); |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | } |