argv-flags 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +26 -24
- package/package.json +1 -2
package/index.js
CHANGED
|
@@ -1,41 +1,43 @@
|
|
|
1
1
|
function parseFlag ( targetArgument, argumentType ) {
|
|
2
2
|
const processArguments = process.argv;
|
|
3
|
-
let argsIndex = [];
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
if ( processArguments[key].charAt( 0 ) === '-' && processArguments[key].charAt( 0 ) === '-' ) {
|
|
7
|
-
argsIndex.push( [ processArguments[key], key ] );
|
|
8
|
-
}
|
|
9
|
-
}
|
|
4
|
+
if ( processArguments.includes( targetArgument ) ) {
|
|
10
5
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return processArguments[Number( key ) + 1];
|
|
6
|
+
if ( argumentType === 'string' ) {
|
|
7
|
+
return processArguments[processArguments.indexOf( targetArgument ) + 1];
|
|
14
8
|
}
|
|
9
|
+
|
|
10
|
+
if ( argumentType === 'array' ) {
|
|
11
|
+
|
|
12
|
+
let flagsIndex = [];
|
|
13
|
+
|
|
14
|
+
for ( const key in processArguments ) {
|
|
15
|
+
if ( processArguments[key].charAt( 0 ) === '-' && processArguments[key].charAt( 0 ) === '-' ) {
|
|
16
|
+
flagsIndex.push( [ processArguments[key], key ] );
|
|
17
|
+
}
|
|
18
|
+
}
|
|
15
19
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return processArguments.slice( Number( argsIndex[key][1] ) + 1, argsIndex[Number( key ) + 1][1] );
|
|
20
|
+
for ( const key in flagsIndex ) {
|
|
21
|
+
if ( flagsIndex[key][0] === targetArgument ) {
|
|
22
|
+
if ( flagsIndex[key][1] < flagsIndex[flagsIndex.length - 1][1] ) {
|
|
23
|
+
return processArguments.slice( Number( flagsIndex[key][1] ) + 1, flagsIndex[Number( key ) + 1][1] );
|
|
21
24
|
} else {
|
|
22
|
-
return processArguments.slice( Number(
|
|
25
|
+
return processArguments.slice( Number( flagsIndex[key][1] ) + 1 );
|
|
23
26
|
}
|
|
24
27
|
}
|
|
25
28
|
}
|
|
26
29
|
}
|
|
27
|
-
|
|
30
|
+
|
|
28
31
|
if ( argumentType === 'boolean' ) {
|
|
29
|
-
|
|
30
|
-
return true;
|
|
31
|
-
}
|
|
32
|
-
return false;
|
|
32
|
+
return true;
|
|
33
33
|
}
|
|
34
|
-
|
|
35
|
-
if ( argumentType === 'number'
|
|
36
|
-
return Number( processArguments[
|
|
34
|
+
|
|
35
|
+
if ( argumentType === 'number' ) {
|
|
36
|
+
return Number( processArguments[processArguments.indexOf( targetArgument ) + 1] );
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
+
|
|
40
|
+
return false;
|
|
39
41
|
}
|
|
40
42
|
|
|
41
|
-
|
|
43
|
+
module.exports = parseFlag;
|