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

Invoke-NullCoalescing lies #93

Closed
wekempf opened this issue Apr 4, 2013 · 5 comments
Closed

Invoke-NullCoalescing lies #93

wekempf opened this issue Apr 4, 2013 · 5 comments
Assignees
Milestone

Comments

@wekempf
Copy link

wekempf commented Apr 4, 2013

I'm not sure why this command is exported publicly? It has nothing to do with Git, and as such I'd prefer it to not be exported, honestly. If you are going to export it, though, it should do what the name says it does.

PS> Invoke-NullCoalescing '' 'oops'
oops
PS> Invoke-NullCoalescing $false 'oops'
oops
PS> Invoke-NullCoalescing 0 'oops'
oops

I'm sure you can think of many other ways to get the wrong result here. However, there is one more example that you may consider correct, but I find to be very confusing.

PS> Invoke-NullCoalescing { } 'oops'
oops

Invoking the ScriptBlocks may be what you need, but it seems very surprising to me. If I were to implement this it would have been simply:

function Invoke-NullCoalescing {
   $args | Where-Object { $_ -ne $null } | Select-Object -First 1
}

To include the script block processing, something like:

function Invoke-NullCoalescing([switch]$ProcessScriptBlocks) {
   $args | ForEach-Object {
        if ($_ -is [ScriptBlock] -and $ProcessScriptBlocks) {
            & $_
        } else {
            $_
        }
    } | Where-Object { $_ -ne $null } | Select-Object -First 1
}
@dahlbyk
Copy link
Owner

dahlbyk commented Apr 10, 2013

I believe I check for "falsey" rather than $null specifically to handle some places where I deal with git output, but I'm honestly not sure. Lacking tests (something else I'd love to figure out at some point), I'm hesitant to change the behavior.

That said, you're right that exporting it doesn't make sense. I'll fix that.

@kamranayub
Copy link

kamranayub commented Sep 1, 2016

I just got a new W10 Anniversary image on my PC and tried Install-Module posh-git and am now seeing this:

PackageManagement\Install-Package : A command with name
'Invoke-NullCoalescing' is already available on this system.
This module 'posh-git' may override the existing commands.
If you still want to install this module 'posh-git', use
-AllowClobber parameter.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1 .0.0.1\PSModule.psm1:1661 char:21

Looks like I have this cmdlet already from PSCX that must be installed. I'll keep playing around, but this is the first time I've seen this.

This is PS 5.1.14393

edit: looks like when I restored my old profile and I had also gotten some PS modules we've developed and someone included PSCX and was adding the local paths to my environment bootup--so I removed that bootup sequence and therefore removed the reference to PSCX.

@dahlbyk dahlbyk mentioned this issue Dec 29, 2016
13 tasks
@JCJAT
Copy link

JCJAT commented Dec 31, 2016

  1. Cannot install posh-git whilst the Powershell Community extensions (pscx) is installed.
  2. posh-git should also not be setting an alias on ??,
  3. should it export this function either since it is an internal function only.
  4. Manifest for posh-git should have -DefaultCommandPrefix set to prevent conflicts with the users session.

@rkeithhill
Copy link
Collaborator

I believe we are planning to not export this function in the 1.0.0 release. It will remain in the upcoming 0.7.0 release as we are trying to avoid potentially breaking changes. The 1.0.0 release however will gives us some latitude WRT breaking changes.

@dahlbyk dahlbyk added this to the v1.0 milestone Jan 2, 2017
@rkeithhill rkeithhill self-assigned this Feb 18, 2017
@rkeithhill
Copy link
Collaborator

Closed with PR #427

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

5 participants