Skip to content

Commit

Permalink
Merge pull request #271 from macbre/fix-bin-opts-handling
Browse files Browse the repository at this point in the history
CLI - fix options handling
  • Loading branch information
macbre authored Mar 22, 2021
2 parents ff71bc4 + 3c471bd commit 4fd258d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
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

0 comments on commit 4fd258d

Please sign in to comment.