Merge pull request #9528 from SteveL-MSFT/login-shell

Add support for `-l` to pwsh so that it is compatible with POSIX shell expectations
This commit is contained in:
Andrew 2019-05-07 11:55:45 -07:00 committed by GitHub
commit e3e37a8e35
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 62 additions and 18 deletions

View file

@ -173,28 +173,29 @@ namespace Microsoft.PowerShell
private const int MaxPipePathLengthMacOS = 104;
internal static string[] validParameters = {
"version",
"nologo",
"noexit",
#if STAMODE
"sta",
"mta",
#endif
"noprofile",
"noninteractive",
"inputformat",
"outputformat",
"windowstyle",
"encodedcommand",
"configurationname",
"file",
"executionpolicy",
"command",
"settingsfile",
"configurationname",
"custompipename",
"encodedcommand",
"executionpolicy",
"file",
"help",
"workingdirectory",
"inputformat",
"loadprofile",
"noexit",
"nologo",
"noninteractive",
"noprofile",
"outputformat",
"removeworkingdirectorytrailingcharacter",
"custompipename"
"settingsfile",
"version",
"windowstyle",
"workingdirectory"
};
internal CommandLineParameterParser(PSHostUserInterface hostUI, string bannerText, string helpText)
@ -742,6 +743,10 @@ namespace Microsoft.PowerShell
_noExit = true;
noexitSeen = true;
}
else if (MatchSwitch(switchKey, "loadprofile", "l"))
{
_skipUserInit = false;
}
else if (MatchSwitch(switchKey, "noprofile", "nop"))
{
_skipUserInit = true;

View file

@ -131,7 +131,7 @@ Type 'help' to get help.</value>
[-ConfigurationName &lt;string&gt;] [-CustomPipeName &lt;string&gt;]
[-EncodedCommand &lt;Base64EncodedCommand&gt;]
[-ExecutionPolicy &lt;ExecutionPolicy&gt;] [-InputFormat {Text | XML}]
[-Interactive] [-NoExit] [-NoLogo] [-NonInteractive] [-NoProfile]
[-Interactive] [-LoadProfile] [-NoExit] [-NoLogo] [-NonInteractive] [-NoProfile]
[-OutputFormat {Text | XML}] [-Version] [-WindowStyle &lt;style&gt;]
[-WorkingDirectory &lt;directoryPath&gt;]
@ -176,11 +176,11 @@ All parameters are case-insensitive.</value>
Example: pwsh -ConfigurationName AdminRoles
-CustomPipeName
Specifies the name to use for an additional IPC server (named pipe) used for debugging
Specifies the name to use for an additional IPC server (named pipe) used for debugging
and other cross-process communication. This offers a predictable mechanism for connecting
to other PowerShell instances. Typically used with the CustomPipeName parameter on Enter-PSHostProcess.
Example:
Example:
# PowerShell instance 1
pwsh -CustomPipeName mydebugpipe
# PowerShell instance 2
@ -224,6 +224,9 @@ All parameters are case-insensitive.</value>
-Interactive | -i
Present an interactive prompt to the user. Inverse for NonInteractive parameter.
-LoadProfile | -l
Load the PowerShell profiles. This is the default behavior even if this is not specified.
-NoExit | -noe
Does not exit after running startup commands.

View file

@ -245,6 +245,42 @@ Describe "ConsoleHost unit tests" -tags "Feature" {
}
}
Context "-LoadProfile Commandline switch" {
BeforeAll {
if (Test-Path $profile) {
Remove-Item -Path "$profile.backup" -ErrorAction SilentlyContinue
Rename-Item -Path $profile -NewName "$profile.backup"
}
Set-Content -Path $profile -Value "'profile-loaded'" -Force
}
AfterAll {
Remove-Item -Path $profile -ErrorAction SilentlyContinue
if (Test-Path "$profile.backup") {
Rename-Item -Path "$profile.backup" -NewName $profile
}
}
It "Verifies pwsh will accept <switch> switch" -TestCases @(
@{ switch = "-l"},
@{ switch = "-loadprofile"}
){
param($switch)
if (Test-Path $profile) {
& pwsh $switch -command exit | Should -BeExactly "profile-loaded"
}
else {
# In CI, may not be able to write to $profile location, so just verify that the switch is accepted
# and no error message is in the output
& pwsh $switch -command exit *>&1 | Should -BeNullOrEmpty
}
}
}
Context "-SettingsFile Commandline switch" {
BeforeAll {