print help for sub-commands
This commit is contained in:
		
							parent
							
								
									83030fb416
								
							
						
					
					
						commit
						e99b9ff4d6
					
				
							
								
								
									
										56
									
								
								bin/cli.js
									
									
									
									
									
								
							
							
						
						
									
										56
									
								
								bin/cli.js
									
									
									
									
									
								
							| @ -55,8 +55,12 @@ function parseArgs(argv, opts) { | |||||||
|     function printCmds(cmds) { |     function printCmds(cmds) { | ||||||
|       console.info(''); |       console.info(''); | ||||||
| 
 | 
 | ||||||
|       console.info('\t' + defaults.main + ' ' + rpad(COMMAND, maxCmdLen), ' # description'); |       var title = defaults.main + ' ' + rpad(COMMAND, maxCmdLen) + '  # description'; | ||||||
|       console.info('\t' + '------------------------------'); |       var bars = title.replace(/./g, '-').split(''); | ||||||
|  |       bars[bars.length - ' # description'.length] = ' '; | ||||||
|  |       bars[bars.length - (' # description'.length + 1)] = ' '; | ||||||
|  |       console.info('\t' + title); | ||||||
|  |       console.info('\t' + bars.join('')); | ||||||
|       cmds.forEach(printCmd); |       cmds.forEach(printCmd); | ||||||
|       console.info(''); |       console.info(''); | ||||||
|     } |     } | ||||||
| @ -94,20 +98,48 @@ function parseArgs(argv, opts) { | |||||||
|       return; |       return; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     console.info(''); |     // matches the first part of the command
 | ||||||
|     console.info('Here are all the "' + command + '"-related commands:'); |     // and has second parts
 | ||||||
|     printCmds( |     if (arg1 === arg1.split(':')[0] && opts.commands.filter(function (desc) { | ||||||
|       opts.commands.filter(function (desc) { |       return arg1 === desc[0].split(/\s+/)[0].split(':')[0] && desc[0].split(/\s+/)[0].split(':'); | ||||||
|  |     }).length > 1) { | ||||||
|  |       console.info(''); | ||||||
|  |       console.info("Here are all the '" + command + "'-related commands:"); | ||||||
|  |       printCmds( | ||||||
|  |         opts.commands.filter(function (desc) { | ||||||
|  |           var pair = desc[0].split(/\s+/)[0]; | ||||||
|  |           var psub = pair.split(sep)[0]; | ||||||
|  |           maxPairLen = Math.max(maxPairLen, pair.length); | ||||||
|  |           if (arg1 === psub || arg1 === pair) { | ||||||
|  |             maxCmdLen = Math.max(maxCmdLen, pair.length); | ||||||
|  |             return true; | ||||||
|  |           } | ||||||
|  |         }) | ||||||
|  |       ); | ||||||
|  |       console.info(''); | ||||||
|  |     } else { | ||||||
|  |       console.info(''); | ||||||
|  |       console.info("Here are all the options and flags for '" + arg1 + "':"); | ||||||
|  |       console.info(''); | ||||||
|  |       opts.commands.some(function (desc) { | ||||||
|         var pair = desc[0].split(/\s+/)[0]; |         var pair = desc[0].split(/\s+/)[0]; | ||||||
|         var psub = pair.split(sep)[0]; |         var psub = pair.split(sep)[0]; | ||||||
|         maxPairLen = Math.max(maxPairLen, pair.length); |         maxPairLen = Math.max(maxPairLen, pair.length); | ||||||
|         if (arg1 === psub || arg1 === pair) { |         if (arg1 !== psub && arg1 !== pair) { | ||||||
|           maxCmdLen = Math.max(maxCmdLen, pair.length); |           return false; | ||||||
|           return true; |  | ||||||
|         } |         } | ||||||
|       }) |         maxCmdLen = Math.max(maxCmdLen, pair.length); | ||||||
|     ); |         console.log('\t' + desc[0] + '\t# ' + desc[1]); | ||||||
|     console.info(''); |         (desc[2]||[]).forEach(function (flag) { | ||||||
|  |           var pair = flag.split(', '); | ||||||
|  |           var f = pair.shift(); | ||||||
|  |           var d = pair.join(', '); | ||||||
|  |           console.log('\t\t' + f + ' # ' + d); | ||||||
|  |         }); | ||||||
|  |         return true; | ||||||
|  |       }); | ||||||
|  |       console.info(''); | ||||||
|  |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   if (-1 === Object.keys(pairsMap).indexOf(cmd)) { |   if (-1 === Object.keys(pairsMap).indexOf(cmd)) { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user