diff --git a/cli/tester.js b/cli/tester.js index b4337a0..112a373 100644 --- a/cli/tester.js +++ b/cli/tester.js @@ -14,8 +14,10 @@ import { const PROVIDERS = new Set(['generic-hmac', 'twilio', 'telnyx', 'vonage', 'plivo']); function parseArgs(argv) { - const options = { command: argv[0] || 'help' }; - for (let index = 1; index < argv.length; index += 1) { + const first = argv[0] || 'help'; + const firstIsOption = first.startsWith('-'); + const options = { command: firstIsOption ? 'help' : first }; + for (let index = firstIsOption ? 0 : 1; index < argv.length; index += 1) { const arg = argv[index]; if (!arg.startsWith('--')) continue; const [rawKey, inlineValue] = arg.slice(2).split('=', 2); @@ -295,7 +297,7 @@ async function main() { const args = parseArgs(process.argv.slice(2)); if (args.command !== 'test') { help(); - process.exitCode = args.command === 'help' || args.help ? 0 : 1; + process.exitCode = args.command === 'help' || args.help || args.h ? 0 : 1; return; } diff --git a/package.json b/package.json index e70c971..0d953d2 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ } }, "bin": { - "secure-sms-webhook": "./cli/tester.js" + "secure-sms-webhook": "cli/tester.js" }, "files": [ "src", diff --git a/tests/integration.test.js b/tests/integration.test.js index 632eb20..c479e6b 100644 --- a/tests/integration.test.js +++ b/tests/integration.test.js @@ -60,6 +60,12 @@ test('CLI refuses public targets before making a request', () => { assert.match(run.stderr, /Remote targets are disabled/); }); +test('CLI help exits successfully', () => { + const run = spawnSync(process.execPath, ['cli/tester.js', '--help'], { encoding: 'utf8' }); + assert.equal(run.status, 0); + assert.match(run.stdout, /Secure SMS Webhook Validator/); +}); + test('documentation site is static, disclosed, and contains no secret form fields', () => { const html = readFileSync('site/index.html', 'utf8'); assert.match(html, /Secure SMS Webhook Validator/);