fix powershell -version
and help (#4958)
PowerShell -v behavior updated to align with other tools like git, curl, and bash where args after -v are silently ignored. Built-in help updated to reflect changes we've made to the console host in PSCore6 removing unsupported parameters. * [feature] removed test that is no longer valid due to change in -version behavior to return error * [feature] fixed `-v X` so that it errors out correctly with proper exit code updated test to catch this * [feature] address PR feedback * [feature] make -v have behavior consistent with other tools like git, curl, bash where args after -v are ignored removed duplicate but not exactly help text that wasn't being used in the resource file removed parameters from help that are not support in PSCore6
This commit is contained in:
parent
a82f6376ab
commit
2e901e53c3
|
@ -400,15 +400,9 @@ namespace Microsoft.PowerShell
|
|||
|
||||
private void ShowHelp()
|
||||
{
|
||||
Dbg.Assert(_helpText != null, "_helpText should not be null");
|
||||
_hostUI.WriteLine("");
|
||||
if (_helpText == null)
|
||||
{
|
||||
_hostUI.WriteLine(CommandLineParameterParserStrings.DefaultHelp);
|
||||
}
|
||||
else
|
||||
{
|
||||
_hostUI.Write(_helpText);
|
||||
}
|
||||
_hostUI.Write(_helpText);
|
||||
_hostUI.WriteLine("");
|
||||
}
|
||||
|
||||
|
@ -548,17 +542,9 @@ namespace Microsoft.PowerShell
|
|||
_noInteractive = true;
|
||||
_skipUserInit = true;
|
||||
_noExit = false;
|
||||
|
||||
++i;
|
||||
if (i < args.Length)
|
||||
{
|
||||
WriteCommandLineError(string.Format(CultureInfo.CurrentCulture, CommandLineParameterParserStrings.DeprecatedVersionParameter,args[i]));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (MatchSwitch(switchKey, "help", "h") || MatchSwitch(switchKey, "?", "?"))
|
||||
else if (MatchSwitch(switchKey, "help", "h") || MatchSwitch(switchKey, "?", "?"))
|
||||
{
|
||||
_showHelp = true;
|
||||
_abortStartup = true;
|
||||
|
|
|
@ -200,7 +200,7 @@ namespace Microsoft.PowerShell
|
|||
// Alternatively, we could call s_theConsoleHost.UI.WriteLine(s_theConsoleHost.Version.ToString());
|
||||
// or start up the engine and retrieve the information via $psversiontable.GitCommitId
|
||||
// but this returns the semantic version and avoids executing a script
|
||||
s_theConsoleHost.UI.WriteLine("powershell " + PSVersionInfo.GitCommitId);
|
||||
s_theConsoleHost.UI.WriteLine("PowerShell " + PSVersionInfo.GitCommitId);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -129,89 +129,6 @@
|
|||
<data name="UnknownParameter" xml:space="preserve">
|
||||
<value>Unrecognized parameter: '{0}'.</value>
|
||||
</data>
|
||||
<data name="DefaultHelp" xml:space="preserve">
|
||||
<value>PowerShell[.exe] [-PSConsoleFile <file> | -Version <version>]
|
||||
[-NoLogo] [-NoExit] [-NoProfile] [-NonInteractive] [-STA]
|
||||
[-OutputFormat {Text | XML}] [-InputFormat {Text | XML}]
|
||||
[-ConfigurationName <string>]
|
||||
[-File fileName [arguments...]] [-ExecutionPolicy <ExecutionPolicy>]
|
||||
[-Command { - | <script-block> [-args <arg-array>]
|
||||
| <string> [<CommandParameters>] } ]
|
||||
|
||||
PowerShell[.exe] -Help | -? | /?
|
||||
|
||||
-PSConsoleFile
|
||||
Loads the specified PowerShell console file. To create a console
|
||||
file, use Export-Console in PowerShell.
|
||||
|
||||
-Version
|
||||
Starts the specified version of PowerShell.
|
||||
|
||||
-NoLogo
|
||||
Hides the copyright banner at startup.
|
||||
|
||||
-NoExit
|
||||
Does not exit after running startup commands.
|
||||
|
||||
-NoProfile
|
||||
Does not use the user profile.
|
||||
|
||||
-NonInteractive
|
||||
Does not present an interactive prompt to the user.
|
||||
|
||||
-STA
|
||||
Uses a single-threaded apartment for the execution thread.
|
||||
|
||||
-OutputFormat
|
||||
Determines how output from PowerShell is formatted. Valid values
|
||||
are "Text" (text strings) or "XML" (serialized CLIXML format).
|
||||
|
||||
-InputFormat
|
||||
Describes the format of data sent to PowerShell. Valid values are
|
||||
"Text" (text strings) or "XML" (serialized CLIXML format).
|
||||
|
||||
-ConfigurationName
|
||||
Specifies a configuration endpoint in which PowerShell is run.
|
||||
This can be any endpoint registered on the local machine including the
|
||||
default PowerShell remoting endpoints or a custom endpoint having
|
||||
specific user role capabilities.
|
||||
|
||||
-Command
|
||||
Executes the specified commands (and any parameters) as though they were
|
||||
typed at the PowerShell command prompt, and then exits, unless
|
||||
NoExit is specified. The value of Command can be "-", a string. or a
|
||||
script block.
|
||||
|
||||
If the value of Command is "-", the command text is read from standard
|
||||
input.
|
||||
|
||||
Script blocks must be enclosed in braces ({}). You can specify a script
|
||||
block only when running PowerShell.exe in PowerShell. The results
|
||||
of the script are returned to the parent shell as deserialized XML objects,
|
||||
not live objects.
|
||||
|
||||
If the value of Command is a string, Command must be the last parameter
|
||||
in the command , because any characters typed after the command are
|
||||
interpreted as the command arguments.
|
||||
To write a string that runs a PowerShell command, use the format:
|
||||
"& {<command>}"
|
||||
where the quotation marks indicate a string and the invoke operator (&)
|
||||
causes the command to be run.
|
||||
|
||||
-Help, -?, /?
|
||||
Shows this message. If you are typing a PowerShell.exe command in Windows
|
||||
PowerShell, prepend the command parameters with a hyphen (-), not a forward
|
||||
slash (/). You can use either a hyphen or forward slash in Cmd.exe.
|
||||
|
||||
|
||||
EXAMPLES
|
||||
PowerShell -PSConsoleFile SqlSnapin.Psc1
|
||||
PowerShell -version 1.0 -NoLogo -InputFormat text -OutputFormat XML
|
||||
PowerShell -ConfigurationName AdminRoles
|
||||
PowerShell -Command {Get-EventLog -LogName security}
|
||||
PowerShell -Command "& {Get-EventLog -LogName security}"
|
||||
</value>
|
||||
</data>
|
||||
<data name="TooManyParametersToCommand" xml:space="preserve">
|
||||
<value>'-' was specified with the -Command parameter; no other arguments to -Command are permitted.</value>
|
||||
</data>
|
||||
|
@ -272,7 +189,4 @@ EXAMPLES
|
|||
<data name="InvalidArgument" xml:space="preserve">
|
||||
<value>Invalid argument '{0}', did you mean:</value>
|
||||
</data>
|
||||
<data name="DeprecatedVersionParameter" xml:space="preserve">
|
||||
<value>Usage of '-Version {0}' is not supported. '-Version' currently only returns the current PowerShell version.</value>
|
||||
</data>
|
||||
</root>
|
||||
|
|
|
@ -122,8 +122,8 @@
|
|||
Copyright (C) Microsoft Corporation. All rights reserved.</value>
|
||||
</data>
|
||||
<data name="ShellHelp" xml:space="preserve">
|
||||
<value>PowerShell[.exe] [-PSConsoleFile <file> | -Version <version>]
|
||||
[-NoLogo] [-NoExit] [-Sta] [-Mta] [-NoProfile] [-NonInteractive] [-Interactive]
|
||||
<value>PowerShell[.exe] [-Version] [-NoLogo] [-NoExit]
|
||||
[-NoProfile] [-NonInteractive] [-Interactive]
|
||||
[-InputFormat {Text | XML}] [-OutputFormat {Text | XML}]
|
||||
[-WindowStyle <style>] [-EncodedCommand <Base64EncodedCommand>]
|
||||
[-ConfigurationName <string>]
|
||||
|
@ -133,13 +133,9 @@ Copyright (C) Microsoft Corporation. All rights reserved.</value>
|
|||
|
||||
PowerShell[.exe] -Help | -? | /?
|
||||
|
||||
-PSConsoleFile
|
||||
Loads the specified PowerShell console file. To create a console
|
||||
file, use Export-Console in PowerShell.
|
||||
|
||||
-Version
|
||||
Starts the specified version of PowerShell.
|
||||
Enter a version number with the parameter, such as "-version 2.0".
|
||||
Shows the version of PowerShell and exits.
|
||||
Additional arguments are ignored.
|
||||
|
||||
-NoLogo
|
||||
Hides the copyright banner at startup.
|
||||
|
@ -147,13 +143,6 @@ PowerShell[.exe] -Help | -? | /?
|
|||
-NoExit
|
||||
Does not exit after running startup commands.
|
||||
|
||||
-Sta
|
||||
Starts the shell using a single-threaded apartment.
|
||||
Single-threaded apartment (STA) is the default.
|
||||
|
||||
-Mta
|
||||
Start the shell using a multithreaded apartment.
|
||||
|
||||
-NoProfile
|
||||
Does not load the PowerShell profile.
|
||||
|
||||
|
@ -228,8 +217,7 @@ PowerShell[.exe] -Help | -? | /?
|
|||
slash (/). You can use either a hyphen or forward slash in Cmd.exe.
|
||||
|
||||
EXAMPLES
|
||||
PowerShell -PSConsoleFile SqlSnapIn.Psc1
|
||||
PowerShell -version 2.0 -NoLogo -InputFormat text -OutputFormat XML
|
||||
PowerShell -Version
|
||||
PowerShell -ConfigurationName AdminRoles
|
||||
PowerShell -Command {Get-EventLog -LogName security}
|
||||
PowerShell -Command "& {Get-EventLog -LogName security}"
|
||||
|
@ -239,6 +227,6 @@ EXAMPLES
|
|||
$command = 'dir "c:\program files" '
|
||||
$bytes = [System.Text.Encoding]::Unicode.GetBytes($command)
|
||||
$encodedCommand = [Convert]::ToBase64String($bytes)
|
||||
powershell.exe -encodedCommand $encodedCommand</value>
|
||||
powershell -encodedCommand $encodedCommand</value>
|
||||
</data>
|
||||
</root>
|
||||
|
|
|
@ -165,26 +165,15 @@ Describe "ConsoleHost unit tests" -tags "Feature" {
|
|||
$actual | Should Be $expected
|
||||
}
|
||||
|
||||
It "-Version should return the engine version" {
|
||||
It "-Version should return the engine version using: -version <value>" -TestCases @(
|
||||
@{value = ""},
|
||||
@{value = "2"},
|
||||
@{value = "-command 1-1"}
|
||||
) {
|
||||
$currentVersion = "powershell " + $PSVersionTable.GitCommitId.ToString()
|
||||
$observed = & $powershell -version
|
||||
$observed = & $powershell -version $value 2>&1
|
||||
$observed | should be $currentVersion
|
||||
}
|
||||
|
||||
It "-Version should ignore other parameters" {
|
||||
$currentVersion = "powershell " + $PSVersionTable.GitCommitId.ToString()
|
||||
$observed = & $powershell -version -command get-date
|
||||
# no extraneous output
|
||||
$observed | should be $currentVersion
|
||||
}
|
||||
|
||||
It "-Version should write an error if a value is present" {
|
||||
$versionValue = "abrakadabra"
|
||||
$tempFile = Join-Path $testdrive "expectedError.txt"
|
||||
$observed = & $powershell -version $versionValue > $tempFile
|
||||
$expectedError = (Get-Content $tempFile)[0]
|
||||
|
||||
$expectedError | Should Match $versionValue
|
||||
$LASTEXITCODE | Should Be 0
|
||||
}
|
||||
|
||||
It "-File should be default parameter" {
|
||||
|
|
Loading…
Reference in a new issue