From e04caab11fb8f2cac4d575ef1e352221bd421586 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Sat, 18 Jul 2020 14:57:08 -0700 Subject: Separate "format" from "convert" Closes wixtoolset/issues#6215 --- src/WixToolset.Converters/FormatCommand.cs | 60 ++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/WixToolset.Converters/FormatCommand.cs (limited to 'src/WixToolset.Converters/FormatCommand.cs') diff --git a/src/WixToolset.Converters/FormatCommand.cs b/src/WixToolset.Converters/FormatCommand.cs new file mode 100644 index 00000000..e9965df3 --- /dev/null +++ b/src/WixToolset.Converters/FormatCommand.cs @@ -0,0 +1,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 FormatCommand : FixupCommandBase + { + private const string SettingsFileDefault = "wix.format.settings.xml"; + + public FormatCommand(IWixToolsetServiceProvider serviceProvider) + { + this.Messaging = serviceProvider.GetService(); + } + + private IMessaging Messaging { get; } + + public override Task ExecuteAsync(CancellationToken cancellationToken) + { + if (this.ShowHelp) + { + DisplayHelp(); + return Task.FromResult(-1); + } + + var converter = new WixConverter(this.Messaging, this.IndentationAmount, this.ErrorsAsWarnings, this.IgnoreErrors); + + this.ParseSettings(SettingsFileDefault); + + var errors = base.Inspect(Inspector, cancellationToken); + + return Task.FromResult(errors); + + int Inspector(string file, bool fix) + { + return converter.FormatFile(file, fix); + } + } + + private static void DisplayHelp() + { + Console.WriteLine(); + Console.WriteLine("Usage: wix format [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 Primary settings file."); + Console.WriteLine(" -set2 Secondary settings file (overrides primary)."); + Console.WriteLine(" -indent: Indentation multiple (overrides default of 4)."); + Console.WriteLine(); + Console.WriteLine(" sourceFile may use wildcards like *.wxs"); + } + } +} -- cgit v1.2.3-55-g6feb