Skip to content

Fixed number parsing for --port. #153

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions packages/open-collaboration-server/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,24 @@ process.on('unhandledRejection', (reason, promise) => {
console.error('Unhandled Rejection at:', promise, 'reason:', reason);
});

function myParseInt(value, dummyPrevious) {
const parsedValue = parseInt(value, 10);
if (isNaN(parsedValue)) {
throw new commander.InvalidArgumentError('Not a number.');
}
return parsedValue;
}

program
.version(pck.version)
.option('-p, --port <number>', 'Port to listen on', parseInt, 8100)
.option('-p, --port <number>', 'Port to listen on', myParseInt, 8100)
.option('-h, --hostname <string>', 'Hostname to bind to', 'localhost')
.option('-c, --config <string>', 'Path to the configuration file')
.action(startServer);

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