Skip to content

Commit 225ac19

Browse files
committed
Update directives file with new content
1 parent 135fada commit 225ac19

File tree

1 file changed

+45
-7
lines changed

1 file changed

+45
-7
lines changed

docs/directives.md

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ The following directives cover the most common tweaking scenarios for cmdlet gen
9090
- [Cmdlet Rename](#Cmdlet-Rename)
9191
- [Cmdlet Aliasing](#Cmdlet-Aliasing)
9292
- [Cmdlet Suppression (Removal and Hiding)](#Cmdlet-Suppression)
93+
- [Suppress ShouldProcess (-WhatIf / -Confirm)](#Suppress-ShouldProcess)
9394
- [Parameter Rename](#Parameter-Rename)
9495
- [Parameter Aliasing](#Parameter-Aliasing)
9596
- [Parameter Hiding](#Parameter-Hiding)
@@ -209,8 +210,45 @@ directive:
209210
remove: true
210211
```
211212

213+
### Suppress ShouldProcess
214+
Some generated cmdlets include PowerShell `SupportsShouldProcess` semantics, exposing `-WhatIf` and `-Confirm`. This is appropriate for operations that can change state. However, certain service operations use non-GET HTTP methods (e.g., `POST /.../listKeys`) while remaining logically read-only. For these, displaying `-WhatIf` and `-Confirm` is misleading.
215+
216+
Use `suppress-should-process` to explicitly disable `SupportsShouldProcess` for selected cmdlets so that `-WhatIf` and `-Confirm` are not generated.
217+
218+
This directive was introduced to address scenarios like issue #704, where `listKeys` style operations were generated with unnecessary confirmation switches.
219+
220+
Usage:
221+
- Target the cmdlet with the usual command filters (`verb`, `subject`, `subject-prefix`, and/or `variant`).
222+
- Set `suppress-should-process: true` under `set`.
223+
224+
```yaml $false
225+
# Disable -WhatIf / -Confirm for a logically read-only list keys operation
226+
directive:
227+
- where:
228+
verb: Get
229+
subject: RedisEnterpriseDatabaseKey
230+
set:
231+
suppress-should-process: true
232+
```
233+
234+
Regex example:
235+
```yaml $false
236+
# Disable ShouldProcess for all Get-*Keys cmdlets whose subject ends with Keys
237+
directive:
238+
- where:
239+
verb: Get
240+
subject: (.*)Keys$
241+
set:
242+
suppress-should-process: true
243+
```
244+
245+
Notes:
246+
- Only applies to `command` targets.
247+
- Has no effect if the cmdlet does not already support ShouldProcess.
248+
- Use sparingly; only when you are certain the underlying operation is non-mutating.
249+
212250
### Parameter Rename
213-
To select a parameter you need to provide the `parameter-name`. Furthermore, if you want to target specific cmdlets you can provide the `subject-prefix`, `subject`, `verb`, and/or `variant` (i.e. parameter-set). For example:
251+
To select a parameter you need to provide the `parameter-name`. Furthermore, if you want to target specific cmdlets you can provide the `subject-prefix`, `subject`, `verb`, and/or `variant` (i.e. parameter-set name). For example:
214252
```yaml false
215253
# This will rename the parameter 'XYZName' from the cmdlet 'Get-Operation' to 'Name'.
216254
directive:
@@ -311,7 +349,7 @@ directive:
311349
```
312350

313351
### Model Cmdlet
314-
To generate a cmdlet for a model facilitating users in constructing complex objects, you can choose the model using `model-name`. The default cmdlet name generated will be New-Az[subject-prefix][model-name]Object, and you can customize it using `cmdlet-name`. For example:
352+
To generate a cmdlet for a model facilitating users in constructing complex objects, you can choose the model using `model-name`. The default cmdlet name generated will be New-Az[subject-prefix][model-name]Object (or equivalent based on module naming). For example:
315353
```yaml $false
316354
- model-cmdlet:
317355
- model-name: Workspace
@@ -345,7 +383,7 @@ directive:
345383
```
346384

347385
### Alias Removal
348-
If the option `--sanitize-names` or `--azure` is provided, AutoRest will make renames to cmdlets and parameters to remove redundancies. For example in the command `Get-VirtualMachine`, the parameter `VirtualMachineName` will be renamed to `Name`, and aliased to VirtualMachineName. It is possible to eliminate that alias by providing the action `clear-alias: true`:
386+
If the option `--sanitize-names` or `--azure` is provided, AutoRest will make renames to cmdlets and parameters to remove redundancies. For example in the command `Get-VirtualMachine`, the parameter `VirtualMachineName` may become just `Name`. To remove an automatically generated alias:
349387
```yaml $false
350388
directive:
351389
- where:
@@ -355,7 +393,7 @@ directive:
355393
The same can be done with cmdlets.
356394

357395
### Table Formatting
358-
This allows you to set the *table format* for a model. This updates the `.format.ps1xml` to have the format described below as opposed to the automatic table format that is created at build-time. For example, we are updating the format for a VirtualMachine model to only show the Name and ResourceGroup properties. It updates the column label for ResourceGroup to Resource Group and sets the columns widths for Name and ResourceGroup:
396+
This allows you to set the *table format* for a model. This updates the `.format.ps1xml` to have the format described below as opposed to the automatic table format that is created at build-time. For example:
359397
```yaml $false
360398
directive:
361399
- where:
@@ -394,7 +432,7 @@ directive:
394432
```
395433

396434
### Argument Completers
397-
For parameters, you can declare argument completers that will allow you to tab through the values when entering that parameter interactively. This allows you to declare a PowerShell script that will run to get the values for the completer. For example:
435+
For parameters, you can declare argument completers that will allow you to tab through the values when entering that parameter interactively. This allows you to declare a PowerShell script that will run to produce the possible values for that parameter.
398436
```yaml $false
399437
# The script should return a list of values.
400438
directive:
@@ -409,7 +447,7 @@ directive:
409447
The name and description are optional. They are currently unused properties that may be used in documentation generation in the future.
410448

411449
### Default Values
412-
For parameters, you can declare a default value script that will run to set the value for the parameter if it is not provided. Once this is declared for a parameter, that parameter will be made optional at build-time. For example:
450+
For parameters, you can declare a default value script that will run to set the value for the parameter if it is not provided. Once this is declared for a parameter, that parameter will be made optional (unless there are other constraints).
413451
```yaml $false
414452
# The script should return a value for the parameter.
415453
directive:
@@ -425,7 +463,7 @@ The name and description are optional. They are currently unused properties that
425463

426464
### Polymorphism
427465

428-
In swagger, polymorphism is recognized as the `discriminator` keyword. The model with this keyword will be the **base class**, and the models that use `allOf` to referece the base class are the **child class**.
466+
In swagger, polymorphism is recognized as the `discriminator` keyword. The model with this keyword will be the **base class**, and the models that use `allOf` to referece the base class are the **child classes**.
429467

430468
We will use two directives to support polymorphism:
431469

0 commit comments

Comments
 (0)