summaryrefslogtreecommitdiff
path: root/src/internal/WixInternal.BaseBuildTasks.Sources/WixCommandLineBuilder.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/internal/WixInternal.BaseBuildTasks.Sources/WixCommandLineBuilder.cs')
-rw-r--r--src/internal/WixInternal.BaseBuildTasks.Sources/WixCommandLineBuilder.cs104
1 files changed, 104 insertions, 0 deletions
diff --git a/src/internal/WixInternal.BaseBuildTasks.Sources/WixCommandLineBuilder.cs b/src/internal/WixInternal.BaseBuildTasks.Sources/WixCommandLineBuilder.cs
new file mode 100644
index 00000000..d950bca9
--- /dev/null
+++ b/src/internal/WixInternal.BaseBuildTasks.Sources/WixCommandLineBuilder.cs
@@ -0,0 +1,104 @@
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.BaseBuildTasks
4{
5 using System;
6 using System.Collections.Generic;
7 using System.Globalization;
8 using System.IO;
9
10 using Microsoft.Build.Framework;
11 using Microsoft.Build.Utilities;
12
13 /// <summary>
14 /// Helper class for appending the command line arguments.
15 /// </summary>
16 public class WixCommandLineBuilder : CommandLineBuilder
17 {
18 internal const int Unspecified = -1;
19
20 /// <summary>
21 /// Append a switch to the command line if the value has been specified.
22 /// </summary>
23 /// <param name="switchName">Switch to append.</param>
24 /// <param name="value">Value specified by the user.</param>
25 public void AppendIfSpecified(string switchName, int value)
26 {
27 if (value != Unspecified)
28 {
29 this.AppendSwitchIfNotNull(switchName, value.ToString(CultureInfo.InvariantCulture));
30 }
31 }
32
33 /// <summary>
34 /// Append a switch to the command line if the condition is true.
35 /// </summary>
36 /// <param name="switchName">Switch to append.</param>
37 /// <param name="condition">Condition specified by the user.</param>
38 public void AppendIfTrue(string switchName, bool condition)
39 {
40 if (condition)
41 {
42 this.AppendSwitch(switchName);
43 }
44 }
45
46 /// <summary>
47 /// Append a switch to the command line if any values in the array have been specified.
48 /// </summary>
49 /// <param name="switchName">Switch to append.</param>
50 /// <param name="values">Values specified by the user.</param>
51 public void AppendArrayIfNotNull(string switchName, IEnumerable<ITaskItem> values)
52 {
53 if (values != null)
54 {
55 foreach (ITaskItem value in values)
56 {
57 this.AppendSwitchIfNotNull(switchName, value);
58 }
59 }
60 }
61
62 /// <summary>
63 /// Append a switch to the command line if any values in the array have been specified.
64 /// </summary>
65 /// <param name="switchName">Switch to append.</param>
66 /// <param name="values">Values specified by the user.</param>
67 public void AppendArrayIfNotNull(string switchName, IEnumerable<string> values)
68 {
69 if (values != null)
70 {
71 foreach (string value in values)
72 {
73 this.AppendSwitchIfNotNull(switchName, value);
74 }
75 }
76 }
77
78 /// <summary>
79 /// Append arbitrary text to the command-line if specified.
80 /// </summary>
81 /// <param name="textToAppend">Text to append.</param>
82 public void AppendTextIfNotNull(string textToAppend)
83 {
84 if (!String.IsNullOrEmpty(textToAppend))
85 {
86 this.AppendSpaceIfNotEmpty();
87 this.AppendTextUnquoted(textToAppend);
88 }
89 }
90
91 /// <summary>
92 /// Append arbitrary text to the command-line if specified.
93 /// </summary>
94 /// <param name="textToAppend">Text to append.</param>
95 public void AppendTextIfNotWhitespace(string textToAppend)
96 {
97 if (!String.IsNullOrWhiteSpace(textToAppend))
98 {
99 this.AppendSpaceIfNotEmpty();
100 this.AppendTextUnquoted(textToAppend);
101 }
102 }
103 }
104}