|
9 | 9 | For the purposes of natural language processing ValueFromPipeline will be ignored. |
10 | 10 | |
11 | 11 | The order the parameters is declared takes precedence over Position attributes. |
| 12 | +.NOTES |
| 13 | + Each potential command can be thought of as a simple sentence with (mostly) natural syntax |
| 14 | + |
| 15 | + command <parametername> ...<parameterargument> (etc) |
| 16 | + |
| 17 | + either more natural or PowerShell syntax should be allowed, for example: |
| 18 | +
|
| 19 | + all functions can Quack { |
| 20 | + "quack" |
| 21 | + } |
| 22 | +
|
| 23 | + would map to the command all and the parameters -Function and -Can (with the arguments Quack and {"quack"}) |
| 24 | +
|
| 25 | + Assuming -Functions was a `[switch]` or an alias to a `[switch]`, it will match that `[switch]` and only that switch. |
| 26 | +
|
| 27 | + If -Functions was not a `[switch]`, it will match values from that point. |
| 28 | +
|
| 29 | + If the parameter type is not a list or PSObject, only the next parameter will be matched. |
| 30 | +
|
| 31 | + If the parameter type *is* a list or an PSObject, |
| 32 | + or ValueFromRemainingArguments is present and no named parameters were found, |
| 33 | + then all remaining arguments will be matched until the next named parameter is found. |
| 34 | + |
| 35 | + _Aliasing is important_ when working with a given parameter. |
| 36 | + The alias, _not_ the parameter name, will be what is mapped in .Parameters. |
12 | 37 | #> |
13 | 38 | param() |
14 | 39 |
|
@@ -67,6 +92,20 @@ if ($IsRightToLeft) { |
67 | 92 | } |
68 | 93 |
|
69 | 94 |
|
| 95 | +$commandElements = # Walk thru each command element |
| 96 | + @(foreach ($element in $commandElements) { |
| 97 | + # If the element is an array literal, expand it |
| 98 | + if ($element -is [Management.Automation.Language.ArrayLiteralAst]) { |
| 99 | + $element.Elements |
| 100 | + } else { |
| 101 | + # otherwise, include it as is. |
| 102 | + $element |
| 103 | + } |
| 104 | + }) |
| 105 | + |
| 106 | +# Now we have all of the words in a sentence. |
| 107 | +# We can still determine if an item in a list was in a list by inspecting it's parent. |
| 108 | + |
70 | 109 | $sentences = @() |
71 | 110 | if ($SpecificCommands) { |
72 | 111 | $potentialCommands = $SpecificCommands |
@@ -117,32 +156,6 @@ $potentialCommandIndex = -1 |
117 | 156 | foreach ($potentialCommand in $potentialCommands) { |
118 | 157 | $potentialCommandIndex++ |
119 | 158 | $commandName = $potentialCommandName = $potentialCommandNames[$potentialCommandIndex] |
120 | | - <# |
121 | | - Each potential command can be thought of as a simple sentence with (mostly) natural syntax |
122 | | - |
123 | | - command <parametername> ...<parameterargument> (etc) |
124 | | - |
125 | | - either more natural or PowerShell syntax should be allowed, for example: |
126 | | -
|
127 | | - all functions can Quack { |
128 | | - "quack" |
129 | | - } |
130 | | -
|
131 | | - would map to the command all and the parameters -Function and -Can (with the arguments Quack and {"quack"}) |
132 | | -
|
133 | | - Assuming -Functions was a `[switch]` or an alias to a `[switch]`, it will match that `[switch]` and only that switch. |
134 | | -
|
135 | | - If -Functions was not a `[switch]`, it will match values from that point. |
136 | | -
|
137 | | - If the parameter type is not a list or PSObject, only the next parameter will be matched. |
138 | | -
|
139 | | - If the parameter type *is* a list or an PSObject, |
140 | | - or ValueFromRemainingArguments is present and no named parameters were found, |
141 | | - then all remaining arguments will be matched until the next named parameter is found. |
142 | | - |
143 | | - _Aliasing is important_ when working with a given parameter. The alias, _not_ the parameter name, will be what is mapped. |
144 | | -
|
145 | | - #> |
146 | 159 |
|
147 | 160 | # Cache the potential parameters |
148 | 161 | $potentialParameters = $potentialCommand.Parameters |
|
0 commit comments