Skip to content

Commit b28e8d2

Browse files
committed
Fixed number parsing for --port.
Signed-off-by: VisualPlugin <aboshadinahmed@gmail.com>
1 parent 2c5e08a commit b28e8d2

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

  • packages/open-collaboration-server/src

packages/open-collaboration-server/src/app.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,24 @@ process.on('unhandledRejection', (reason, promise) => {
3030
console.error('Unhandled Rejection at:', promise, 'reason:', reason);
3131
});
3232

33+
function myParseInt(value, dummyPrevious) {
34+
const parsedValue = parseInt(value, 10);
35+
if (isNaN(parsedValue)) {
36+
throw new commander.InvalidArgumentError('Not a number.');
37+
}
38+
return parsedValue;
39+
}
40+
3341
program
3442
.version(pck.version)
35-
.option('-p, --port <number>', 'Port to listen on', parseInt, 8100)
43+
.option('-p, --port <number>', 'Port to listen on', myParseInt, 8100)
3644
.option('-h, --hostname <string>', 'Hostname to bind to', 'localhost')
3745
.option('-c, --config <string>', 'Path to the configuration file')
3846
.action(startServer);
3947

4048
// Deprecated start command for backwards compatibility
4149
program.command('start')
42-
.option('-p, --port <number>', 'Port to listen on', parseInt, 8100)
50+
.option('-p, --port <number>', 'Port to listen on', myParseInt, 8100)
4351
.option('-h, --hostname <string>', 'Hostname to bind to', 'localhost')
4452
.option('-l, --log-level <string>', 'Log level', 'info')
4553
.option('-c, --config <string>', 'Path to the configuration file')

0 commit comments

Comments
 (0)