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

Support Typhoeus options from command line #490

Merged
merged 1 commit into from
Jan 4, 2019

Conversation

SeanKilleen
Copy link
Contributor

@SeanKilleen SeanKilleen commented Sep 15, 2018

Hi all,

First off -- thanks for a great tool! It's useful enough that I went out of my way to use it for my Jekyll blog recently.

I noticed that there appear to have been some requests previously to support Typhoeus options from the command-line. I would also find this quite useful, even though we can currently use a ruby script to obtain the same things.

I figured I would take a shot at contributing this feature as an exercise to expand my own ruby capabilities as well as contribute something back that I and others have expressed interest in.

Along the way, I am open to guidance and direction. And I intend to ensure the specs are covered to your satisfaction.

Suggested Feature Set (as I understand it)

  • Enable users to pass --typhoeus-config CONFIG with a JSON-formatted config string which we then pass directly in as typhoeus options to the original options object. This is then merged with the defaults.

NOTE: I've examined proposing this with both a command line and a config file option, but am choosing to limit this PR to the cmdline option (will do a follow-up PR for allowing a file if the support is there for adding it).

Example Usage

bundle exec htmlproofer --typhoeus-config '{ "timeout": 100 }' ./_site

To Do (as I understand it)

  • Add --typhoeus-config option to mercenary wiring.
  • Add json as a dependency (to parse the json)
  • Config flag description
  • Test / run locally
  • Update README
  • Specs

Specs

  • When JSON parsing is invalid (for file & direct input), show a graceful error
  • When no Typhoeus config specified, should be equal to the defaults
  • When Typheous config specified, overwrites the defaults.

@SeanKilleen
Copy link
Contributor Author

SeanKilleen commented Sep 15, 2018

As of this point, when testing locally, the following command works as expected:

ruby htmlproofer --typhoeus-config '{ "timeout": 100, "verbose": true }' [directory I'm testing]

I see a longer timeout and verbose output.

So it does appear that this is parsing the JSON, passing it through, and mapping it on top of the defaults that html-proofer is supplying.

I know it's a far cry from being ready to go yet, but that result is encouraging.

@SeanKilleen
Copy link
Contributor Author

I noticed that the Travis CI build failed. Upon inspection, those appear to be two unrelated rubocop findings in areas I haven't modified. If you believe it's something to do with this PR, let me know and I'll be happy to modify.

@gjtorikian
Copy link
Owner

Hey, this is looking good!

I noticed that the Travis CI build failed. Upon inspection, those appear to be two unrelated rubocop findings in areas I haven't modified.

Thanks for that report. I merged a fix into master: #491

If you update your branch, the tests should pass.

I think the only thing keeping this from being merged in, really are spec tests; I'd also really like to see a rescue for the case where JSON.parse might be fed a non-JSON string. This should report as an error back to the CLI.

@SeanKilleen
Copy link
Contributor Author

@gjtorikian thanks for the feedback and being receptive to the PR! At first glance the spec updates seem doable for sure, just going to take a little time with it due to less familiarity with Ruby in general. I figure I'll do a few and then you can suggest others I may have missed?

@SeanKilleen
Copy link
Contributor Author

@gjtorikian hey! I'm looking into this and I don't see any specs set up specifically around the mercenary configuration and testing options, etc. I started testing check_file by passing in options but I realized that's later in the pipeline than is effective to test.

Am I missing the location of those specs? If they don't exist, would you prefer I:

  • Look into mercenary and try to create a spec around the passing of options?
  • Add the rescue clause and provide some screenshots of the outputs on my local?

Normally the first option would be my preference, but given the lack of familiarity I wonder if that's a heavy lift for this PR given my familiarity. Happen to take a stab at it if you prefer though.

@SeanKilleen
Copy link
Contributor Author

@gjtorikian I extracted the functionality into a new function that I'm hoping I can write specs around. Pushed some changes including empty specs and the beginnings of the refactor. Look good?

@codecov-io
Copy link

codecov-io commented Sep 23, 2018

Codecov Report

Merging #490 into master will increase coverage by 0.03%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #490      +/-   ##
==========================================
+ Coverage   98.27%   98.31%   +0.03%     
==========================================
  Files          27       28       +1     
  Lines        1802     1838      +36     
==========================================
+ Hits         1771     1807      +36     
  Misses         31       31
Impacted Files Coverage Δ
lib/html-proofer.rb 100% <100%> (ø) ⬆️
spec/html-proofer/parse_json_option_spec.rb 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c1ada79...a2d322f. Read the comment docs.

@SeanKilleen
Copy link
Contributor Author

SeanKilleen commented Sep 23, 2018

Apologies if you're getting push notifications on this -- I'm doing my dev in windows for convenience and need to push the changes so I can test them in my Ubuntu WSL instance, so there's some noise as I work through stuff.

I'll definitely be squashing these changes.

@SeanKilleen
Copy link
Contributor Author

@gjtorikian I think this might be ready to go -- as far as I can tell, all the related specs pass on my local (one unrelated spec is failing but appears to be to due more with a timeout).

I rebased to squash & clean stuff up as well. Would love your review when you get the chance!

@SeanKilleen SeanKilleen changed the title In Progress: Support Typhoeus options from command line Support Typhoeus options from command line Sep 23, 2018
@SeanKilleen
Copy link
Contributor Author

SeanKilleen commented Oct 6, 2018

@gjtorikian I think this is ready to go, so just checking in. The build is failing but my understanding is it's an unrelated timeout on an existing case and not due to my changes. I'll double-check to make sure.

Update: nevermind I can see the build output now and I see there's some rubocop violations to clean up. working on it now!

@SeanKilleen
Copy link
Contributor Author

@gjtorikian OK, I fixed all the rubocop issues and then rebased to squash / include them all in the larger commit. Now truly green & passing. ✅

@SeanKilleen
Copy link
Contributor Author

@gjtorikian wanted to check in on this. I'm sure you're probably busy, but I'd love to get it in soon or shore it up if you feel it's missing something. Or if it needs to wait for a bit, let me know and I'll stop bugging you. :)

  • Build passes
  • Rubocop issues fixed
  • Specs exist (at least as many as I can think of)
  • Local usage checks out on my WSL install

@SeanKilleen
Copy link
Contributor Author

@gjtorikian any word on this?

Copy link
Contributor

@Floppy Floppy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me!

@SeanKilleen
Copy link
Contributor Author

Thanks @Floppy!

@gjtorikian let me know if you think anything else is needed here.

@SeanKilleen
Copy link
Contributor Author

@gjtorikian checking in one more time on this.

✅ Build passing
✅ Additional tests created & passing
✅ Local usage confirms it works as intended as well
✅ Positive feedback received from you in Sept.
✅ Approved by @Floppy on Nov 19

Are there any hesitations I could address? Or would it be possible to get this merged soon? Happy to address any questions or concerns.

@gjtorikian gjtorikian merged commit a2d322f into gjtorikian:master Jan 4, 2019
@gjtorikian
Copy link
Owner

Hi, I'm very sorry for my delay in review here for this much requested feature! Personal life got in the way of open source, I'm afraid.

This looks nearly perfect--I simply moved the parse_json_option into the Configuration module, and changed up the syntax a bit.

Thank you so much for this contribution! And again, I'm sorry it took me so long to get back to you.

@SeanKilleen
Copy link
Contributor Author

No worries at all! I totally understand and I'm all about work-life balance. 👍 Glad this is useful and was able to make it in!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants