budo icon indicating copy to clipboard operation
budo copied to clipboard

Default port should be used if `port` is empty/invalid

Open cvan opened this issue 9 years ago • 6 comments

I want to allow folks to spawn budo with a custom default port (instead of 9966) like this:

PORT=3000 npm start

But this won't work:

  "start": "budo --port $PORT"

budo tries to parse the empty string with parseInt and the NaN gets passed as an (invalid) port, thereby preventing budo from starting the server.

cvan avatar Dec 03 '15 10:12 cvan

I'd say this works as intended; if --port is passed it's your responsibility to set it. To set a default value regardless try this:

$ if [ $PORT ]; then budo --port $PORT; else budo; fi

I'm not sure what the error looks like you're getting, if it's unclear we could perhaps improve that? Cheers!

yoshuawuyts avatar Dec 03 '15 11:12 yoshuawuyts

Also to clarify: setting variables before running the script works:

 "derp": "echo $foo"
$ foo='bar' npm run foo
bar

yoshuawuyts avatar Dec 03 '15 12:12 yoshuawuyts

Yeah typically CLIs will error out when you pass undefined stuff. I think we could add a clearer error message.

mattdesl avatar Dec 03 '15 13:12 mattdesl

I would write the command like this, but I recently discovered Git Bash on Windows doesn't like this format:

$ if [ $PORT ]; then budo --port $PORT; else budo; fi

And it's also not kind of a pain to type in each project's npm scripts.

before

empty

--port screenshot 2015-12-03 02 30 00

invalid (non-numeric)

--port swag screenshot 2015-12-03 02 37 57

after

valid

--port 7000 screenshot 2015-12-03 03 18 01

empty

--port screenshot 2015-12-03 03 17 02

environment variables

PORT='' … --port $PORT PORT=7000 … --port $PORT screenshot 2015-12-03 03 18 30

invalid

--port swag screenshot 2015-12-03 03 17 29

cvan avatar Dec 03 '15 13:12 cvan

Seems like a pretty legitimate use case, I've run into similar issues with Unix stuff not working in Windows. Should be merged in latest, I'll cut a new release soon.

mattdesl avatar Dec 03 '15 15:12 mattdesl

Going to reopen this while we figure out another way to allow user-override port/host in a cross-platform manner.

mattdesl avatar Dec 17 '15 18:12 mattdesl