Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,14 @@ internal bool ServerMode
}
}

internal bool ShowVersion
{
get
{
return _showVersion;
Copy link
Collaborator

@vors vors Feb 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not simple { get; private set; } #WontFix

Copy link
Member

@daxian-dbw daxian-dbw Feb 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine to follow the existing code pattern here. We can convert the style using a tool later. #ByDesign

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to match the current code style


In reply to: 100213197 [](ancestors = 100213197)

}
}

internal Serialization.DataFormat OutputFormat
{
get
Expand Down Expand Up @@ -500,7 +508,6 @@ private void ParseHelper(string[] args)

// chop off the first character so that we're agnostic wrt specifying / or -
// in front of the switch name.

switchKey = switchKey.Substring(1);

// chop off the second dash so we're agnostic wrt specifying - or --
Expand All @@ -509,6 +516,18 @@ private void ParseHelper(string[] args)
switchKey = switchKey.Substring(1);
}

// If version is in the commandline, don't continue to look at any other parameters
Copy link
Collaborator

@vors vors Feb 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder how it's going to interact with existing in Windows PowerShell
powershell -version 2.0

Since we are stopping to build Windows powershell, and core edition doesn't have any -version 2.0 support, it's probably okey. #ByDesign

Copy link
Member

@SteveL-MSFT SteveL-MSFT Feb 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vors, the @PowerShell/powershell-committee discussed this and that is pretty much the thinking: -version for Windows PowerShell really only supported 2.0 and we're moving away from that. Aligning with Linux convention makes sense. PSCore supports side-by-side intrinsically and using file paths to launch different versions is completely acceptable. #ByDesign

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Furthermore we can always do something like powershell -version:2 if people really demand that functionality in the future (and actually @lzybkr and @BrucePay agreed that it would even be acceptable to do powershell -version 2 as it's highly unlikely that anyone wants to echo one int when they shell out to PowerShell).

if (MatchSwitch(switchKey, "version", "v"))
{
_showVersion = true;
_showBanner = false;
_noInteractive = true;
_skipUserInit = true;
_noExit = false;
break;
}


if (MatchSwitch(switchKey, "help", "h") || MatchSwitch(switchKey, "?", "?"))
{
_showHelp = true;
Expand Down Expand Up @@ -1091,6 +1110,7 @@ private bool CollectArgs(string[] args, ref int i)
private bool _serverMode;
private bool _namedPipeServerMode;
private bool _sshServerMode;
private bool _showVersion;
private string _configurationName;
private PSHostUserInterface _hostUI;
private bool _showHelp;
Expand Down
9 changes: 9 additions & 0 deletions src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,15 @@ internal static int Start(

s_cpp.Parse(tempArgs);

if (s_cpp.ShowVersion)
{
// 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);
return 0;
}

// Servermode parameter validation check.
if ((s_cpp.ServerMode && s_cpp.NamedPipeServerMode) || (s_cpp.ServerMode && s_cpp.SocketServerMode) || (s_cpp.NamedPipeServerMode && s_cpp.SocketServerMode))
{
Expand Down
8 changes: 8 additions & 0 deletions src/System.Management.Automation/engine/PSVersionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ internal static Version PSVersion
}
}

internal static string GitCommitId
{
get
{
return (string)GetPSVersionTable()["GitCommitId"];
}
}

internal static Version CLRVersion
{
get
Expand Down
12 changes: 12 additions & 0 deletions test/powershell/Host/ConsoleHost.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,18 @@ Describe "ConsoleHost unit tests" -tags "Feature" {
$actual | Should Be $expected
}

It "-Version should return the engine version" {
$currentVersion = "powershell " + $PSVersionTable.GitCommitId.ToString()
$observed = & $powershell -version
$observed | should be $currentVersion
}

It "-Version should ignore other parameters" {
$currentVersion = "powershell " + $PSVersionTable.GitCommitId.ToString()
$observed = & $powershell -version -command get-date
Copy link
Member

@daxian-dbw daxian-dbw Feb 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what would happen if I have powershell -noprofile -noexit -version? #WontFix

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would report the version and exit - I can add a test for that explicitly if you like. Rather than testing all of the permutations for the parameters, I chose a representative single case


In reply to: 100405816 [](ancestors = 100405816)

# no extraneous output
$observed | should be $currentVersion
}
}

Context "Pipe to/from powershell" {
Expand Down