diff options
Diffstat (limited to 'src/wixcop/CommandLine/WixCopCommandLineParser.cs')
-rw-r--r-- | src/wixcop/CommandLine/WixCopCommandLineParser.cs | 135 |
1 files changed, 0 insertions, 135 deletions
diff --git a/src/wixcop/CommandLine/WixCopCommandLineParser.cs b/src/wixcop/CommandLine/WixCopCommandLineParser.cs deleted file mode 100644 index f06decee..00000000 --- a/src/wixcop/CommandLine/WixCopCommandLineParser.cs +++ /dev/null | |||
@@ -1,135 +0,0 @@ | |||
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.Tools.WixCop.CommandLine | ||
4 | { | ||
5 | using System; | ||
6 | using System.Collections.Generic; | ||
7 | using WixToolset.Core; | ||
8 | using WixToolset.Extensibility.Data; | ||
9 | using WixToolset.Extensibility.Services; | ||
10 | using WixToolset.Tools.WixCop.Interfaces; | ||
11 | |||
12 | public sealed class WixCopCommandLineParser : IWixCopCommandLineParser | ||
13 | { | ||
14 | private bool fixErrors; | ||
15 | private int indentationAmount; | ||
16 | private readonly List<string> searchPatterns; | ||
17 | private readonly IWixToolsetServiceProvider serviceProvider; | ||
18 | private string settingsFile1; | ||
19 | private string settingsFile2; | ||
20 | private bool showHelp; | ||
21 | private bool showLogo; | ||
22 | private bool subDirectories; | ||
23 | |||
24 | public WixCopCommandLineParser(IWixToolsetServiceProvider serviceProvider) | ||
25 | { | ||
26 | this.serviceProvider = serviceProvider; | ||
27 | |||
28 | this.indentationAmount = 4; | ||
29 | this.searchPatterns = new List<string>(); | ||
30 | this.showLogo = true; | ||
31 | } | ||
32 | |||
33 | public ICommandLineArguments Arguments { get; set; } | ||
34 | |||
35 | public ICommandLineCommand ParseWixCopCommandLine() | ||
36 | { | ||
37 | this.Parse(); | ||
38 | |||
39 | if (this.showLogo) | ||
40 | { | ||
41 | AppCommon.DisplayToolHeader(); | ||
42 | Console.WriteLine(); | ||
43 | } | ||
44 | |||
45 | if (this.showHelp) | ||
46 | { | ||
47 | return new HelpCommand(); | ||
48 | } | ||
49 | |||
50 | return new ConvertCommand( | ||
51 | this.serviceProvider, | ||
52 | this.showLogo, | ||
53 | this.fixErrors, | ||
54 | this.indentationAmount, | ||
55 | this.searchPatterns, | ||
56 | this.subDirectories, | ||
57 | this.settingsFile1, | ||
58 | this.settingsFile2); | ||
59 | } | ||
60 | |||
61 | private void Parse() | ||
62 | { | ||
63 | this.showHelp = 0 == this.Arguments.Arguments.Length; | ||
64 | var parser = this.Arguments.Parse(); | ||
65 | |||
66 | while (!this.showHelp && | ||
67 | String.IsNullOrEmpty(parser.ErrorArgument) && | ||
68 | parser.TryGetNextSwitchOrArgument(out var arg)) | ||
69 | { | ||
70 | if (String.IsNullOrWhiteSpace(arg)) // skip blank arguments. | ||
71 | { | ||
72 | continue; | ||
73 | } | ||
74 | |||
75 | if (parser.IsSwitch(arg)) | ||
76 | { | ||
77 | if (!this.ParseArgument(parser, arg)) | ||
78 | { | ||
79 | parser.ErrorArgument = arg; | ||
80 | } | ||
81 | } | ||
82 | else | ||
83 | { | ||
84 | this.searchPatterns.Add(arg); | ||
85 | } | ||
86 | } | ||
87 | } | ||
88 | |||
89 | private bool ParseArgument(ICommandLineParser parser, string arg) | ||
90 | { | ||
91 | var parameter = arg.Substring(1); | ||
92 | |||
93 | switch (parameter.ToLowerInvariant()) | ||
94 | { | ||
95 | case "?": | ||
96 | this.showHelp = true; | ||
97 | return true; | ||
98 | case "f": | ||
99 | this.fixErrors = true; | ||
100 | return true; | ||
101 | case "nologo": | ||
102 | this.showLogo = false; | ||
103 | return true; | ||
104 | case "s": | ||
105 | this.subDirectories = true; | ||
106 | return true; | ||
107 | default: // other parameters | ||
108 | if (parameter.StartsWith("set1", StringComparison.Ordinal)) | ||
109 | { | ||
110 | this.settingsFile1 = parameter.Substring(4); | ||
111 | } | ||
112 | else if (parameter.StartsWith("set2", StringComparison.Ordinal)) | ||
113 | { | ||
114 | this.settingsFile2 = parameter.Substring(4); | ||
115 | } | ||
116 | else if (parameter.StartsWith("indent:", StringComparison.Ordinal)) | ||
117 | { | ||
118 | try | ||
119 | { | ||
120 | this.indentationAmount = Convert.ToInt32(parameter.Substring(7)); | ||
121 | } | ||
122 | catch | ||
123 | { | ||
124 | throw new ArgumentException("Invalid numeric argument.", parameter); | ||
125 | } | ||
126 | } | ||
127 | else | ||
128 | { | ||
129 | throw new ArgumentException("Invalid argument.", parameter); | ||
130 | } | ||
131 | return true; | ||
132 | } | ||
133 | } | ||
134 | } | ||
135 | } | ||