diff --git a/lib/cli.js b/lib/cli.js index 9b5edd5fe..408500015 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -26,6 +26,15 @@ var validatePathOption = function(optionName, path) { } }; +var isJsonString = function(str) { + try { + JSON.parse(str); + } catch (e) { + return false; + } + return true; +}; + var cli = nomnom.help( 'sitespeed.io is a tool that helps you analyze your website performance and show you what you should optimize, more info at http://www.sitespeed.io.' + EOL + @@ -404,13 +413,20 @@ var cli = nomnom.help( help: 'The API key if running on webpagetest on the public instances.' }, requestHeaders: { - metavar: '', - help: 'Any request headers to use, a file with JSON form of {\"name\":\"value\",\"name2\":\"value\"}. Not supported for WPT & GPSI.', + metavar: '|
', + type: 'string', + help: 'Any request headers to use, a file or a header string with JSON form of {\"name\":\"value\",\"name2\":\"value\"}. Not supported for WPT & GPSI.', callback: function(path) { - return validatePathOption('requestHeaders', path); + if (!fs.existsSync(path) && !isJsonString(path)) { + return '--requestHeaders: \'' + path + '\' is not a file or not a valid JSON header string!'; + } }, transform: function(path) { - return fileHelper.getFileAsJSON(path); + if (fs.existsSync(path)) { + return fileHelper.getFileAsJSON(path); + } else { + return JSON.parse(path); + } } }, postURL: {