Skip to content

Conversation

@iSazonov
Copy link
Collaborator

@iSazonov iSazonov commented Mar 22, 2017

It is first experimental implementation Get-Hash cmdlet for https://github.com/PowerShell/PowerShell-RFC/blob/master/2-Draft-Accepted/RFC0018-Get-StringHash.md

  1. According to the RFC the type of Encoding parameter is FileSystemCmdletProviderEncoding but I had to use EncodingConversion class because the API contains useful methods and can be easily enhanced in future (to support full set of codepages). Now multiple Utility cmdlets uses it. In contrast, a code using FileSystemCmdletProviderEncoding type is distributed in FileProvider and it's hard to reuse it although it is designated as the preferred (?) in https://github.com/PowerShell/PowerShell-RFC/blob/master/1-Draft/RFC0020-DefaultFileEncoding.md We also talked about that we should rationalize the use of encoding so EncodingConversion class looks like the best option.
  2. Added ValueFromPipelineByPropertyName to Path parameter that is skipped in the RFC 0018.
  3. After the implementation we can really see that Path and InputString parameters have the same type and cannot be both ValueFromPipeline. Perhaps here we understand that it is better for UX to have both options and we should split on Get-FileHash and Get-StringHash still. Until concluding on this I haven't added pipeline tests. We follow Select-String pattern as suggested by @rkeithhill.
  4. I wanted to implement ValidateEncoding attribute but was blocked so how to implement Tab Completion. I need help. We should follow Unify file encoding when a cmdlet creates a file #4119.

@rkeithhill
Copy link
Collaborator

rkeithhill commented Mar 22, 2017

RE # 3, try changing the InputString type to PSObject[] and then convert each PSObject ToString before hashing. That should get you around the pipeline binding issue. This pattern in common for cmdlets that take both an InputObject and Path parameters like Select-String.

@daxian-dbw daxian-dbw self-assigned this Mar 22, 2017
@iSazonov
Copy link
Collaborator Author

@rkeithhill Thanks for workaround! The code looks not pretty. But I am ready to try this if community votes for this.

Can we introduce new Path type to resolve such problems? (This can be a lot of work)

public class PSPath : PSObject
{
    string Path;
    public string ToString()
    {
        return Path;
    }
}

@rkeithhill
Copy link
Collaborator

If you look at the SelectStringCommand impl -

it appears you use the FilenfoToString argument transform attribute on the Path/LiteralPath parameters.

@iSazonov iSazonov added the Review - Needed The PR is being reviewed label Mar 23, 2017
@iSazonov
Copy link
Collaborator Author

How do the attribute help to resolve conflict of parameter bindings?

@rkeithhill
Copy link
Collaborator

Given that this attribute is private I've not had the chance to use it. However, it makes Select-String work so I'm assuming here it should make Get-Hash work as well. If you look at the parameter config for Select-String it is very similar to Get-Hash:

    Command: Microsoft.PowerShell.Utility/Select-String
    Set:    File *


Name                   Aliases      Position Mandatory Pipeline ByName Provider        Type
----                   -------      -------- --------- -------- ------ --------        ----
AllMatches             {A*}         Named    False     False    False  All             SwitchParameter
CaseSensitive          {Ca*}        Named    False     False    False  All             SwitchParameter
Context                {Co*}        Named    False     False    False  All             Int32[]
Encoding               {En*}        Named    False     False    False  All             String
Exclude                {Ex*}        Named    False     False    False  All             String[]
Include                {Inc*}       Named    False     False    False  All             String[]
List                   {Lis*}       Named    False     False    False  All             SwitchParameter
NotMatch               {N*}         Named    False     False    False  All             SwitchParameter
Path                   {}           1        True      False    True   All             String[]
Pattern                {Patt*}      0        True      False    False  All             String[]
Quiet                  {Q*}         Named    False     False    False  All             SwitchParameter
SimpleMatch            {S*}         Named    False     False    False  All             SwitchParameter


    Command: Microsoft.PowerShell.Utility/Select-String
    Set:    Object


Name                   Aliases      Position Mandatory Pipeline ByName Provider        Type
----                   -------      -------- --------- -------- ------ --------        ----
AllMatches             {A*}         Named    False     False    False  All             SwitchParameter
CaseSensitive          {Ca*}        Named    False     False    False  All             SwitchParameter
Context                {Co*}        Named    False     False    False  All             Int32[]
Encoding               {En*}        Named    False     False    False  All             String
Exclude                {Ex*}        Named    False     False    False  All             String[]
Include                {Inc*}       Named    False     False    False  All             String[]
InputObject            {Inp*}       Named    True      True     False  All             PSObject
List                   {Lis*}       Named    False     False    False  All             SwitchParameter
NotMatch               {N*}         Named    False     False    False  All             SwitchParameter
Pattern                {Patt*}      0        True      False    False  All             String[]
Quiet                  {Q*}         Named    False     False    False  All             SwitchParameter
SimpleMatch            {S*}         Named    False     False    False  All             SwitchParameter


    Command: Microsoft.PowerShell.Utility/Select-String
    Set:    LiteralFile


Name                   Aliases      Position Mandatory Pipeline ByName Provider        Type
----                   -------      -------- --------- -------- ------ --------        ----
AllMatches             {A*}         Named    False     False    False  All             SwitchParameter
CaseSensitive          {Ca*}        Named    False     False    False  All             SwitchParameter
Context                {Co*}        Named    False     False    False  All             Int32[]
Encoding               {En*}        Named    False     False    False  All             String
Exclude                {Ex*}        Named    False     False    False  All             String[]
Include                {Inc*}       Named    False     False    False  All             String[]
List                   {Lis*}       Named    False     False    False  All             SwitchParameter
LiteralPath            {PSPath, ... Named    True      False    True   All             String[]
NotMatch               {N*}         Named    False     False    False  All             SwitchParameter
Pattern                {Patt*}      0        True      False    False  All             String[]
Quiet                  {Q*}         Named    False     False    False  All             SwitchParameter
SimpleMatch            {S*}         Named    False     False    False  All             SwitchParameter

Path and LiteralPath are pipeline bound by property name and are of type string[]. InputObject is bound by value and is of type PSObject. Somehow Select-String takes both string input to search through (bound to InputObject) and FileInfo objects from Get-ChildItem/Item.

@daxian-dbw
Copy link
Member

daxian-dbw commented Jun 23, 2017

@TravisEz13 I have my hands full and thus re-assigned this PR to you. Could you please help drive it?

@iSazonov
Copy link
Collaborator Author

I'll continue on next week.

@daxian-dbw
Copy link
Member

daxian-dbw commented Jun 23, 2017

@iSazonov No rush at all 😄 I was the assignee previously but I have too much on my plate right now and thus I reassigned this PR to Travis. That comment is just to let Travis know.

@TravisEz13
Copy link
Member

@iSazonov We should close inactive PRs and reopen the PR when it's active. Any issues?

@iSazonov
Copy link
Collaborator Author

I'm going to give my time and finish my work.

@iSazonov iSazonov force-pushed the gethashrfc branch 4 times, most recently from 73a5efc to 8db565d Compare July 24, 2017 13:40
@iSazonov
Copy link
Collaborator Author

Ready for a code review.
I corrected the PR desciption and cleaned up test.
We have a conflict with #4119 for Encoding parameter.

@TravisEz13
Copy link
Member

Please use the present tense, imperative style for commit messages and title per Contribution Guide

@TravisEz13 TravisEz13 added Breaking-Change breaking change that may affect users and removed Breaking-Change breaking change that may affect users labels Jul 24, 2017
Copy link
Member

Choose a reason for hiding this comment

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

Add a test for piping a file. The equivalent of dir * -File | Get-FileHash

Copy link
Member

Choose a reason for hiding this comment

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

To ensure compatibility

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added the test .

Copy link
Member

Choose a reason for hiding this comment

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

#resolved

@TravisEz13
Copy link
Member

@BerheAbrha Can you review to ensure this won't cause issues for PowerShell DSC?

@iSazonov iSazonov changed the title First experimental implementation Get-Hash cmdlet Implement Get-Hash cmdlet Jul 25, 2017
@TravisEz13
Copy link
Member

You have a test error in travis-ci

@TravisEz13 TravisEz13 dismissed their stale review July 25, 2017 16:22

issues resolved

@TravisEz13
Copy link
Member

@iSazonov merge conflicts need to be resolved

iSazonov and others added 5 commits December 20, 2017 00:12
1. Replace GetFileHashCommand with GetHashCommand
2. Exclude an exception
3. Fix tests.
@TravisEz13
Copy link
Member

Tests are failing

@iSazonov
Copy link
Collaborator Author

iSazonov commented Jan 4, 2018

This is too old code. I will update it.

@TravisEz13 TravisEz13 changed the title Implement Get-Hash cmdlet WIP - Implement Get-Hash cmdlet Jan 11, 2018
@stale
Copy link

stale bot commented Mar 16, 2018

This PR has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed if no further activity occurs within 10 days. Thank you for your contributions.

@stale stale bot added the Stale label Mar 16, 2018
@stale
Copy link

stale bot commented Mar 27, 2018

This PR has be automatically close because it is stale. If you wish to continue working on the PR, please first update the PR, then reopen it.
Thanks again for your contribution.
Community members are welcome to grab these works.

@boernsen-development
Copy link

Please reopen this :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Review - Needed The PR is being reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants