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

CLI - fix options handling #271

Merged
merged 3 commits into from
Mar 22, 2021
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
9 changes: 6 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@ jobs:
npm test

- name: Run bin/analyze-css.js for CSS file
run: ./bin/analyze-css.js --file examples/ti.mobile.css -p | grep metrics -B2
run: ./bin/analyze-css.js --file examples/ti.mobile.css -p | jq .metrics

- name: Run bin/analyze-css.js for SCSS file
run: ./bin/analyze-css.js --file examples/base.scss -p | grep offenders -A3
run: ./bin/analyze-css.js --file examples/base.scss -p | jq .offenders

- name: Run bin/analyze-css.js for stdin-provided CSS
run: cat examples/ti.mobile.css | ./bin/analyze-css.js - | jq .metrics

- name: Run bin/analyze-css.js for external file over HTTP
run: ./bin/analyze-css.js --url http://s3.macbre.net/analyze-css/propertyResets.css -p | grep metrics -A5
run: ./bin/analyze-css.js --url http://s3.macbre.net/analyze-css/propertyResets.css -p | jq .metrics
13 changes: 8 additions & 5 deletions bin/analyze-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,23 @@ program

// parse it
program.parse(process.argv);
const options = program.opts();

debug("analyze-css v%s", analyzer.version);
debug("argv %j", process.argv);
debug("opts %j", options);

// support stdin (issue #28)
if (process.argv.indexOf("-") > -1) {
runnerOpts.stdin = true;
}
// --url
else if (program.url) {
runnerOpts.url = program.url;
else if (options.url) {
runnerOpts.url = options.url;
}
// --file
else if (program.file) {
runnerOpts.file = program.file;
else if (options.file) {
runnerOpts.file = options.file;
}
// either --url or --file or - (stdin) needs to be provided
else {
Expand All @@ -70,7 +73,7 @@ runnerOpts.authUser = program["auth-user"];
runnerOpts.authPass = program["auth-pass"];
runnerOpts.proxy = program.proxy;

debug("opts: %j", runnerOpts);
debug("runner opts: %j", runnerOpts);

// run the analyzer
runner(runnerOpts, function (err, res) {
Expand Down