File tree 2 files changed +14
-5
lines changed
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 {
18
18
* @version 1.0.0
19
19
* @since 0.0.1-alpha
20
20
*/
21
- export function resolve ( ) {
21
+ export function resolve ( _args : string [ ] = full ) {
22
22
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 ] ;
25
25
26
26
if ( ! s . startsWith ( '-' ) && command === undefined ) command = s ;
27
27
28
28
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 ] ;
31
31
i ++ ;
32
32
}
33
33
You can’t perform that action at this time.
0 commit comments