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

clarify CLI booleans #738

Merged
merged 1 commit into from
Jul 26, 2022
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
30 changes: 19 additions & 11 deletions bin/htmlproofer
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ Mercenary.program(:htmlproofer) do |p|

p.description 'Runs the HTML-Proofer suite on the files in PATH. For more details, see the README.'

p.option 'allow_hash_href', '--allow-hash-href', 'If `true`, assumes `href="#"` anchors are valid'
p.option 'allow_missing_href', '--allow-missing-href', 'If `true`, does not flag `a` tags missing `href`. In HTML5, this is technically allowed, but could also be human error.'
p.option 'allow_hash_href', '--allow-hash-href=<true|false>', 'String', 'If `true`, assumes `href="#"` anchors are valid (default: `true`)'
p.option 'allow_missing_href', '--allow-missing-href=<true|false>', 'String', 'If `true`, does not flag `a` tags missing `href`. In HTML5, this is technically allowed, but could also be human error. (default: `false`)'
p.option 'as_links', '--as-links', 'Assumes that `PATH` is a comma-separated array of links to check.'
p.option 'assume_extension', '--assume-extension <ext>', 'Automatically add specified extension to files for internal links, to allow extensionless URLs (as supported by most servers) (default: `.html`).'
p.option 'checks', '--checks check1,[check2,...]', Array, 'A comma-separated list of Strings indicating which checks you want to run (default: `["Links", "Images", "Scripts"]`)'
p.option 'check_external_hash', '--check-external-hash', 'Checks whether external hashes exist (even if the webpage exists) (default: `true`).'
p.option 'check_internal_hash', '--check-internal-hash', 'Checks whether internal hashes exist (even if the webpage exists) (default: `true`).'
p.option 'check_sri', '--check-sri', 'Check that `<link>` and `<script>` external resources use SRI (default: `false`).'
p.option 'check_external_hash', '--check-external-hash=<true|false>', 'String', 'Checks whether external hashes exist (even if the webpage exists) (default: `true`).'
p.option 'check_internal_hash', '--check-internal-hash=<true|false>', 'String', 'Checks whether internal hashes exist (even if the webpage exists) (default: `true`).'
p.option 'check_sri', '--check-sri=<true|false>', 'String', 'Check that `<link>` and `<script>` external resources use SRI (default: `false`).'
p.option 'directory_index_file', '--directory-index-file <filename>', String, 'Sets the file to look for when a link refers to a directory. (default: `index.html`)'
p.option 'disable_external', '--disable-external', 'If `true`, does not run the external link checker (default: `false`)'
p.option 'enforce_https', '--enforce-https <false>', String, 'Fails a link if it\'s not marked as `https` (default: `true`).'
p.option 'disable_external', '--disable-external=<true|false>', String, 'If `true`, does not run the external link checker (default: `false`)'
p.option 'enforce_https', '--enforce-https=<true|false>', String, 'Fails a link if it\'s not marked as `https` (default: `true`).'
p.option 'extensions', '--extensions ext1,[ext2,...[', Array, 'A comma-separated list of Strings indicating the file extensions you would like to check (including the dot) (default: `.html`)'
p.option 'ignore_empty_alt', '--ignore-empty-alt', ' If `true`, ignores images with empty/missing alt tags (in other words, `<img alt>` and `<img alt="">` are valid; set this to `false` to flag those)'
p.option 'ignore_empty_alt', '--ignore-empty-alt=<true|false>', 'String', 'If `true`, ignores images with empty/missing alt tags (in other words, `<img alt>` and `<img alt="">` are valid; set this to `false` to flag those) (default: `true`)'
p.option 'ignore_empty_mailto', '--ignore-empty-mailto=<true|false>', 'String', 'If `true`, allows `mailto:` `href`s which do not contain an email address (default: `false`)'
p.option 'ignore_files', '--ignore-files file1,[file2,...]', Array, 'A comma-separated list of Strings or RegExps containing file paths that are safe to ignore'
p.option 'ignore_empty_mailto', '--ignore-empty-mailto', 'If `true`, allows `mailto:` `href`s which do not contain an email address'
p.option 'ignore_missing_alt', '--ignore-missing-alt', 'If `true`, ignores images with missing alt tags'
p.option 'ignore_missing_alt', '--ignore-missing-alt=<true|false>', 'String', 'If `true`, ignores images with missing alt tags (default: `false`)'
p.option 'ignore_status_codes', '--ignore-status-codes 123,[xxx, ...]', Array, 'A comma-separated list of numbers representing status codes to ignore.'
p.option 'ignore_urls', '--ignore-urls link1,[link2,...]', Array, 'A comma-separated list of Strings or RegExps containing URLs that are safe to ignore. This affects all HTML attributes, such as `alt` tags on images.'
p.option 'log_level', '--log-level <level>', String, 'Sets the logging level, as determined by Yell. One of `:debug`, `:info`, `:warn`, `:error`, or `:fatal`. (default: `:info`)'
Expand Down Expand Up @@ -68,7 +68,15 @@ Mercenary.program(:htmlproofer) do |p|
end
end

options[:enforce_https] = false if opts['enforce_https'] == "false"
# check booleans
[:allow_hash_href, :allow_missing_href, :check_external_hash, :check_internal_hash, :check_sri, :disable_external, :enforce_https, :ignore_empty_alt, :ignore_empty_mailto, :ignore_missing_alt].each do |option|
next if (val = opts[option.to_s]).nil?
if val == "false"
options[option] = false
else
options[option] = true
end
end

options[:log_level] = opts['log_level'].to_sym unless opts['log_level'].nil?

Expand Down
14 changes: 10 additions & 4 deletions spec/html-proofer/command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@

it "works with check-external-hash" do
broken_hash_on_the_web = File.join(FIXTURES_DIR, "links", "broken_hash_on_the_web.html")
output = make_bin("--check-external-hash #{broken_hash_on_the_web}")
output = make_bin("--check-external-hash=true #{broken_hash_on_the_web}")
expect(output).to(match("1 failure"))
end

it "passes for broken hashes on the web when ignored" do
broken_hash_on_the_web = File.join(FIXTURES_DIR, "links", "broken_hash_on_the_web.html")
output = make_bin("#{broken_hash_on_the_web} --check-external-hash=false")
expect(output).to(match("successfully"))
end

it "works with directory-index-file" do
link_pointing_to_directory = File.join(FIXTURES_DIR, "links", "link_pointing_to_directory.html")
output = make_bin("--directory-index-file index.php #{link_pointing_to_directory}")
Expand All @@ -29,7 +35,7 @@

it "works with disable-external" do
external = File.join(FIXTURES_DIR, "links", "broken_link_external.html")
output = make_bin("--disable-external #{external}")
output = make_bin("--disable-external=true #{external}")
expect(output).to(match("successfully"))
end

Expand Down Expand Up @@ -78,13 +84,13 @@

it "works with empty-alt-ignore" do
broken = File.join(FIXTURES_DIR, "images", "empty_image_alt_text.html")
output = make_bin("--ignore-empty-alt #{broken}")
output = make_bin("--ignore-empty-alt=true #{broken}")
expect(output).to(match("successfully"))
end

it "works with allow-hash-href" do
broken = File.join(FIXTURES_DIR, "links", "hash_href.html")
output = make_bin("--allow-hash-href #{broken}")
output = make_bin("--allow-hash-href=true #{broken}")
expect(output).to(match("successfully"))
end

Expand Down