forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWriteFormatDataCommand.cs
More file actions
151 lines (138 loc) · 3.96 KB
/
Copy pathWriteFormatDataCommand.cs
File metadata and controls
151 lines (138 loc) · 3.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/********************************************************************++
Copyright (c) Microsoft Corporation. All rights reserved.
--********************************************************************/
using System;
using System.Management.Automation;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
namespace Microsoft.PowerShell.Commands
{
/// <summary>
/// Cmdlet used to write a collection of formatting directives to
/// an XML file
/// </summary>
[Cmdlet(VerbsData.Export, "FormatData", DefaultParameterSetName = "ByPath", HelpUri = "https://go.microsoft.com/fwlink/?LinkID=144302")]
public class ExportFormatDataCommand : PSCmdlet
{
private ExtendedTypeDefinition[] _typeDefinition;
/// <summary>
/// type definition to include in export
/// </summary>
[Parameter(Mandatory = true, ValueFromPipeline = true)]
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
public ExtendedTypeDefinition[] InputObject
{
get
{
return _typeDefinition;
}
set
{
_typeDefinition = value;
}
}
private string _filepath;
/// <summary>
/// Path of the XML file
/// </summary>
[Parameter(ParameterSetName = "ByPath", Mandatory = true)]
[Alias("FilePath")]
public String Path
{
get
{
return _filepath;
}
set
{
_filepath = value;
}
}
/// <summary>
/// Literal path of the XML file
/// </summary>
[Parameter(ParameterSetName = "ByLiteralPath", Mandatory = true)]
[Alias("PSPath")]
public String LiteralPath
{
get
{
return _filepath;
}
set
{
_filepath = value;
_isLiteralPath = true;
}
}
private bool _isLiteralPath = false;
private List<ExtendedTypeDefinition> _typeDefinitions = new List<ExtendedTypeDefinition>();
private bool _force;
/// <summary>
/// Force writing a file
/// </summary>
[Parameter()]
public SwitchParameter Force
{
get
{
return _force;
}
set
{
_force = value;
}
}
/// <summary>
/// Do not overwrite file if exists
/// </summary>
[Parameter()]
[Alias("NoOverwrite")]
public SwitchParameter NoClobber
{
get
{
return _noclobber;
}
set
{
_noclobber = value;
}
}
private bool _noclobber;
/// <summary>
/// Include scriptblocks for export
/// </summary>
[Parameter()]
public SwitchParameter IncludeScriptBlock
{
get
{
return _includescriptblock;
}
set
{
_includescriptblock = value;
}
}
private bool _includescriptblock;
/// <summary>
/// Adds the type to the collection
/// </summary>
protected override void ProcessRecord()
{
foreach (ExtendedTypeDefinition typedef in _typeDefinition)
{
_typeDefinitions.Add(typedef);
}
}
/// <summary>
/// writes out the formatting directives from the
/// collection to the specified XML file
/// </summary>
protected override void EndProcessing()
{
FormatXmlWriter.WriteToPs1Xml(this, _typeDefinitions, _filepath, _force, _noclobber, _includescriptblock, _isLiteralPath);
}
}
}