|
5 | 5 | /*global CSSLint*/
|
6 | 6 | function cli(api){
|
7 | 7 |
|
| 8 | + var globalOptions = { |
| 9 | + "help" : { "format" : "", "description" : "Displays this information."}, |
| 10 | + "format" : { "format" : "<format>", "description" : "Indicate which format to use for output."}, |
| 11 | + "list-rules" : { "format" : "", "description" : "Outputs all of the rules available."}, |
| 12 | + "quiet" : { "format" : "", "description" : "Only output when errors are present."}, |
| 13 | + "errors" : { "format" : "<rule[,rule]+>", "description" : "Indicate which rules to include as errors."}, |
| 14 | + "warnings" : { "format" : "<rule[,rule]+>", "description" : "Indicate which rules to include as warnings."}, |
| 15 | + "ignore" : { "format" : "<rule[,rule]+>", "description" : "Indicate which rules to ignore completely."}, |
| 16 | + "exclude-list": { "format" : "<file|dir[,file|dir]+>", "description" : "Indicate which files/directories to exclude from being linted."}, |
| 17 | + "version" : { "format" : "", "description" : "Outputs the current version number."} |
| 18 | + }; |
| 19 | + |
8 | 20 | //-------------------------------------------------------------------------
|
9 | 21 | // Helper functions
|
10 | 22 | //-------------------------------------------------------------------------
|
@@ -158,20 +170,35 @@ function cli(api){
|
158 | 170 | * @return {void}
|
159 | 171 | */
|
160 | 172 | function outputHelp(){
|
| 173 | + var lenToPad = 40, |
| 174 | + toPrint = '', |
| 175 | + formatString = ''; |
| 176 | + |
161 | 177 | api.print([
|
162 | 178 | "\nUsage: csslint-rhino.js [options]* [file|dir]*",
|
163 | 179 | " ",
|
164 |
| - "Global Options", |
165 |
| - " --help Displays this information.", |
166 |
| - " --format=<format> Indicate which format to use for output.", |
167 |
| - " --list-rules Outputs all of the rules available.", |
168 |
| - " --quiet Only output when errors are present.", |
169 |
| - " --errors=<rule[,rule]+> Indicate which rules to include as errors.", |
170 |
| - " --warnings=<rule[,rule]+> Indicate which rules to include as warnings.", |
171 |
| - " --ignore=<rule[,rule]+> Indicate which rules to ignore completely.", |
172 |
| - " --exclude-list=<file|dir[,file|dir]+> Indicate which files/directories to exclude from being linted.", |
173 |
| - " --version Outputs the current version number." |
174 |
| - ].join("\n") + "\n"); |
| 180 | + "Global Options" |
| 181 | + ].join("\n")); |
| 182 | + |
| 183 | + for (var optionName in globalOptions) { |
| 184 | + if (globalOptions.hasOwnProperty(optionName)) { |
| 185 | + // Print the option name and the format if present |
| 186 | + toPrint += " --" + optionName; |
| 187 | + if (globalOptions[optionName].format !== "") { |
| 188 | + formatString = '=' + globalOptions[optionName].format; |
| 189 | + toPrint += formatString; |
| 190 | + } else { |
| 191 | + formatString = ''; |
| 192 | + } |
| 193 | + |
| 194 | + // Pad out with the appropriate number of spaces |
| 195 | + toPrint += Array(lenToPad - (optionName.length + formatString.length)).join(' '); |
| 196 | + |
| 197 | + // Print the description |
| 198 | + toPrint += globalOptions[optionName].description + "\n"; |
| 199 | + } |
| 200 | + } |
| 201 | + api.print(toPrint); |
175 | 202 | }
|
176 | 203 |
|
177 | 204 | /**
|
@@ -255,6 +282,16 @@ function cli(api){
|
255 | 282 | return options;
|
256 | 283 | }
|
257 | 284 |
|
| 285 | + function validateOptions(options) { |
| 286 | + for (var option_key in options) { |
| 287 | + if (!globalOptions.hasOwnProperty(option_key) && option_key !== 'files') { |
| 288 | + api.print(option_key + ' is not a valid option. Exiting...'); |
| 289 | + outputHelp(); |
| 290 | + api.quit(0); |
| 291 | + } |
| 292 | + } |
| 293 | + } |
| 294 | + |
258 | 295 | function readConfigFile(options) {
|
259 | 296 | var data = api.readFile(api.getFullPath(".csslintrc"));
|
260 | 297 | if (data) {
|
@@ -285,6 +322,9 @@ function cli(api){
|
285 | 322 | api.quit(0);
|
286 | 323 | }
|
287 | 324 |
|
| 325 | + // Validate options |
| 326 | + validateOptions(options); |
| 327 | + |
288 | 328 | if (options.version){
|
289 | 329 | api.print("v" + CSSLint.version);
|
290 | 330 | api.quit(0);
|
|
0 commit comments