aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Converters/FormatCommand.cs
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2020-07-18 14:57:08 -0700
committerRob Mensching <rob@firegiant.com>2020-07-18 15:06:43 -0700
commite04caab11fb8f2cac4d575ef1e352221bd421586 (patch)
tree7c9752f17fab2793cabb07e73a42b52d573e1249 /src/WixToolset.Converters/FormatCommand.cs
parent92bb1d2d74e46714459c2d0fc23f185329745718 (diff)
downloadwix-e04caab11fb8f2cac4d575ef1e352221bd421586.tar.gz
wix-e04caab11fb8f2cac4d575ef1e352221bd421586.tar.bz2
wix-e04caab11fb8f2cac4d575ef1e352221bd421586.zip
Separate "format" from "convert"
Closes wixtoolset/issues#6215
Diffstat (limited to 'src/WixToolset.Converters/FormatCommand.cs')
-rw-r--r--src/WixToolset.Converters/FormatCommand.cs60
1 files changed, 60 insertions, 0 deletions
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 @@
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
3namespace WixToolset.Converters
4{
5 using System;
6 using System.Threading;
7 using System.Threading.Tasks;
8 using WixToolset.Extensibility.Services;
9
10 internal class FormatCommand : FixupCommandBase
11 {
12 private const string SettingsFileDefault = "wix.format.settings.xml";
13
14 public FormatCommand(IWixToolsetServiceProvider serviceProvider)
15 {
16 this.Messaging = serviceProvider.GetService<IMessaging>();
17 }
18
19 private IMessaging Messaging { get; }
20
21 public override Task<int> ExecuteAsync(CancellationToken cancellationToken)
22 {
23 if (this.ShowHelp)
24 {
25 DisplayHelp();
26 return Task.FromResult(-1);
27 }
28
29 var converter = new WixConverter(this.Messaging, this.IndentationAmount, this.ErrorsAsWarnings, this.IgnoreErrors);
30
31 this.ParseSettings(SettingsFileDefault);
32
33 var errors = base.Inspect(Inspector, cancellationToken);
34
35 return Task.FromResult(errors);
36
37 int Inspector(string file, bool fix)
38 {
39 return converter.FormatFile(file, fix);
40 }
41 }
42
43 private static void DisplayHelp()
44 {
45 Console.WriteLine();
46 Console.WriteLine("Usage: wix format [options] sourceFile [sourceFile ...]");
47 Console.WriteLine();
48 Console.WriteLine("Options:");
49 Console.WriteLine(" -h|--help Show command line help.");
50 Console.WriteLine(" --nologo Suppress displaying the logo information.");
51 Console.WriteLine(" -n|--dry-run Only display errors, do not update files.");
52 Console.WriteLine(" -r|--recurse Search for matching files in current dir and subdirs.");
53 Console.WriteLine(" -set1<file> Primary settings file.");
54 Console.WriteLine(" -set2<file> Secondary settings file (overrides primary).");
55 Console.WriteLine(" -indent:<n> Indentation multiple (overrides default of 4).");
56 Console.WriteLine();
57 Console.WriteLine(" sourceFile may use wildcards like *.wxs");
58 }
59 }
60}