@@ -13,7 +13,7 @@ import {
1313 Prefixes ,
1414 FlagConfig ,
1515} from './option'
16- import { DeepRequired , setOrPush , deepMerge , getErrorMessage } from './utils'
16+ import { DeepRequired , setOrPush , deepMerge , getErrorMessage , capitalize } from './utils'
1717import { MassargExample , ExampleConfig } from './example'
1818import { format } from './style'
1919
@@ -187,7 +187,7 @@ export class MassargCommand<Args extends ArgsObject = ArgsObject> {
187187 flag ( config : FlagConfig | MassargFlag ) : MassargCommand < Args > {
188188 try {
189189 const flag = config instanceof MassargFlag ? config : new MassargFlag ( config )
190- this . assertNotDuplicate ( flag )
190+ this . assertNotDuplicate ( flag , 'flag' )
191191 this . options . push ( flag as MassargOption )
192192 return this
193193 } catch ( e ) {
@@ -227,7 +227,7 @@ export class MassargCommand<Args extends ArgsObject = ArgsObject> {
227227 config instanceof MassargOption
228228 ? config
229229 : MassargOption . fromTypedConfig ( config as TypedOptionConfig < T , A > )
230- this . assertNotDuplicate ( option )
230+ this . assertNotDuplicate ( option , 'option' )
231231 this . assertOnlyOneDefault < T , A > ( option )
232232 this . options . push ( option as MassargOption )
233233 return this
@@ -243,12 +243,15 @@ export class MassargCommand<Args extends ArgsObject = ArgsObject> {
243243 }
244244 }
245245
246- private assertNotDuplicate < T = string , A extends ArgsObject = Args > ( option : MassargOption < T , A > ) {
247- const existingName = this . options . find ( ( c ) => c . name === option . name ) )
246+ private assertNotDuplicate < T = string , A extends ArgsObject = Args > (
247+ option : MassargOption < T , A > ,
248+ type : 'option' | 'flag' ,
249+ ) {
250+ const existingName = this . options . find ( ( c ) => c . name === option . name )
248251 if ( existingName ) {
249252 throw new ValidationError ( {
250- code : 'duplicate_option_name' ,
251- message : `Option name "${ existingName . name } " already exists` ,
253+ code : `duplicate_ ${ type } _name` ,
254+ message : `${ capitalize ( type ) } name "${ existingName . name } " already exists` ,
252255 path : [ this . name , option . name ] ,
253256 } )
254257 }
0 commit comments