Skip to content

Commit 2881c48

Browse files
matkochlahma
authored andcommitted
fix: powershell argument ordering
1 parent 6b0527a commit 2881c48

File tree

4 files changed

+4
-8
lines changed

4 files changed

+4
-8
lines changed

source/Nuke.Common/Tools/PowerShell/PowerShell.Generated.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ public partial class PowerShellSettings : ToolOptions
6969
/// <summary>Sets the default execution policy for the current session and saves it in the <c>$env:PSExecutionPolicyPreference</c> environment variable. This parameter does not change the PowerShell execution policy that is set in the registry. For information about PowerShell execution policies, including a list of valid values, see <a href="https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies">about_Execution_Policies</a>.</summary>
7070
[Argument(Format = "-ExecutionPolicy {value}")] public string ExecutionPolicy => Get<string>(() => ExecutionPolicy);
7171
/// <summary>If the value of File is <c>-</c>, the command text is read from standard input. Running <c>powershell -File -</c> without redirected standard input starts a regular session. This is the same as not specifying the <c>File</c> parameter at all.<para/>If the value of File is a file path, the script runs in the local scope (<c>dot-sourced</c>), so that the functions and variables that the script creates are available in the current session. Enter the script file path and any parameters. <c>File</c> must be the last parameter in the command. All values typed after the <c>File</c> parameter are interpreted as the script file path and parameters passed to that script. Parameters passed to the script are passed as literal strings, after interpretation by the current shell. For example, if you are in cmd.exe and want to pass an environment variable value, you would use the cmd.exe syntax: <c>powershell.exe -File .\test.ps1 -TestParam %windir%</c>.<para/>In contrast, running <c>powershell.exe -File .\test.ps1 -TestParam $env:windir</c> in cmd.exe results in the script receiving the literal string <c>$env:windir</c> because it has no special meaning to the current cmd.exe shell. The <c>$env:windir</c> style of environment variable reference can be used inside a Command parameter, since there it will be interpreted as PowerShell code.<para/>Similarly, if you want to execute the same command from a Batch script, you would use <c>%~dp0</c> instead of <c>.\</c> or <c>$PSScriptRoot</c> to represent the current execution directory: <c>powershell.exe -File %~dp0test.ps1 -TestParam %windir%</c>. If you instead used <c>.\test.ps1</c>, PowerShell would throw an error because it cannot find the literal path <c>.\test.ps1</c>.<para/>When the value of <c>File</c> is a file path, <c>File</c> must be the last parameter in the command because any characters typed after the <c>File</c> parameter name are interpreted as the script file path followed by the script parameters.<para/>You can include the script parameters and values in the value of the <c>File</c> parameter. For example: <c>-File .\Get-Script.ps1 -Domain Central</c>.<para/>Typically, the switch parameters of a script are either included or omitted. For example, the following command uses the <c>All</c> parameter of the <c>Get-Script.ps1</c> script file: <c>-File .\Get-Script.ps1 -All</c>.<para/>In rare cases, you might need to provide a Boolean value for a parameter. It is not possible to pass an explicit boolean value for a switch parameter when running a script in this way. This limitation was removed in PowerShell 6 (<c>pwsh.exe</c>).</summary>
72-
[Argument(Format = "-File {value}", Position = 1)] public string File => Get<string>(() => File);
72+
[Argument(Format = "-File {value}")] public string File => Get<string>(() => File);
7373
/// <summary>Arguments passed in when using the <c>-File</c> option.</summary>
74-
[Argument(Format = "{value}", Position = 2)] public IReadOnlyList<string> FileArguments => Get<List<string>>(() => FileArguments);
74+
[Argument(Format = "{value}")] public IReadOnlyList<string> FileArguments => Get<List<string>>(() => FileArguments);
7575
/// <summary>Key-value pairs passed in when using the <c>-File</c> option.</summary>
7676
[Argument(Format = "-{key} {value}", Secret = false)] public IReadOnlyDictionary<string, string> FileKeyValueParameters => Get<Dictionary<string, string>>(() => FileKeyValueParameters);
7777
/// <summary>Executes the specified commands (and any parameters) as though they were typed at the PowerShell command prompt, and then exits, unless the <c>NoExit</c> parameter is specified.<para/>The value of Command can be <c>-</c>, a script block, or a string. If the value of <c>Command</c> is <c>-</c>, the command text is read from standard input.<para/>The <c>Command</c> parameter only accepts a script block for execution when it can recognize the value passed to <c>Command</c> as a <c>ScriptBlock</c> type. This is only possible when running <c>powershell.exe</c> from another PowerShell host. The <c>ScriptBlock</c> type may be contained in an existing variable, returned from an expression, or parsed by the PowerShell host as a literal script block enclosed in curly braces (<c>{}</c>), before being passed to <c>powershell.exe</c>.</summary>

source/Nuke.Common/Tools/PowerShell/PowerShell.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,12 @@
9999
"name": "File",
100100
"type": "string",
101101
"format": "-File {value}",
102-
"position": 1,
103102
"help": "If the value of File is <c>-</c>, the command text is read from standard input. Running <c>powershell -File -</c> without redirected standard input starts a regular session. This is the same as not specifying the <c>File</c> parameter at all.<para/>If the value of File is a file path, the script runs in the local scope (<c>dot-sourced</c>), so that the functions and variables that the script creates are available in the current session. Enter the script file path and any parameters. <c>File</c> must be the last parameter in the command. All values typed after the <c>File</c> parameter are interpreted as the script file path and parameters passed to that script. Parameters passed to the script are passed as literal strings, after interpretation by the current shell. For example, if you are in cmd.exe and want to pass an environment variable value, you would use the cmd.exe syntax: <c>powershell.exe -File .\\test.ps1 -TestParam %windir%</c>.<para/>In contrast, running <c>powershell.exe -File .\\test.ps1 -TestParam $env:windir</c> in cmd.exe results in the script receiving the literal string <c>$env:windir</c> because it has no special meaning to the current cmd.exe shell. The <c>$env:windir</c> style of environment variable reference can be used inside a Command parameter, since there it will be interpreted as PowerShell code.<para/>Similarly, if you want to execute the same command from a Batch script, you would use <c>%~dp0</c> instead of <c>.\\</c> or <c>$PSScriptRoot</c> to represent the current execution directory: <c>powershell.exe -File %~dp0test.ps1 -TestParam %windir%</c>. If you instead used <c>.\\test.ps1</c>, PowerShell would throw an error because it cannot find the literal path <c>.\\test.ps1</c>.<para/>When the value of <c>File</c> is a file path, <c>File</c> must be the last parameter in the command because any characters typed after the <c>File</c> parameter name are interpreted as the script file path followed by the script parameters.<para/>You can include the script parameters and values in the value of the <c>File</c> parameter. For example: <c>-File .\\Get-Script.ps1 -Domain Central</c>.<para/>Typically, the switch parameters of a script are either included or omitted. For example, the following command uses the <c>All</c> parameter of the <c>Get-Script.ps1</c> script file: <c>-File .\\Get-Script.ps1 -All</c>.<para/>In rare cases, you might need to provide a Boolean value for a parameter. It is not possible to pass an explicit boolean value for a switch parameter when running a script in this way. This limitation was removed in PowerShell 6 (<c>pwsh.exe</c>)."
104103
},
105104
{
106105
"name": "FileArguments",
107106
"type": "List<string>",
108107
"format": "{value}",
109-
"position": 2,
110108
"help": "Arguments passed in when using the <c>-File</c> option."
111109
},
112110
{

source/Nuke.Common/Tools/Pwsh/Pwsh.Generated.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ public partial class PwshSettings : ToolOptions
7373
/// <summary>Sets the default execution policy for the current session and saves it in the <c>$env:PSExecutionPolicyPreference</c> environment variable. This parameter does not change the PowerShell execution policy that is set in the registry. This parameter only applies to Windows computers. The <c>$env:PSExecutionPolicyPreference</c> environment variable does not exist on non-Windows platforms.</summary>
7474
[Argument(Format = "-ExecutionPolicy {value}")] public PwshExecutionPolicy ExecutionPolicy => Get<PwshExecutionPolicy>(() => ExecutionPolicy);
7575
/// <summary>If the value of File is <c>-</c>, the command text is read from standard input. Running <c>pwsh -File -</c> without redirected standard input starts a regular session. This is the same as not specifying the File parameter at all.<para/>This is the default parameter if no parameters are present but values are present in the command line. The specified script runs in the local scope ("dot-sourced"), so that the functions and variables that the script creates are available in the current session. Enter the script file path and any parameters. File must be the last parameter in the command, because all characters typed after the File parameter name are interpreted as the script file path followed by the script parameters.</summary>
76-
[Argument(Format = "-File {value}", Position = 1)] public string File => Get<string>(() => File);
76+
[Argument(Format = "-File {value}")] public string File => Get<string>(() => File);
7777
/// <summary>Arguments passed in when using the <c>-File</c> option.</summary>
78-
[Argument(Format = "{value}", Position = 2)] public IReadOnlyList<string> FileArguments => Get<List<string>>(() => FileArguments);
78+
[Argument(Format = "{value}")] public IReadOnlyList<string> FileArguments => Get<List<string>>(() => FileArguments);
7979
/// <summary>Executes the specified commands (and any parameters) as though they were typed at the PowerShell command prompt, and then exits, unless the <c>NoExit</c> parameter is specified.<para/>The value of Command can be <c>-</c>, a script block, or a string. If the value of Command is <c>-</c>, the command text is read from standard input.<para/>The Command parameter only accepts a script block for execution when it can recognize the value passed to Command as a ScriptBlock type. This is only possible when running pwsh from another PowerShell host. The ScriptBlock type may be contained in an existing variable, returned from an expression, or parsed by the PowerShell host as a literal script block enclosed in curly braces (<c>{}</c>), before being passed to pwsh.</summary>
8080
[Argument(Format = "-Command {value}")] public string Command => Get<string>(() => Command);
8181
/// <summary>Overrides the system-wide <c>powershell.config.json</c> settings file for the session. By default, system-wide settings are read from the powershell.config.json in the $PSHOME directory. Note that these settings are not used by the endpoint specified by the <c>-ConfigurationName</c> argument.</summary>

source/Nuke.Common/Tools/Pwsh/Pwsh.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,12 @@
105105
"name": "File",
106106
"type": "string",
107107
"format": "-File {value}",
108-
"position": 1,
109108
"help": "If the value of File is <c>-</c>, the command text is read from standard input. Running <c>pwsh -File -</c> without redirected standard input starts a regular session. This is the same as not specifying the File parameter at all.<para/>This is the default parameter if no parameters are present but values are present in the command line. The specified script runs in the local scope (\"dot-sourced\"), so that the functions and variables that the script creates are available in the current session. Enter the script file path and any parameters. File must be the last parameter in the command, because all characters typed after the File parameter name are interpreted as the script file path followed by the script parameters."
110109
},
111110
{
112111
"name": "FileArguments",
113112
"type": "List<string>",
114113
"format": "{value}",
115-
"position": 2,
116114
"help": "Arguments passed in when using the <c>-File</c> option."
117115
},
118116
{

0 commit comments

Comments
 (0)