@@ -4,11 +4,12 @@ import chalk from 'chalk'
44import yargs from 'yargs/yargs'
55import path from 'path'
66import fs from 'fs-extra'
7+ import semver from 'semver'
78import { fetchChangelog } from '../index'
89import { debug } from '../util/debug'
910
1011/* eslint-env node */
11- const { argv } = yargs ( process . argv . slice ( 2 ) )
12+ const yargsInstance = yargs ( process . argv . slice ( 2 ) )
1213 . usage (
1314 `Usage: $0 <pkg>[@<range>]
1415
@@ -20,6 +21,10 @@ Prints changelog entries for an npm package from GitHub.
2021 alias : 'r' ,
2122 describe : 'semver version range to get changelog entries for' ,
2223 type : 'string' ,
24+ coerce : ( value : string ) : string => {
25+ if ( ! semver . valid ( value ) ) throw new Error ( `invalid --range: ${ value } ` )
26+ return value
27+ } ,
2328 } ,
2429 json : {
2530 describe : 'output json' ,
@@ -43,6 +48,7 @@ Prints changelog entries for an npm package from GitHub.
4348 . help ( )
4449
4550async function go ( ) {
51+ const { argv } = yargsInstance
4652 let {
4753 _ : [ pkg ] ,
4854 range,
@@ -51,7 +57,10 @@ async function go() {
5157 debug ( 'process.version:' , process . version )
5258 debug ( 'process.execPath:' , process . execPath )
5359 debug ( argv )
54- if ( ! pkg ) process . exit ( 1 )
60+ if ( ! pkg ) {
61+ yargsInstance . showHelp ( )
62+ process . exit ( 1 )
63+ }
5564
5665 const filters = [
5766 ...( argv . major ? [ 'major' ] : [ ] ) ,
0 commit comments