GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Implement -version parameter in console host (address part of https:/… by JamesWTruher · Pull Request #3115 · PowerShell/PowerShell

Implement -version parameter in console host (address part of https:/… #3115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Dongbo Wang (daxian-dbw) merged 2 commits into PowerShell:master from JamesWTruher:jameswtruher/ShowVersion
Feb 23, 2017

Uh oh!

There was an error while loading. Please reload this page.

Merged

Implement -version parameter in console host (address part of https:/… #3115

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
2 commits
Select commit Hold shift + click to select a range
9a608aa
Implement -version parameter in console host (address part of https:/…
JamesWTruher Feb 2, 2017
96abb8f
use a new static internal for GitCommitId rather than calling method …
JamesWTruher Feb 17, 2017
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

22 changes: 21 additions & 1 deletion 22 src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs
Show comments
View file
Open in desktop
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;
Comment thread Outdated

@vors sergei (vors) Feb 9, 2017 •
edited by JamesWTruher
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@daxian-dbw Dongbo Wang (daxian-dbw) Feb 9, 2017 •
edited by JamesWTruher
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@JamesWTruher James Truher (JamesWTruher) Feb 17, 2017

Copy link
Copy Markdown
Collaborator Author

There was a problem hiding this comment.

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)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
}
}

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
Comment thread Outdated

@vors sergei (vors) Feb 9, 2017 •
edited by JamesWTruher
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@SteveL-MSFT Steve Lee (SteveL-MSFT) Feb 9, 2017 •
edited by JamesWTruher
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

sergei (@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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@joeyaiello Joey Aiello (joeyaiello) Feb 9, 2017

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

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 Jason Shirk (@lzybkr) and Bruce Payette (@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).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
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 9 src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs
Show comments
View file
Open in desktop
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 8 src/System.Management.Automation/engine/PSVersionInfo.cs
Show comments
View file
Open in desktop
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 12 test/powershell/Host/ConsoleHost.Tests.ps1
Show comments
View file
Open in desktop
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
Comment thread Outdated

@daxian-dbw Dongbo Wang (daxian-dbw) Feb 9, 2017 •
edited by JamesWTruher
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@JamesWTruher James Truher (JamesWTruher) Feb 17, 2017

Copy link
Copy Markdown
Collaborator Author

There was a problem hiding this comment.

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)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

Context "Pipe to/from powershell" {
Expand Down
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.