11#!/usr/bin/env node
22
3+ const docURL = 'https://github.com/adamlui/js-utils/tree/main/generate-ip#-command-line-usage' ;
4+
35// Import LIBS
46const { ipv4 } = require ( __dirname . match ( / s r c / ) ? './generate-ip' : './generate-ip.min' ) ,
57 { execSync } = require ( 'child_process' ) ; // for cross-platform copying
@@ -28,16 +30,15 @@ process.argv.forEach(arg => {
2830 else if ( matchedParamOption ) {
2931 if ( ! arg . includes ( '=' ) ) {
3032 console . error ( `\n${ br } ERROR: Arg [--${ arg . replace ( / - / g, '' ) } ] requires '=' followed by a value.${ nc } ` ) ;
31- console . error ( `\n${ by } For more help, type 'generate-pw --help'.${ nc } ` ) ;
32- process . exit ( 1 ) ;
33+ printHelpCmdAndDocURL ( ) ; process . exit ( 1 ) ;
3334 }
3435 const value = arg . split ( '=' ) [ 1 ] ;
3536 config [ matchedParamOption ] = parseInt ( value ) || value ;
3637 } else if ( ! matchedInfoCmd ) {
3738 console . error ( `\n${ br } ERROR: Arg [${ arg } ] not recognized.${ nc } ` ) ;
3839 console . info ( `\n${ by } Valid arguments are below.${ nc } ` ) ;
3940 printHelpSections ( [ 'paramOptions' , 'flags' , 'infoCmds' ] ) ;
40- process . exit ( 1 ) ;
41+ printHelpCmdAndDocURL ( ) ; process . exit ( 1 ) ;
4142} } ) ;
4243
4344// Show HELP screen if -h or --help passed
@@ -50,7 +51,7 @@ else if (process.argv.some(arg => argRegex.infoCmds.version.test(arg)))
5051else { // log/copy RESULT(S)
5152 if ( config . qty && ( isNaN ( config . qty ) || config . qty < 1 ) ) {
5253 console . error ( `\n${ br } Error: [qty] argument can only be > 0.${ nc } ` ) ;
53- process . exit ( 1 ) ;
54+ printHelpCmdAndDocURL ( ) ; process . exit ( 1 ) ;
5455 }
5556 const ipResult = ipv4 . generate ( { qty : config . qty || 1 , verbose : ! config . quietMode } ) ;
5657 if ( ! config . quietMode ) {
@@ -108,6 +109,9 @@ function printHelpSections(includeSections = ['cmdFormat', 'paramOptions', 'flag
108109 }
109110}
110111
112+ function printHelpCmdAndDocURL ( ) {
113+ console . info ( `\n${ by } For more help, type 'generate-ip --help' or visit\n${ docURL + nc } ` ) ; }
114+
111115function copyToClipboard ( data ) {
112116 data = data . replace ( / \s + $ / , '' ) . replace ( / " / g, '""' ) ;
113117 if ( process . platform === 'darwin' ) // macOS
0 commit comments