true icon indicating copy to clipboard operation
true copied to clipboard

Add `false` option

Open cscott opened this issue 9 years ago • 5 comments

Since this is a port of the unix utility true, I feel it is important to provide a false option. Quoting from the man page for GNU true:

Note, however, that it is possible to cause ‘true’ to exit with
nonzero status: with the ‘--help’ or ‘--version’ option, and with
standard output already closed or redirected to a file that evokes an
I/O error.  For example, using a Bourne-compatible shell:

     $ ./true --version >&-
     ./true: write error: Bad file number
     $ ./true --version > /dev/full
     ./true: write error: No space left on device

Clearly we need to provide equivalent functionality in the npm module.

cscott avatar Mar 24 '16 15:03 cscott

I feel it is important to provide a false option.

It's too complicated. Let's respect the single responsibility principle.

AlexDEVpro avatar May 18 '18 14:05 AlexDEVpro

Apologies for coming onto this thread so late.

It's worth noting that true does indeed have a complementary false module. (Just as with the actual Unix false utility that exists.)

These methods of evoking a non-zero exit code from true seem somewhat hacky and not necessarily intended by the author of the Unix true. It's not exactly a false 'option.' Are there any ideas for how this would work with our Node port here?

mde avatar May 18 '18 14:05 mde

Still not solved?

This is 2021.

Taewa avatar Mar 03 '21 19:03 Taewa

Guys, i solve the issue by creating another function

const random = require('random')
function aJavaScriptPortOfTheUnixUtilityTrueReturnsTheBooleanValueFalseButWithTwist(){
    return random.int(0, 100) < 98 ? !aJavaScriptPortOfTheUnixUtilityTrueReturnsTheBooleanValueTrue() : aJavaScriptPortOfTheUnixUtilityTrueReturnsTheBooleanValueTrue();
}

Elly2018 avatar Dec 10 '22 07:12 Elly2018

While this is an interesting approach, I am beginning to think the ideal way to handle this is with quantum states.

mde avatar Jan 14 '23 19:01 mde

For false we should make separate package.

labokas avatar May 28 '24 11:05 labokas

As I just said: https://github.com/mde/true/issues/15#issuecomment-390226854

mde avatar May 29 '24 01:05 mde

Probably worth wrapping this thread up. Good points for considering, given how critical this library truly is.

mde avatar May 29 '24 01:05 mde