@@ -2,6 +2,7 @@ var _ = require('underscore');
22var nconf = require ( 'nconf' ) ;
33
44var h = require ( '../helper' ) ;
5+ var chalk = require ( '../chalk' ) ;
56var config = require ( '../config' ) ;
67var log = require ( '../log' ) ;
78var session = require ( '../session' ) ;
@@ -10,19 +11,35 @@ var cmd = {
1011 command : 'config [key] [value]' ,
1112 aliases : [ 'conf' , 'cfg' , 'setting' ] ,
1213 desc : 'Manage user configs' ,
13- builder : {
14- a : {
15- alias : 'all' ,
16- type : 'boolean' ,
17- describe : 'Show all config' ,
18- default : false
19- } ,
20- d : {
21- alias : 'delete' ,
22- type : 'boolean' ,
23- describe : 'Delete config by key' ,
24- default : false
25- }
14+ builder : function ( yargs ) {
15+ return yargs
16+ . option ( 'a' , {
17+ alias : 'all' ,
18+ type : 'boolean' ,
19+ describe : 'Show all config' ,
20+ default : false
21+ } )
22+ . option ( 'd' , {
23+ alias : 'delete' ,
24+ type : 'boolean' ,
25+ describe : 'Delete config by key' ,
26+ default : false
27+ } )
28+ . positional ( 'key' , {
29+ type : 'string' ,
30+ describe : 'Config key' ,
31+ default : ''
32+ } )
33+ . positional ( 'value' , {
34+ type : 'string' ,
35+ describe : 'Config value' ,
36+ default : ''
37+ } )
38+ . example ( chalk . yellow ( 'leetcode config' ) , 'Show user configs' )
39+ . example ( chalk . yellow ( 'leetcode config -a' ) , 'Show all configs = user + default' )
40+ . example ( chalk . yellow ( 'leetcode config plugins:github:repo "your repo URL"' ) , 'Set config by key' )
41+ . example ( chalk . yellow ( 'leetcode config plugins:github' ) , 'Show config by key' )
42+ . example ( chalk . yellow ( 'leetcode config plugins:github -d' ) , 'Delete config by key' ) ;
2643 }
2744} ;
2845
@@ -44,7 +61,7 @@ cmd.handler = function(argv) {
4461 nconf . file ( 'local' , h . getConfigFile ( ) ) ;
4562
4663 // show all
47- if ( argv . key === undefined )
64+ if ( argv . key . length === 0 )
4865 return log . info ( prettyConfig ( loadConfig ( argv . all ) ) ) ;
4966
5067 var v = nconf . get ( argv . key ) ;
@@ -57,7 +74,7 @@ cmd.handler = function(argv) {
5774 }
5875
5976 // show
60- if ( argv . value === undefined ) {
77+ if ( argv . value . length === 0 ) {
6178 if ( v === undefined ) return log . error ( 'Key not found: ' + argv . key ) ;
6279 return log . info ( prettyConfig ( v ) ) ;
6380 }
0 commit comments