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

jsmin should take true as parameter values #8

Open
madskristensen opened this issue Sep 9, 2015 · 3 comments
Open

jsmin should take true as parameter values #8

madskristensen opened this issue Sep 9, 2015 · 3 comments

Comments

@madskristensen
Copy link

Setting the parameter MinifyCode to true throws. The value has to be 1|0 instead of true|false

Actual

jsmin -MinifyCode 1

Expected

jsmin -MinifyCode true

or (no value, just the parameter)

jsmin -MinifyCode
@sayedihashimi
Copy link
Member

I think what you're running into is more of a PowerShell issue. Let me exaplain.

On jsmin there is a parameter -MinifyCode which is defined as a bool. In PowerShell uses $true and $false for true/false.

When you call jsmin -MinifyCode 1 the 1 is known to be an int and is then converted to $true on your behalf.

When you call jsmin -MinifyCode true, in this case true is ambiguous and PowerShell will look for a command with the name true. If you had passed jsmin -MinifyCode 'true' then PowerShell would have recognized 'true' to be a string and then automatically converted it to $true.

OK after that explanation, there is an easy for us to support your suggestion. Since the underlying issue is that powershell is looking for a command named true or false then we just define commands with those names. For example (you can add the following in your script to test this).

function Invoke-GeoffreyReturnTrue{
    [cmdletbinding()]
    param()
    process{
        $true
    }
}
set-alias true Invoke-GeoffreyReturnTrue


function Invoke-GeoffreyReturnFalse{
    [cmdletbinding()]
    param()
    process{
        $false
    }
}
set-alias false Invoke-GeoffreyReturnTrue

Thoughts?

@madskristensen
Copy link
Author

I see. In that case then $true should be fine. However, for Boolean properties should we make it so they don't require a value. Then these would be the same:

  1. jsmin -MinifyCode $true
  2. jsmin -MinifyCode

@sayedihashimi
Copy link
Member

Oh yeah I'm going to update to convert it to a PowerShell [switch] which can be used like: -MinifyCode or -MinifyCode:$false.

So no need for the true/false alias then, ok.

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

No branches or pull requests

2 participants