@@ -6,6 +6,7 @@ const validator = require("validator");
6
6
const cmdConfig = require ( "./cmdconfig" ) ;
7
7
const assert = require ( "assert" ) ;
8
8
9
+ < << << << HEAD
9
10
module . exports . validate = function ( )
10
11
{
11
12
const options = cmdConfig . options ;
@@ -56,12 +57,65 @@ assert(options._all.url,"No url specified");
56
57
console . error ( err . message ) ;
57
58
}
58
59
}
59
-
60
- if ( assertCount || options . _all . help )
61
- {
62
- console . error ( cmdConfig . usage ) ;
63
- return false ;
64
- }
65
-
66
- return true ;
60
+ = === ===
61
+ module . exports . validate = function ( ) {
62
+ const options = cmdConfig . options ;
63
+ let errors = [ ] ;
64
+ errors = validateEmptyURL ( options . _all . url , errors ) ;
65
+ errors = validateURLFormat ( options . _all . url , errors ) ;
66
+ errors = validateConcurrency ( options . _all . concurrency , errors ) ;
67
+ errors = validateNesting ( options . _all . nesting , errors ) ;
68
+ return errors ;
67
69
} ;
70
+
71
+ function validateEmptyURL ( url , errors ) {
72
+ try {
73
+ assert ( url , "No url specified" ) ;
74
+ } catch ( err ) {
75
+ errors . push ( err . message ) ;
76
+ }
77
+ return errors ;
78
+ }
79
+ >>> > >>> development
80
+
81
+ function validateURLFormat ( url , errors ) {
82
+ if ( url ) {
83
+ try {
84
+ assert ( validator . isURL ( url , {
85
+ protocols : [ "http" , "https" ] ,
86
+ require_host : true ,
87
+ require_valid_protocol : true ,
88
+ require_protocols : true
89
+ } ) , url + " is invalid." ) ;
90
+ } catch ( err ) {
91
+ errors . push ( err . message ) ;
92
+ }
93
+ }
94
+ return errors ;
95
+ }
96
+
97
+ function validateConcurrency ( concurrency , errors ) {
98
+ if ( concurrency !== undefined ) {
99
+ try {
100
+ assert ( validator . isInt ( concurrency . toString ( ) , {
101
+ min : 1
102
+ } ) , "Concurrency must be greater than 0" ) ;
103
+ } catch ( err ) {
104
+ errors . push ( err . message ) ;
105
+ }
106
+ }
107
+ return errors ;
108
+ }
109
+
110
+ function validateNesting ( nesting , errors ) {
111
+ if ( nesting !== undefined ) {
112
+ try {
113
+ assert ( validator . isInt ( nesting . toString ( ) , {
114
+ gt : 0
115
+ } ) , "Nesting must be greater than 0" ) ;
116
+ } catch ( err ) {
117
+ errors . push ( err . message ) ;
118
+ }
119
+ }
120
+ return errors ;
121
+ }
0 commit comments