Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core(cli): accept flags from path #9109

Merged
merged 3 commits into from
Jun 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lighthouse-cli/cli-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ function getFlags(manualArgv) {
'lighthouse <url> --only-categories=performance,pwa',
'Only run specific categories.')

/**
* Also accept a file for all of these flags. Yargs will merge in and override the file-based
* flags with the command-line flags.
*
* i.e. when command-line `--throttling-method=provided` and file `throttlingMethod: "devtools"`,
* throttlingMethod will be `provided`.
*
* @see https://github.com/yargs/yargs/blob/a6e67f15a61558d0ba28bfe53385332f0ce5d431/docs/api.md#config
*/
.config('cli-flags-path')

// List of options
.group(['verbose', 'quiet'], 'Logging:')
.describe({
Expand All @@ -78,6 +89,7 @@ function getFlags(manualArgv) {
],
'Configuration:')
.describe({
'cli-flags-path': 'The path to a JSON file that contains the desired CLI flags to apply. Flags specified at the command line will still override the file-based ones.',
// We don't allowlist specific locales. Why? So we can support the user who requests 'es-MX' (unsupported) and we'll fall back to 'es' (supported)
'locale': 'The locale/language the report should be formatted in',
'enable-error-reporting':
Expand Down
19 changes: 19 additions & 0 deletions lighthouse-cli/test/cli/cli-flags-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,25 @@ describe('CLI bin', function() {
});
});

it('settings are accepted from a file path', () => {
const flags = getFlags([
'http://www.example.com',
`--cli-flags-path="${__dirname}/../fixtures/cli-flags-path.json"`,
'--budgets-path=path/to/my/budget-from-command-line.json', // this should override the config value
].join(' '));

expect(flags).toMatchObject({
budgetsPath: 'path/to/my/budget-from-command-line.json',
onlyCategories: ['performance', 'seo'],
chromeFlags: '--window-size 800,600',
throttlingMethod: 'devtools',
throttling: {
requestLatencyMs: 700,
cpuSlowdownMultiplier: 6,
},
});
});

it('array values support csv when appropriate', () => {
const flags = getFlags([
'http://www.example.com',
Expand Down
10 changes: 10 additions & 0 deletions lighthouse-cli/test/fixtures/cli-flags-path.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"budgetPath": "path/to/my/budget-from-config.json",
"onlyCategories": ["performance", "seo"],
"chromeFlags": "--window-size 800,600",
"throttling-method": "devtools",
"throttling": {
"requestLatencyMs": 700,
"cpuSlowdownMultiplier": 6
}
}
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ Output:
Options:
--help Show help [boolean]
--version Show version number [boolean]
--cli-flags-path The path to a JSON file that contains the desired CLI flags to apply.
Flags specified at the command line will still override the file-based ones.
--blocked-url-patterns Block any network requests to the specified URL patterns [array]
--disable-storage-reset Disable clearing the browser cache and other storage APIs before a run [boolean]
--throttling-method Controls throttling method [choices: "devtools", "provided", "simulate"]
Expand Down