Browse Source

Improve command line args validation. Fixes #478.

master
Jarmo Isotalo 8 years ago
parent
commit
1248c46295
  1. 10
      bin/now-scale.js

10
bin/now-scale.js

@ -117,6 +117,14 @@ function guessParams() {
process.exit(1);
}
function isHostNameOrId(str) {
return (
/(https?:\/\/)?((?:(?=[a-z0-9-]{1,63}\.)(?:xn--)?[a-z0-9]+(?:-[a-z0-9]+)*\.)+[a-z]{2,63})/.test(
str
) || str.length === 28
);
}
async function run({ token, config: { currentTeam } }) {
const scale = new NowScale({ apiUrl, token, debug, currentTeam });
const start = Date.now();
@ -127,7 +135,7 @@ async function run({ token, config: { currentTeam } }) {
} else if (id === 'info') {
await info(scale);
process.exit(0);
} else if (id) {
} else if (id && isHostNameOrId(id)) {
// Normalize URL by removing slash from the end
if (isURL(id) && id.slice(-1) === '/') {
id = id.slice(0, -1);

Loading…
Cancel
Save