@@ -31,7 +31,9 @@ export class Option {
3131
3232 public path ?: string ,
3333
34- public parent ?: Command
34+ public parent ?: Command ,
35+
36+ public argName : string = "VALUE"
3537 ) {
3638
3739 }
@@ -43,12 +45,12 @@ export class Option {
4345
4446 public static isValidName ( name : string ) : boolean {
4547
46- return / ^ [ a - z A - Z 0 - 9 ] [ - a - z A - Z 0 - 9 ] + $ / . test ( name ) ;
48+ return / ^ [ a - z 0 - 9 ] [ - a - z 0 - 9 ] + $ / i . test ( name ) ;
4749 }
4850
4951 public static isValidShortcut ( shortcut : string ) : boolean {
5052
51- return / ^ [ a - z A - Z 0 - 9 ] $ / . test ( shortcut ) ;
53+ return / ^ [ a - z 0 - 9 ] $ / i . test ( shortcut ) ;
5254 }
5355
5456}
@@ -73,7 +75,7 @@ export class Command {
7375
7476 public description : string ,
7577
76- public alias ?: string [ ] ,
78+ public aliases ?: string [ ] ,
7779
7880 public parent ?: Command
7981 ) {
@@ -99,6 +101,16 @@ export class Command {
99101 return null ;
100102 }
101103
104+ public get hasSubCommands ( ) : boolean {
105+
106+ return ! ! Object . keys ( this . subCommands ) . length ;
107+ }
108+
109+ public get hasOptions ( ) : boolean {
110+
111+ return ! ! Object . keys ( this . options ) . length ;
112+ }
113+
102114 public getOptionByShortcut ( shortcut : string ) : Option | null {
103115
104116 if ( this . optionShortcuts [ shortcut ] ) {
@@ -116,12 +128,12 @@ export class Command {
116128
117129 public static isValidName ( name : string ) : boolean {
118130
119- return / ^ [ - a - z A - Z 0 - 9 ] + $ / . test ( name ) ;
131+ return / ^ [ a - z 0 - 9 ] [ - a - z 0 - 9 ] * $ / i . test ( name ) ;
120132 }
121133
122134 public static isValidPath ( path : string ) : boolean {
123135
124- return / ^ [ - a - z A - Z 0 - 9 ] + ( \. [ - a - z A - Z 0 - 9 ] + ) * $ / . test ( path ) ;
136+ return / ^ [ a - z 0 - 9 ] [ - a - z 0 - 9 ] * ( \. [ a - z 0 - 9 ] [ - a - z 0 - 9 ] * ) * $ / i . test ( path ) ;
125137 }
126138}
127139
@@ -143,6 +155,50 @@ export abstract class AbstractParser implements C.IParser {
143155 this . _cmdAliases = { } ;
144156 this . _options = { } ;
145157 this . _optionShortcuts = { } ;
158+
159+ if ( this . _config . help . delegated ) {
160+
161+ if (
162+ ! this . _config . help . flag &&
163+ ! this . _config . help . command
164+ ) {
165+
166+ throw new E . E_CONFLICT_CONFIG ( {
167+ "message" : "Must enable at least one of help-command or help-flag."
168+ } ) ;
169+ }
170+ }
171+
172+ if ( this . _config . help . delegated && this . _config . help . flag ) {
173+
174+ this . addOption ( {
175+ "name" : "help" ,
176+ "description" : "Display the help information." ,
177+ "shortcut" : this . _config . help . flagShortchut ? "h" : undefined ,
178+ "arguments" : 0
179+ } ) ;
180+ }
181+
182+ if (
183+ ! this . _config . options . long . followArgument &&
184+ ! this . _config . options . long . assignArgument
185+ ) {
186+
187+ throw new E . E_CONFLICT_CONFIG ( {
188+ "message" : "Must enable at least one of follow-mode or assign-mode."
189+ } ) ;
190+ }
191+
192+ if (
193+ ! this . _config . options . shortcut . followArgument &&
194+ ! this . _config . options . shortcut . assignArgument &&
195+ ! this . _config . options . shortcut . attachArgument
196+ ) {
197+
198+ throw new E . E_CONFLICT_CONFIG ( {
199+ "message" : "Must enable at least one of follow-mode, attach-mode or assign-mode."
200+ } ) ;
201+ }
146202 }
147203
148204 public addCommand ( settings : C . ICommandSettings ) : this {
@@ -156,7 +212,7 @@ export abstract class AbstractParser implements C.IParser {
156212
157213 if ( settings . path ) {
158214
159- const cmd = this . _findCommandByPath ( settings . path ) ;
215+ const cmd = this . _getCommandByPath ( settings . path ) ;
160216
161217 if ( ! cmd ) {
162218
@@ -249,7 +305,8 @@ export abstract class AbstractParser implements C.IParser {
249305 settings ,
250306 path ,
251307 optName ,
252- optShortcut
308+ optShortcut ,
309+ settings . argumentName
253310 ) ;
254311 }
255312 }
@@ -258,7 +315,8 @@ export abstract class AbstractParser implements C.IParser {
258315 this . _addOption (
259316 settings ,
260317 optName ,
261- optShortcut
318+ optShortcut ,
319+ settings . argumentName
262320 ) ;
263321 }
264322
@@ -269,10 +327,11 @@ export abstract class AbstractParser implements C.IParser {
269327 settings : C . IOptionSettings ,
270328 path : string ,
271329 optName : string ,
272- optShortcut : string | undefined
330+ optShortcut : string | undefined ,
331+ argName ?: string
273332 ) : void {
274333
275- const cmd = this . _findCommandByPath ( path ) ;
334+ const cmd = this . _getCommandByPath ( path ) ;
276335
277336 if ( ! cmd ) {
278337
@@ -301,7 +360,8 @@ export abstract class AbstractParser implements C.IParser {
301360 optShortcut ,
302361 settings . arguments ,
303362 path ,
304- cmd
363+ cmd ,
364+ argName
305365 ) ;
306366
307367 if ( optShortcut ) {
@@ -313,7 +373,8 @@ export abstract class AbstractParser implements C.IParser {
313373 protected _addOption (
314374 settings : C . IOptionSettings ,
315375 optName : string ,
316- optShortcut : string | undefined
376+ optShortcut : string | undefined ,
377+ argName ?: string
317378 ) : void {
318379
319380 if ( this . _options [ optName ] ) {
@@ -334,7 +395,10 @@ export abstract class AbstractParser implements C.IParser {
334395 optName ,
335396 settings . description ,
336397 optShortcut ,
337- settings . arguments
398+ settings . arguments ,
399+ undefined ,
400+ undefined ,
401+ argName
338402 ) ;
339403
340404 if ( optShortcut ) {
@@ -413,7 +477,7 @@ export abstract class AbstractParser implements C.IParser {
413477 return ret ;
414478 }
415479
416- protected _findCommandByPath ( path : string ) : Command | null {
480+ protected _getCommandByPath ( path : string ) : Command | null {
417481
418482 path = this . _prepareCommandPath ( path ) ;
419483
@@ -434,5 +498,11 @@ export abstract class AbstractParser implements C.IParser {
434498 }
435499 }
436500
437- public abstract parse ( args : string [ ] ) : C . IResult | false ;
501+ public abstract parse ( args : string [ ] ) : C . IResult ;
502+
503+ public abstract generateHelp (
504+ appName : string ,
505+ path : string ,
506+ width ?: number
507+ ) : string [ ] ;
438508}
0 commit comments