@@ -19,8 +19,8 @@ import { CommandParseResult } from "./class.ParseResult";
1919import * as External from "./interfaces" ;
2020import * as Errors from "./errors" ;
2121import * as Internal from "./internal" ;
22- import MainCommand = require ( "./class.MainCommand" ) ;
23- import { SimpleParser } from "./class.SimpleParser" ;
22+ import MainCommand from "./class.MainCommand" ;
23+ import SimpleParser from "./class.SimpleParser" ;
2424
2525export class CommandParser extends SimpleParser implements External . ICommandParser {
2626
@@ -37,7 +37,7 @@ export class CommandParser extends SimpleParser implements External.ICommandPars
3737 this . _shortMainCommands = { } ;
3838 }
3939
40- public addCommand ( opts : External . ICommandSettings ) : External . ICommandParser {
40+ public addCommand ( opts : External . ICommandSettings ) : this {
4141
4242 opts . name = opts . name . toLowerCase ( ) ;
4343
@@ -70,7 +70,7 @@ export class CommandParser extends SimpleParser implements External.ICommandPars
7070 public addSubCommand (
7171 main : string ,
7272 opts : External . ICommandSettings
73- ) : External . ICommandParser {
73+ ) : this {
7474
7575 main = main . toLowerCase ( ) ;
7676
@@ -106,20 +106,25 @@ export class CommandParser extends SimpleParser implements External.ICommandPars
106106 ) ;
107107 }
108108
109- if ( ! ret . mainCommand ) {
109+ if ( ! this . _settings . allowOptionsOnly ) {
110110
111- throw new Exception (
112- Errors . E_LACK_MAIN_COMMAND ,
113- "No command input."
114- ) ;
115- }
111+ if ( ! ret . mainCommand ) {
112+
113+ throw new Exception (
114+ Errors . E_LACK_MAIN_COMMAND ,
115+ "No command input."
116+ ) ;
117+ }
116118
117- if ( ! ret . subCommand && this . _mainCommands [ ret . mainCommand ] . enableSubCommand ) {
119+ if ( ! ret . subCommand
120+ && this . _mainCommands [ ret . mainCommand ] . enableSubCommand
121+ ) {
118122
119- throw new Exception (
120- Errors . E_LACK_SUB_COMMAND ,
121- "No sub command input."
122- ) ;
123+ throw new Exception (
124+ Errors . E_LACK_SUB_COMMAND ,
125+ "No sub command input."
126+ ) ;
127+ }
123128 }
124129
125130 ret . setSuccess ( ) ;
0 commit comments