@@ -7,19 +7,19 @@ const emailValidator = require('email-validator');
77const pkg = require ( './package.json' ) ;
88
99const options = {
10- size : {
11- alias : 's ' ,
10+ s : {
11+ alias : 'size ' ,
1212 describe : 'size of the requested image. (1-2048)'
1313 } ,
14- protocol : {
15- alias : 'p ' ,
14+ p : {
15+ alias : 'protocol ' ,
1616 describe : 'specifies the protocol of the url' ,
1717 choices : [ 'http' , 'https' ]
1818 } ,
19- default : {
20- alias : 'd ' ,
21- describe : `default image when no profile image found.
22- [choices: "404", "mm", "identicon", "monsterid", "wavatar", "retro", "blank", "an image url"]`
19+ d : {
20+ alias : 'default ' ,
21+ describe : `default image when no profile image found. [choices: "404",
22+ "mm", "identicon", "monsterid", "wavatar", "retro", "blank", "an image url"]`
2323 }
2424} ;
2525
@@ -35,6 +35,11 @@ const profileOptions = {
3535 }
3636} ;
3737
38+ const footer = `Useful Links:
39+ - https://en.gravatar.com/site/implement/images/
40+ - https://en.gravatar.com/site/implement/profiles/
41+ - ${ pkg . homepage } ` ;
42+
3843const getOptions = argv => pick ( argv , [ ...Object . keys ( options ) , ...Object . keys ( profileOptions ) ] ) ;
3944
4045const setUsage = function ( yargs ) {
@@ -45,14 +50,11 @@ const setUsage = function (yargs) {
4550 . alias ( 'v' , 'version' )
4651 . version ( `gravatar version: ${ pkg . version } ` )
4752 . describe ( 'v' , 'show version information' )
48- . epilogue ( `Useful Links:
49- - https://en.gravatar.com/site/implement/images/
50- - https://en.gravatar.com/site/implement/profiles/
51- - ${ pkg . homepage } ` ) ;
53+ . epilogue ( footer ) ;
5254} ;
5355
5456const yargs = setUsage ( require ( 'yargs' ) )
55- . usage ( 'Usage: $0 command somebody@example.com [options]' )
57+ . usage ( 'Usage: $0 [ command] < somebody@example.com> [options]' )
5658 . command ( 'avatar' , 'avatar somebody@example.com [options]' , options )
5759 . command ( 'profile' , 'profile somebody@example.com [options]' , profileOptions )
5860 . example ( '$0 somebody@example.com' )
@@ -70,14 +72,20 @@ function printAvatarProfile(email, options) {
7072function exec ( argv ) {
7173 const [ command , email ] = argv . _ ;
7274 const options = getOptions ( argv ) ;
73- if ( command === 'profile' ) return printAvatarProfile ( email , options ) ;
74- if ( command === 'avatar' && emailValidator . validate ( email ) ) return printAvatarUrl ( email , options ) ;
75- if ( emailValidator . validate ( command ) ) return printAvatarUrl ( command , options ) ;
75+ if ( command === 'profile' ) {
76+ return printAvatarProfile ( email , options ) ;
77+ }
78+ if ( command === 'avatar' && emailValidator . validate ( email ) ) {
79+ return printAvatarUrl ( email , options ) ;
80+ }
81+ if ( emailValidator . validate ( command ) ) {
82+ return printAvatarUrl ( command , options ) ;
83+ }
7684 yargs . showHelp ( ) ;
7785 return '' ;
7886}
7987
80- process . stdout . write ( exec ( yargs . argv ) ) ;
88+ exec ( yargs . argv ) ;
8189process . exit ( ) ;
8290
8391function pick ( obj , keys = [ ] ) {
0 commit comments