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:
commit
e3e37a8e35
|
@ -173,28 +173,29 @@ namespace Microsoft.PowerShell
|
||||||
private const int MaxPipePathLengthMacOS = 104;
|
private const int MaxPipePathLengthMacOS = 104;
|
||||||
|
|
||||||
internal static string[] validParameters = {
|
internal static string[] validParameters = {
|
||||||
"version",
|
|
||||||
"nologo",
|
|
||||||
"noexit",
|
|
||||||
#if STAMODE
|
#if STAMODE
|
||||||
"sta",
|
"sta",
|
||||||
"mta",
|
"mta",
|
||||||
#endif
|
#endif
|
||||||
"noprofile",
|
|
||||||
"noninteractive",
|
|
||||||
"inputformat",
|
|
||||||
"outputformat",
|
|
||||||
"windowstyle",
|
|
||||||
"encodedcommand",
|
|
||||||
"configurationname",
|
|
||||||
"file",
|
|
||||||
"executionpolicy",
|
|
||||||
"command",
|
"command",
|
||||||
"settingsfile",
|
"configurationname",
|
||||||
|
"custompipename",
|
||||||
|
"encodedcommand",
|
||||||
|
"executionpolicy",
|
||||||
|
"file",
|
||||||
"help",
|
"help",
|
||||||
"workingdirectory",
|
"inputformat",
|
||||||
|
"loadprofile",
|
||||||
|
"noexit",
|
||||||
|
"nologo",
|
||||||
|
"noninteractive",
|
||||||
|
"noprofile",
|
||||||
|
"outputformat",
|
||||||
"removeworkingdirectorytrailingcharacter",
|
"removeworkingdirectorytrailingcharacter",
|
||||||
"custompipename"
|
"settingsfile",
|
||||||
|
"version",
|
||||||
|
"windowstyle",
|
||||||
|
"workingdirectory"
|
||||||
};
|
};
|
||||||
|
|
||||||
internal CommandLineParameterParser(PSHostUserInterface hostUI, string bannerText, string helpText)
|
internal CommandLineParameterParser(PSHostUserInterface hostUI, string bannerText, string helpText)
|
||||||
|
@ -742,6 +743,10 @@ namespace Microsoft.PowerShell
|
||||||
_noExit = true;
|
_noExit = true;
|
||||||
noexitSeen = true;
|
noexitSeen = true;
|
||||||
}
|
}
|
||||||
|
else if (MatchSwitch(switchKey, "loadprofile", "l"))
|
||||||
|
{
|
||||||
|
_skipUserInit = false;
|
||||||
|
}
|
||||||
else if (MatchSwitch(switchKey, "noprofile", "nop"))
|
else if (MatchSwitch(switchKey, "noprofile", "nop"))
|
||||||
{
|
{
|
||||||
_skipUserInit = true;
|
_skipUserInit = true;
|
||||||
|
|
|
@ -131,7 +131,7 @@ Type 'help' to get help.</value>
|
||||||
[-ConfigurationName <string>] [-CustomPipeName <string>]
|
[-ConfigurationName <string>] [-CustomPipeName <string>]
|
||||||
[-EncodedCommand <Base64EncodedCommand>]
|
[-EncodedCommand <Base64EncodedCommand>]
|
||||||
[-ExecutionPolicy <ExecutionPolicy>] [-InputFormat {Text | XML}]
|
[-ExecutionPolicy <ExecutionPolicy>] [-InputFormat {Text | XML}]
|
||||||
[-Interactive] [-NoExit] [-NoLogo] [-NonInteractive] [-NoProfile]
|
[-Interactive] [-LoadProfile] [-NoExit] [-NoLogo] [-NonInteractive] [-NoProfile]
|
||||||
[-OutputFormat {Text | XML}] [-Version] [-WindowStyle <style>]
|
[-OutputFormat {Text | XML}] [-Version] [-WindowStyle <style>]
|
||||||
[-WorkingDirectory <directoryPath>]
|
[-WorkingDirectory <directoryPath>]
|
||||||
|
|
||||||
|
@ -176,11 +176,11 @@ All parameters are case-insensitive.</value>
|
||||||
Example: pwsh -ConfigurationName AdminRoles
|
Example: pwsh -ConfigurationName AdminRoles
|
||||||
|
|
||||||
-CustomPipeName
|
-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
|
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.
|
to other PowerShell instances. Typically used with the CustomPipeName parameter on Enter-PSHostProcess.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
# PowerShell instance 1
|
# PowerShell instance 1
|
||||||
pwsh -CustomPipeName mydebugpipe
|
pwsh -CustomPipeName mydebugpipe
|
||||||
# PowerShell instance 2
|
# PowerShell instance 2
|
||||||
|
@ -224,6 +224,9 @@ All parameters are case-insensitive.</value>
|
||||||
-Interactive | -i
|
-Interactive | -i
|
||||||
Present an interactive prompt to the user. Inverse for NonInteractive parameter.
|
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
|
-NoExit | -noe
|
||||||
Does not exit after running startup commands.
|
Does not exit after running startup commands.
|
||||||
|
|
||||||
|
|
|
@ -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" {
|
Context "-SettingsFile Commandline switch" {
|
||||||
|
|
||||||
BeforeAll {
|
BeforeAll {
|
||||||
|
|
Loading…
Reference in a new issue