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

Fix get terminalWidth in non interactive mode #837

Merged
merged 1 commit into from Mar 30, 2017

Conversation

vitalymak
Copy link
Contributor

@vitalymak vitalymak commented Mar 24, 2017

Run in non-interactive mode:

yargs.wrap(yargs.terminalWidth())

Raises:

YError: Invalid first argument. Expected number or null but received undefined.
    at argumentTypeError (/Users/vitaly/Work/n/node_modules/yargs/lib/argsert.js:70:9)
    at /Users/vitaly/Work/n/node_modules/yargs/lib/argsert.js:41:39
    at Array.forEach (native)
    at module.exports (/Users/vitaly/Work/n/node_modules/yargs/lib/argsert.js:35:21)
    at Object.Yargs.self.wrap (/Users/vitaly/Work/n/node_modules/yargs/yargs.js:692:5)
    at Object.<anonymous> (/Users/vitaly/Work/n/tools/cli.js:275:6)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)

Because process.stdout.columns is undefined in non-interactive shell mode.

Copy link
Member

@bcoe bcoe left a comment

Choose a reason for hiding this comment

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

thanks for the contribution! we just need to get tests passing on OSX.

yargs.js Outdated
@@ -922,7 +922,7 @@ function Yargs (processArgs, cwd, parentRequire) {

self.terminalWidth = function () {
argsert([], 0)
return process.stdout.columns
return process.stdout.columns || null
Copy link
Member

Choose a reason for hiding this comment

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

this is breaking tests because some environments report the width as 0 (OSX on Travis specifically).

What if we replace this with:

return typeof process.stdout.columns !== 'undefined' ? process.stdout.columns : null

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@bcoe bcoe merged commit 360e301 into yargs:master Mar 30, 2017
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

2 participants