Skip to content

Commit cb9315d

Browse files
StartAutomatingStartAutomating
authored andcommitted
Adding [inherit] transpiler (Fixes #235)
1 parent 3d0c409 commit cb9315d

File tree

1 file changed

+292
-0
lines changed

1 file changed

+292
-0
lines changed

docs/Inherit.md

Lines changed: 292 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,292 @@
1+
2+
Inherit
3+
-------
4+
### Synopsis
5+
Inherits a Command
6+
7+
---
8+
### Description
9+
10+
Inherits a given command.
11+
12+
This acts similarily to inheritance in Object Oriented programming.
13+
14+
By default, inheriting a function will join the contents of that function with the -ScriptBlock.
15+
16+
Your ScriptBlock will come first, so you can override any of the behavior of the underlying command.
17+
18+
You can "abstractly" inherit a command, that is, inherit only the command's parameters.
19+
20+
Inheritance can also be -Abstract.
21+
22+
When you use Abstract inheritance, you get only the function definition and header from the inherited command.
23+
24+
You can also -Override the command you are inheriting.
25+
26+
This will add an [Alias()] attribute containing the original command name.
27+
28+
One interesting example is overriding an application
29+
30+
---
31+
### Examples
32+
#### EXAMPLE 1
33+
```PowerShell
34+
Invoke-PipeScript {
35+
[inherit("Get-Command")]
36+
param()
37+
}
38+
```
39+
40+
#### EXAMPLE 2
41+
```PowerShell
42+
{
43+
[inherit("gh",Overload)]
44+
param()
45+
begin { "ABOUT TO CALL GH"}
46+
end { "JUST CALLED GH" }
47+
}.Transpile()
48+
```
49+
50+
#### EXAMPLE 3
51+
```PowerShell
52+
# Inherit Get-Transpiler abstractly and make it output the parameters passed in.
53+
{
54+
[inherit("Get-Transpiler", Abstract)]
55+
param() process { $psBoundParameters }
56+
}.Transpile()
57+
```
58+
59+
#### EXAMPLE 4
60+
```PowerShell
61+
{
62+
[inherit("Get-Transpiler", Dynamic, Abstract)]
63+
param()
64+
} | .>PipeScript
65+
```
66+
67+
---
68+
### Parameters
69+
#### **Command**
70+
71+
> **Type**: ```[String]```
72+
73+
> **Required**: true
74+
75+
> **Position**: 1
76+
77+
> **PipelineInput**:false
78+
79+
80+
81+
---
82+
#### **Abstract**
83+
84+
If provided, will abstractly inherit a function.
85+
This include the function's parameters, but not it's content
86+
It will also define a variable within a dynamicParam {} block that contains the base command.
87+
88+
89+
90+
> **Type**: ```[Switch]```
91+
92+
> **Required**: false
93+
94+
> **Position**: named
95+
96+
> **PipelineInput**:false
97+
98+
99+
100+
---
101+
#### **Override**
102+
103+
If provided, will set an alias on the function to replace the original command.
104+
105+
106+
107+
> **Type**: ```[Switch]```
108+
109+
> **Required**: false
110+
111+
> **Position**: named
112+
113+
> **PipelineInput**:false
114+
115+
116+
117+
---
118+
#### **Dynamic**
119+
120+
If set, will dynamic overload commands.
121+
This will use dynamic parameters instead of static parameters, and will use a proxy command to invoke the inherited command.
122+
123+
124+
125+
> **Type**: ```[Switch]```
126+
127+
> **Required**: false
128+
129+
> **Position**: named
130+
131+
> **PipelineInput**:false
132+
133+
134+
135+
---
136+
#### **Proxy**
137+
138+
If set, will always inherit commands as proxy commands.
139+
This is implied by -Dynamic.
140+
141+
142+
143+
> **Type**: ```[Switch]```
144+
145+
> **Required**: false
146+
147+
> **Position**: named
148+
149+
> **PipelineInput**:false
150+
151+
152+
153+
---
154+
#### **CommandType**
155+
156+
The Command Type. This can allow you to specify the type of command you are overloading.
157+
If the -CommandType includes aliases, and another command is also found, that command will be used.
158+
(this ensures you can continue to overload commands)
159+
160+
161+
162+
> **Type**: ```[String[]]```
163+
164+
> **Required**: false
165+
166+
> **Position**: named
167+
168+
> **PipelineInput**:false
169+
170+
171+
172+
---
173+
#### **ExcludeBlockType**
174+
175+
A list of block types to be excluded during a merge of script blocks.
176+
By default, no blocks will be excluded.
177+
178+
179+
180+
Valid Values:
181+
182+
* using
183+
* requires
184+
* help
185+
* header
186+
* param
187+
* dynamicParam
188+
* begin
189+
* process
190+
* end
191+
192+
193+
194+
> **Type**: ```[String[]]```
195+
196+
> **Required**: false
197+
198+
> **Position**: named
199+
200+
> **PipelineInput**:false
201+
202+
203+
204+
---
205+
#### **IncludeBlockType**
206+
207+
A list of block types to include during a merge of script blocks.
208+
209+
210+
211+
Valid Values:
212+
213+
* using
214+
* requires
215+
* help
216+
* header
217+
* param
218+
* dynamicParam
219+
* begin
220+
* process
221+
* end
222+
223+
224+
225+
> **Type**: ```[String[]]```
226+
227+
> **Required**: false
228+
229+
> **Position**: named
230+
231+
> **PipelineInput**:false
232+
233+
234+
235+
---
236+
#### **IncludeParameter**
237+
238+
A list of parameters to include. Can contain wildcards.
239+
If -IncludeParameter is provided without -ExcludeParameter, all other parameters will be excluded.
240+
241+
242+
243+
> **Type**: ```[String[]]```
244+
245+
> **Required**: false
246+
247+
> **Position**: named
248+
249+
> **PipelineInput**:false
250+
251+
252+
253+
---
254+
#### **ExcludeParameter**
255+
256+
A list of parameters to exclude. Can contain wildcards.
257+
Excluded parameters with default values will declare the default value at the beginnning of the command.
258+
259+
260+
261+
> **Type**: ```[String[]]```
262+
263+
> **Required**: false
264+
265+
> **Position**: named
266+
267+
> **PipelineInput**:false
268+
269+
270+
271+
---
272+
#### **ScriptBlock**
273+
274+
> **Type**: ```[ScriptBlock]```
275+
276+
> **Required**: false
277+
278+
> **Position**: named
279+
280+
> **PipelineInput**:true (ByValue)
281+
282+
283+
284+
---
285+
### Syntax
286+
```PowerShell
287+
Inherit [-Command] <String> [-Abstract] [-Override] [-Dynamic] [-Proxy] [-CommandType <String[]>] [-ExcludeBlockType <String[]>] [-IncludeBlockType <String[]>] [-IncludeParameter <String[]>] [-ExcludeParameter <String[]>] [-ScriptBlock <ScriptBlock>] [<CommonParameters>]
288+
```
289+
---
290+
291+
292+

0 commit comments

Comments
 (0)