8000 fix `powershell -version` and help by SteveL-MSFT · Pull Request #4958 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

fix powershell -version and help #4958

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.

By 8000 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
merged 4 commits into from
Oct 1, 2017

Conversation

SteveL-MSFT
Copy link
Member
@SteveL-MSFT SteveL-MSFT commented Sep 30, 2017

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.

Doc update aligned with these changes (and general cleanup of parameters we don't support in PSCore6) MicrosoftDocs/PowerShell-Docs#1707

removed test that is no longer valid due to change in -version behavior to return error
@daxian-dbw
Copy link
Member

The same test didn't fail in AppVeyor. In AppVeyor, the failed test is Version should write an error if a value is present, see https://ci.appveyor.com/project/PowerShell/powershell/build/6.0.0-beta.7-5642#L384

On Travis, a different test failed: Version should ignore other parameters. See https://travis-ci.org/PowerShell/PowerShell/jobs/281514325#L1461

So probably we shouldn't just remove that test.

@SteveL-MSFT
Copy link
Member Author

We still need to remove this test as the change is to return an error if there's anything after -version whereas previously we silently ignored it. I think the current behavior is correct.

@SteveL-MSFT
Copy link
Member Author

Need to fix the other test and also make a change to the -v handling. I should have caught this in the code review. Apologies.

fixed `-v X` so that it errors out correctly with proper exit code
updated test to catch this
Copy link
Collaborator
@iSazonov iSazonov left a comment

Choose a reason for hiding this comment

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

Leave a comment

$expectedError = (Get-Content $tempFile)[0]

$expectedError | Should Match $versionValue
$observed = & $powershell -version $versionValue 2>&1
Copy link
Collaborator

Choose a reason for hiding this comment

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

😕 I skipped [Feature] in previous PR. I saw "CI" on top the test file but we have "Feature" tests below.
We need an idea how exclude this in future.
(I wonder that the test was passed locally.)

In CI log I see messages:

[00:08:17] Usage of '-Version -command' is not supported. '-Version' currently only returns the current PowerShell version.
[00:08:17] +
[00:08:17] Usage of '-Version abrakadabra' is not supported. '-Version' currently only returns the current PowerShell version.

The first message looks incorrect. Maybe: "Error in '-Version {0}'. Now '-Version' shows the current PowerShell version and don't accept an argument."

Also previous test helped us to catch the problem - so I prefer to don't remove it because it may test another code path in future.

Copy link
Member Author

Choose a reason for hiding this comment

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

The test I removed was when we supported:

poweshell -version -command 1+1

I think this syntax doesn't make sense as what it ended up doing was outputting the version string and ignoring everything after it. It seems that this should have caught an unintentional user error which is why I removed that test since the new behavior prevents that old behavior.

I agree that the error message could be better particularly in the above scenario. I'll update it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I'll change it to

Unsupported value '{0}' passed to `-Version`. '-Version' currently only returns the current PowerShell version and must be used standalone.

@SteveL-MSFT SteveL-MSFT changed the title removed test that is no longer valid for values after powershell -version fix powershell -version test Sep 30, 2017
address PR feedback
@@ -273,6 +273,6 @@ EXAMPLES
<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>
<value>Unsupported value '{0}' passed to `-Version`. '-Version' only returns the current PowerShell version and must be used standalone.</value>
Copy link
Collaborator
@iSazonov iSazonov Sep 30, 2017

Choose a reason for hiding this comment

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

I still unlike this:

  1. `-Version``. '-Version' - looks bad.
  2. Unsupported value - implies that there are supported values.

Copy link
Member Author

Choose a reason for hiding this comment

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

If we follow the example of some other tools like: git, curl, bash (although each of them use --version), they basically ignore anything after --version and simply output the version string. Perhaps that's the right behavior.

Copy link
Member Author

Choose a reason for hiding this comment

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

For now, I think I'll follow the other tools and will update the documentation as well.

Copy link
Collaborator
@iSazonov iSazonov Sep 30, 2017

Choose a reason for hiding this comment

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

Initial idea (in #4834) for PowerShell was to inform users that we change -Version semantics. So I write information error and PowerShell version too.

@SteveL-MSFT SteveL-MSFT changed the title fix powershell -version test fix powershell -version and help Sep 30, 2017
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
@SteveL-MSFT
Copy link
Member Author

@iSazonov if you're fine with the changes, can you merge so we can unblock other PRs? If you have specific concerns with the expected behavior, I think we can continue that discussion in a new issue. Thanks!

@iSazonov
Copy link
Collaborator
iSazonov commented Oct 1, 2017

One concern is that we show full help in case of an error.
It's very annoying in interactive session if I typo - I'm forced to scroll back to see error message and lost my history before eyes. I'd prefer to see an error message and shot hint "Use powershell -? or -h to get more help" .

@SteveL-MSFT
Copy link
Member Author

@iSazonov you referring to existing behavior and not something I introduced, correct?

@SteveL-MSFT SteveL-MSFT deleted the version-test branch October 1, 2017 03:53
@iSazonov
Copy link
Collaborator
iSazonov commented Oct 1, 2017

Yes, I wanted to say that we need more review and cleanups in the file. I see:

  1. #if !CORE
  2. _ShowHelp=true
  3. maybe formattings

@SteveL-MSFT
Copy link
Member Author

@iSazonov can submit a new PR? the #if CORECLR I was going to take care of as part of #4953

@iSazonov
Copy link
Collaborator
iSazonov commented Oct 1, 2017

I'll try to review on next week.

@iSazonov
Copy link
Collaborator
iSazonov commented Oct 2, 2017

@SteveL-MSFT Please clarify. In #4834 we decided to write an error to inform users about changing -Version behavior. In the PR we remove the error. Should we write in #4834 that we reject the request now?

Update after review.

  1. I see that we show the full command line help in some cases but not if parameter is wrong. Should we show the help in all cases? It seems bash do so.
  2. By default we assume a file name passed. If the file don't found we write an error (bash do so too) - to write the help is not trivial but desired fix (bash don't show a help) - is it?
  3. I suggest reformat the help in Bash style:
  • sort parameter list in alphabetical order.
  • replace long header on powershell[.exe] [options]
  1. Maybe add examples in end of the help.

@SteveL-MSFT
Copy link
Member Author

@iSazonov added comment and closed #4834

  1. we should be consistent and, in general, use existing norms like bash
  2. we should not output help either
  3. agree with the proposed changes
  4. absolutely!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0