File tree Expand file tree Collapse file tree 2 files changed +14
-5
lines changed Expand file tree Collapse file tree 2 files changed +14
-5
lines changed Original file line number Diff line number Diff line change 1+ import { expect , test } from '@jest/globals' ;
2+ import { arg } from './arg.js' ;
3+
4+ test ( 'Argument resolver should work.' , ( ) => {
5+ const args = arg . resolve ( [ 'help' , '--watch' , '-version' , '1.0' ] ) ;
6+ expect ( arg . getCommand ( ) ) . toBe ( 'hello' ) ;
7+ expect ( arg . hasFlag ( 'watch' ) ) . toBe ( true ) ;
8+ expect ( arg . getArgument ( 'version' ) ) . toBe ( '1.0' ) ;
9+ } ) ;
Original file line number Diff line number Diff line change @@ -18,16 +18,16 @@ export namespace arg {
1818 * @version 1.0.0
1919 * @since 0.0.1-alpha
2020 */
21- export function resolve ( ) {
21+ export function resolve ( _args : string [ ] = full ) {
2222
23- for ( let i = 0 ; i < full . length ; i ++ ) {
24- const s = full [ i ] ;
23+ for ( let i = 0 ; i < _args . length ; i ++ ) {
24+ const s = _args [ i ] ;
2525
2626 if ( ! s . startsWith ( '-' ) && command === undefined ) command = s ;
2727
2828 if ( s . match ( argumentRegex ) ) {
29- if ( full [ i + 1 ] === undefined || full [ i + 1 ] . match ( argumentRegex ) || full [ i + 1 ] . match ( flagRegex ) ) log . exit . error ( `Argument ${ chalk . gray ( s ) } not specified` ) ;
30- args [ s . slice ( 1 ) ] = full [ i + 1 ] ;
29+ if ( _args [ i + 1 ] === undefined || _args [ i + 1 ] . match ( argumentRegex ) || _args [ i + 1 ] . match ( flagRegex ) ) log . exit . error ( `Argument ${ chalk . gray ( s ) } not specified` ) ;
30+ args [ s . slice ( 1 ) ] = _args [ i + 1 ] ;
3131 i ++ ;
3232 }
3333
You can’t perform that action at this time.
0 commit comments