Skip to content
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 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

refactor to splat #2

Merged
merged 1 commit into from Jun 30, 2019
Merged

Conversation

TylerLeonhardt
Copy link
Contributor

Splatting is a very PowerShell-y concept. The idea is that you define the parameters for your command in a hashtable and then use the @ sign instead of the $ to "splat" them onto a command.

This change refactors to that so we don't have to use Add-Member.

@shanselman
Copy link
Owner

Sorry I was messing around. Would you rebase on top of the new stuff?

@TylerLeonhardt
Copy link
Contributor Author

Done!

@gpduck
Copy link

gpduck commented Jun 29, 2019

Another problem with the existing if statements is they won't for values that cast to $false (like empty string, $null, and 0):

if(!$terminalProfile.backgroundImage){
    $terminalProfile | Add-Member -NotePropertyName backgroundImage -NotePropertyValue ""
}

If backgroundImage is present but set to "", PowerShell will cast the "" to $false and then try to add the member on top of the existing member, generating an error. A safe way to implement the same logic would be to use Get-Member to test for the property existance:

if(!(Get-Member -Name backgroundImage -InputObject $TerminalProfile)) {
    $terminalProfile | Add-Member -NotePropertyName backgroundImage -NotePropertyValue ""
}

But switching to use the parameters on Set-MSTerminalProfile is a better solution :)

@shanselman
Copy link
Owner

So sorry about this, but you still stomped on the Seconds parameter and set it back to a hard coded 5?

@TylerLeonhardt
Copy link
Contributor Author

Ah. No worries. I'll fix 👍

@TylerLeonhardt
Copy link
Contributor Author

Ok there we go! I even moved over the Mood script - only 28 lines (most of which are parameter handling & whitespace) not bad!

@shanselman shanselman merged commit d0e98a0 into shanselman:Main Jun 30, 2019
@shanselman
Copy link
Owner

So clean @TylerLeonhardt! :shipit:

@TylerLeonhardt TylerLeonhardt deleted the refactor-to-splat branch June 30, 2019 07:55
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.

None yet

3 participants