FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Implement Format-Hex in C# by MiaRomero · Pull Request #3320 · PowerShell/PowerShell · GitHub

Implement Format-Hex in C# by MiaRomero · Pull Request #3320 · PowerShell/PowerShell · GitHub
Skip to content

Navigation Menu

Sign in

Implement Format-Hex in C# - #3320

Merged
Jason Shirk (lzybkr) merged 2 commits into
PowerShell:masterfrom
MiaRomero:formatHex
Mar 21, 2017
Merged

Implement Format-Hex in C##3320
Jason Shirk (lzybkr) merged 2 commits into
PowerShell:masterfrom
MiaRomero:formatHex

Conversation

Maria Romero (MiaRomero) commented Mar 13, 2017
edited
Loading

Copy link
Copy Markdown
Member

Addressing issue #2730 'Rewrite Format-Hex in C#'

  • Documentation for Format-Hex states both the Path and LiteralPath parameters accept string arrays, though this functionality was not actually present for the cmdlet. This has been corrected so both parameters can accept and process an array of strings. If an invalid path is included in the array, a non-terminating 'FileNotFound' error will be thrown, but the remaining valid paths will be processed and output as usual.

  • After a discussion with Francisco Gamino (@Francisco-Gamino) and Joey Aiello (@joeyaiello), it was decided to make the Raw parameter No-op. Going forward all of the output will be displayed with a true representation of numbers that includes all of the bytes for its type (what the Raw parameter was formally doing). For example, [Int32]170 passed to Format-Hex would have previously displayed only "AA". Now it will display "AA 00 00 00".

  • Updated the InputObject parameter to accept an Int32[], in addition to all previously accepted types.

  • The way Format-Hex processes and displays input from the pipeline has been corrected. Previously, the output for numbers in an array or range would be combined into one as seen below:

  PS D:\GitHub\PowerShell> 1,2 | fhx


           Path:

           00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F

  00000000   01 02                                            ..

Now each number will be displayed as its own input object:

  PS D:\GitHub\PowerShell> 1,2 |fhx


           00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F

  00000000   01 00 00 00                                      ....


           00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F

  00000000   02 00 00 00                                      ....
  • Added a new error that states Format-Hex only supports FileSystem Provider Paths. Previously an error was thrown, but was not specific about the problem (and was displaying the wrong path).
fhx : The given path 'Cert:\CurrentUser\My\' is not supported. This command only supports the FileSystem Provider paths.
At line:1 char:1
+ fhx -path Cert:\CurrentUser\My\
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (Cert:\CurrentUser\My\:String) [Format-Hex], ArgumentException
    + FullyQualifiedErrorId : FormatHexOnlySupportsFileSystemPaths,Microsoft.PowerShell.Commands.FormatHex
  • Cleaned up how we are exposing the Format-Hex error messages. Removed from UtilityCommon.cs and are being accessed through UtilityCommonStrings.resx instead.

  • Updated and added tests for this cmdlet to validate newly implemented functionality and to be more comprehensive for original functionality.

@MiaRomero,
Thanks for your contribution.
To ensure that the project team has proper rights to use your work, please complete the Contribution License Agreement at https://cla.microsoft.com.

It will cover your contributions to all Microsoft-managed open source projects.
Thanks,
Microsoft Pull Request Bot

Copy link
Copy Markdown
Contributor

SandeepSutari, Mike Richmond (@mirichmo), Dongbo Wang (@daxian-dbw), Joey Aiello (@joeyaiello): Could you please take a look? Thanks.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Why is the private member not camel cased ? Unless Pascal casing is the recommended pattern for C# cmdlets, we should use camel casing

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I mean method name...var name is fine

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I talked to Dongbo Wang (@daxian-dbw) about this, and Pascal casing is the recommended pattern for the cmdlets.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Looks like you could get the inputBytes out of each of these else if {} blocks and do the convert* at the end if else block. that would prevent 10 uses of convert calls peppered across this method.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Fixed.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

unless this is the pattern or a standard practice to use _ for private members we should avoid it. Also why is the method variable using the private member style...we should stick with camel casing since its a method variable.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

parameter names shouldn't have '_' prefixed to them.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Fixed.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I would fix indentation here

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Fixed for all error messages.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

i64 should get itself a better var name. currently its a type name.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

You can do something like foreach (Int64 value in inputInts){...}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Fixed.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

use string constants instead of raw strings

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Fixed.

SandeepSutari left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

here are a few high level comments

Comment thread githublog.log Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

this file shouldn't be part of the PR

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

convention is to use automatic properties:

public string[] Path { get; set; }

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Fixed.

Copy link
Copy Markdown
Collaborator

Maria Romero (@MiaRomero) Do you use the same e-mail for GitHub and CLA sign?

Ilya (iSazonov) added the Breaking-Change breaking change that may affect users label Mar 14, 2017

Copy link
Copy Markdown
Collaborator

Add Breaking-Change because -Raw removed.

Maria Romero (@MiaRomero), thanks for signing the contribution license agreement. We will now validate the agreement and then the pull request.

Thanks, Microsoft Pull Request Bot

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

The HelpUr should be "http://go.microsoft.com/fwlink/?LinkId=526919". This will fix your failures in the CI test pass.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Shouldn't this be https?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Fixed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

As per Dongbo Wang (@daxian-dbw) suggestion, please see if you can reuse some of existing cmdlets' code that support encoding parameters.

You can probably reuse some of this code:

internal static Encoding GetEncodingFromEnum(TextEncodingType type)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

yes, this should probably be an enum rather than the string set


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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

We have FileSystemCmdletProviderEncoding enum (but in EncodingConversion the same is string constants in the class.
It seems we need to bring this to the common code base.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Fixed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Please fix the indentation of all the errorrecords.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Fixed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

You can do something like foreach (Int64 value in inputInts){...}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This test case could probably be simplified to:

{ Get-Alias fhx } | Should Not Throw

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Fixed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Could you please use a more meaningful variable name? E.g., $output, and $errorThrown?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Fixed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

'expectedError' should be rename to 'expectedFullyQualifiedErrorId'.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Fixed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

$otherProvider should probably be renamed to '$certificateProvider'.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Fixed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Could you please rename this Context to something like "Validate Format-Hex error scenarios" or "Validate negative test cases" or "Validate error scenarios"?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Fixed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Should these be ExpectedResult, and ExpectedSecondResult?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Fixed.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

do you need to validate that these paths are filesystem provider paths?
for example, format-hex -literalpath hklm:/software should perhaps produce the same error as format-hex -path hklm:/software

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Fixed.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

it seems like it would be a useful scenario to support multiple files here:
format-hex file*.txt
unless that's an explicit non-supported scenario

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

yep - looking below, it appears that it just loops through the provided paths, it seems reasonable to support more than one resolved path


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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Fixed.

Francisco Gamino (Francisco-Gamino) added the Review - Committee The PR/Issue needs a review from the PowerShell Committee label Mar 15, 2017

Jason Shirk (lzybkr) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

The file src\Modules\Unix\Microsoft.PowerShell.Utility\Microsoft.PowerShell.Utility.psd1 also needs updating - that should get the tests passing in Travis.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Please use platform independent [Environment]::NewLine

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Fixed.

Maria Romero (MiaRomero) commented Mar 15, 2017
edited
Loading

Copy link
Copy Markdown
Member Author

Hi SandeepSutari, Francisco Gamino (@Francisco-Gamino), Steve Lee (@SteveL-MSFT), Ilya (@iSazonov), and James Truher (@JamesWTruher),
Thank you for your feedback. I have addressed your comments - would you please take another look?
Thanks,
Maria

Francisco Gamino (Francisco-Gamino) commented Mar 15, 2017
edited
Loading

Copy link
Copy Markdown
Contributor

Ilya (@iSazonov), Joey Aiello (@joeyaiello): I am removing "Breaking-Change" label as the -Raw parameter is still present (is a No-op).

Francisco Gamino (Francisco-Gamino) removed the Breaking-Change breaking change that may affect users label Mar 15, 2017

Steve Lee (SteveL-MSFT) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

My comments have been addressed. Thanks Maria Romero (@MiaRomero) !

Jason Shirk (lzybkr) added the Breaking-Change breaking change that may affect users label Mar 15, 2017

Copy link
Copy Markdown
Contributor

Francisco Gamino (@Francisco-Gamino) - Even with the noop -Raw parameter - there is a change in behavior we need to document - so please keep the Breaking Change label.

Copy link
Copy Markdown
Member

It looks like we are using little-endian, since all windows version are little-endian. But since we are going cross-plat, maybe considering supporting big-endian as well? Or maybe at least document that we use little-endian by default?

Copy link
Copy Markdown
Contributor

Dongbo Wang (@daxian-dbw) - I don't think we want to get in the business of dealing with endian-ness in this cmdlet.

I think of it as more of a memory dumping tool, and it shouldn't necessarily interpret what it's dumping (even though we could).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

The test Count == 0 is not necessary if we aren't reporting any errors, the foreach statement handles that case cleanly and efficiently.

That said, should we report an error if there are no files?

Maria Romero (MiaRomero) Mar 20, 2017
edited
Loading

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thank you. Good point, it turns out we do not need this code. It does throw an error if the path does not resolve to a file.

The sample below shows an array of two paths that don't exist. Each will throw a non-terminating error.

fhx -Path "c:\dlfkjasdkfj.txt", "c:\ldkfj.txt"
fhx : Cannot find path 'C:\dlfkjasdkfj.txt' because it does not exist.
At line:1 char:1
+ fhx -Path "c:\dlfkjasdkfj.txt", "c:\ldkfj.txt"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (System.String[]:String[]) [Format-Hex], ItemNotFoundException
    + FullyQualifiedErrorId : FileNotFound,Microsoft.PowerShell.Commands.FormatHex

fhx : Cannot find path 'C:\ldkfj.txt' because it does not exist.
At line:1 char:1
+ fhx -Path "c:\dlfkjasdkfj.txt", "c:\ldkfj.txt"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (System.String[]:String[]) [Format-Hex], ItemNotFoundException
    + FullyQualifiedErrorId : FileNotFound,Microsoft.PowerShell.Commands.FormatHex

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

And just to confirm - there is no error if you use a wildcard and there are no matches?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Clone is copying data needlessly here.

Instead, you could pass buffer to ConvertToHexidecimal, then create a new array that is zero initialized. The zeroing of memory by .Net is going to be more efficient than the Clone (which will have started with zeroed memory anyway).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I've changed it to copy the buffer into a new array instead of cloning the buffer. If this isn't what you had in mind, please file an issue and Francisco Gamino (@Francisco-Gamino) will follow up. Due to time constraints with my internship, I won't be able to follow up after today.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I know this is just a translation of the C#, but I don't think this case makes sense.

If I pass an object for Format-Hex, I expect that object to be formatted. I didn't ask for the contents of the file, that's a different parameter set.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Per committee review/comment below, we'll leave as is for now.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

It would be nice to see all primitive types (including enums) and arrays of these types - instead of this random assortment.

I wrote some code that covers much of what I think is useful and it's a similar number of lines of code, see https://gist.github.com/lzybkr/9940b63c8301c31316bdb3ec6305536f

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

It might also be useful to support any value type, not just primitives, but that is a little harder.

Francisco Gamino (Francisco-Gamino) Mar 17, 2017
edited
Loading

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Hi Jason Shirk (@lzybkr), Maria Romero (@MiaRomero) Leap Program assignment/internship ends today, so I will follow-up on this. I have open an issue #3358 to track this. Thanks.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

It doesn't look like there is any file header, so if there are multiple files, it will be difficult to understand the output.

Maria Romero (MiaRomero) Mar 20, 2017
edited
Loading

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

There is a header for each ByteCollection object, e.g.,

New-Item -Value "foo" -Path foo1.txt -ItemType File
New-Item -Value "foo2" -Path foo2.txt -ItemType File

PS C:\exp> dir foo* | fhx
           Path: C:\exp\foo1.txt
           00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
00000000   66 6F 6F                                         foo

           Path: C:\exp\foo2.txt
           00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
00000000   66 6F 6F 32                                      foo2

PS C:\exp> fhx -Path .\foo*
           Path: C:\exp\foo1.txt
           00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
00000000   66 6F 6F                                         foo

           Path: C:\exp\foo2.txt
           00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
00000000   66 6F 6F 32                                      foo2

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Great.

Steve Lee (SteveL-MSFT) added Committee-Reviewed PS-Committee has reviewed this and made a decision and removed Review - Committee The PR/Issue needs a review from the PowerShell Committee labels Mar 15, 2017

Copy link
Copy Markdown
Member

@PowerShell/powershell-committee reviewed this and agreed on:

  • for numbers, we should prefix with 0 to retain width
  • change to formatting (due to storing in property) is a breaking change that just needs to be documented
  • if array is passed in, then each element in the array is a separate output object
  • FileInfo retains current behavior (special cased to format the content)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

It seems like this is unnecessary and should be removed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

In this scenario we want to test that we get both an error and output.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Please use the template to check FullyQualifiedErrorId

{ Start-Process -FilePath $pingCommand -WindowStyle Normal } | ShouldBeErrorId "NotSupportedException,Microsoft.PowerShell.Commands.StartProcessCommand"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I've tried using this but get this error:
The term 'ShouldBeErrorId' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

So for now I'll keep Should Match

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

We could call the function with parameter PathCase = $true then PathCase = $false

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Yes, that is true. But I'll leave as is for now.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Please remove the test because we already have separate files with tests for aliases.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Removed.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Is there any chance we could get Count and Offset parameters? I could probably live without Offset but on the PSCX Format-Hex command, I use -Count almost all the time. That's because I use it to see if a text file has a BOM, in which case I only want to see the first 3 characters.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Those are good suggestions, but out of scope for this PR.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Keith Hill (@rkeithhill), please open a issue for that suggestion. Thanks.

Maria Romero (MiaRomero) force-pushed the formatHex branch 2 times, most recently from 971954d to 41f6b10 Compare March 21, 2017 04:37

Copy link
Copy Markdown
Member Author

Thank you everyone for your feedback. Jason Shirk (@lzybkr) can you please merge when you have a chance? My internship is over so if there are any questions/concerns please address them to Francisco Gamino (@Francisco-Gamino). Thanks!

Copy link
Copy Markdown
Contributor

It was great working with you Maria Romero (@MiaRomero), thank you!

Jason Shirk (lzybkr) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I opened #3382 so we clean up the test a little, but otherwise looks good.

Jason Shirk (lzybkr) merged commit 0e12fbf into PowerShell:master Mar 21, 2017

Copy link
Copy Markdown
Contributor

Thanks Jason Shirk (@lzybkr)! I will take care of #3382.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Breaking-Change breaking change that may affect users Committee-Reviewed PS-Committee has reviewed this and made a decision

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants

Footer

© 2026 GitHub, Inc.

Back | FazBrowse Home | New Git URL