11'use strict' ;
22
33const {
4- ArrayIsArray,
54 ArrayPrototypeConcat,
65 ArrayPrototypeIncludes,
76 ArrayPrototypeSlice,
87 ArrayPrototypePush,
8+ ObjectHasOwn,
99 StringPrototypeCharAt,
1010 StringPrototypeIncludes,
1111 StringPrototypeIndexOf,
1212 StringPrototypeSlice,
1313 StringPrototypeStartsWith,
1414} = require ( './primordials' ) ;
1515
16+ const {
17+ codes : {
18+ ERR_NOT_IMPLEMENTED
19+ }
20+ } = require ( './errors' ) ;
21+
22+ const {
23+ validateArray,
24+ validateObject
25+ } = require ( './validators' ) ;
26+
1627function getMainArgs ( ) {
1728 // This function is a placeholder for proposed process.mainArgs.
1829 // Work out where to slice process.argv for user supplied arguments.
@@ -75,11 +86,12 @@ const parseArgs = (
7586 argv = getMainArgs ( ) ,
7687 options = { }
7788) => {
78- if ( typeof options !== 'object' || options === null ) {
79- throw new Error ( 'Whoops!' ) ;
80- }
81- if ( options . withValue !== undefined && ! ArrayIsArray ( options . withValue ) ) {
82- throw new Error ( 'Whoops! options.withValue should be an array.' ) ;
89+ validateArray ( argv , 'argv' ) ;
90+ validateObject ( options , 'options' ) ;
91+ for ( const key of [ 'withValue' , 'multiples' ] ) {
92+ if ( ObjectHasOwn ( options , key ) ) {
93+ validateArray ( options [ key ] , `options.${ key } ` ) ;
94+ }
8395 }
8496
8597 const result = {
@@ -104,7 +116,7 @@ const parseArgs = (
104116 } else if (
105117 StringPrototypeCharAt ( arg , 1 ) !== '-'
106118 ) { // Look for shortcodes: -fXzy
107- throw new Error ( 'What are we doing with shortcodes!?! ') ;
119+ throw new ERR_NOT_IMPLEMENTED ( ' shortcodes') ;
108120 }
109121
110122 arg = StringPrototypeSlice ( arg , 2 ) ; // remove leading --
0 commit comments