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

curl: --help [option] displays documentation for given cmdline option #13997

Closed
wants to merge 1 commit into from

Conversation

bagder
Copy link
Member

@bagder bagder commented Jun 24, 2024

The extracting of the help texts is still a little crude: because we typically have 270KB of text zlib compressed into a single blob, we have to scan for the text to show.

The searching can be made to use Boyer-Moore or similar to speed things up but leaving that for later.

Tasks

  • basic functionality
  • build integration, both compressed and uncompressed
  • verify a --disable-manual build
  • documentation
  • test cases
  • show help for documented negative options like --no-alpn
  • accept --no- prefix for boolean options
  • reject --no- prefix for non-boolean options
  • show --keepalive - do not match --keepalive-cnt (works because of the alpha sorting)
  • make sure it does not erroneously find a ^ -- combo before the first option in the manpage

Example command lines.

Short cmdline option

$ curl -h -k
    -k, --insecure
        (TLS SFTP SCP) By default,  every secure connection curl makes  is
        verified to  be  secure  before the  transfer  takes  place.  This
        option makes curl skip the  verification step and proceed  without
        checking.

        When this  option  is  not  used for  protocols  using  TLS,  curl
        verifies the server's  TLS certificate before  it continues:  that
        the  certificate  contains  the  right  name  which  matches   the
        hostname used in the URL and that the certificate has  been signed
        by a CA  certificate present in  the cert  store. See this  online
        resource for further details: https://curl.se/docs/sslcerts.html

        For SFTP  and SCP,  this option  makes curl  skip the  known_hosts
        verification. known_hosts is a file normally stored in the  user's
        home  directory  in  the   ".ssh"  subdirectory,  which   contains
        hostnames and their public keys.

        WARNING: using this option makes the transfer insecure.

        When curl uses  secure protocols  it trusts  responses and  allows
        for example HSTS  and Alt-Svc  information to be  stored and  used
        subsequently. Using --insecure  can make curl  trust and use  such
        information from malicious servers.

        Providing --insecure multiple times  has no extra effect.  Disable
        it again with --no-insecure.

        Example:
         curl --insecure https://example.com

        See also --proxy-insecure, --cacert and --capath.

Long cmdline option

$ curl -h --hsts
    --hsts <filename>
        (HTTPS) Enable HSTS for  the transfer. If  the filename points  to
        an existing  HSTS cache  file,  that is  used. After  a  completed
        transfer, the cache is saved to the filename again if it  has been
        modified.

        If curl  is  told  to  use  HTTP:// for  a  transfer  involving  a
        hostname that exists in the  HSTS cache, it upgrades the  transfer
        to use HTTPS. Each  HSTS cache entry  has an individual life  time
        after which the upgrade is no longer performed.

        Specify a ""  filename (zero length)  to avoid loading/saving  and
        make curl just handle HSTS in memory.

        If this option  is used  several times, curl  loads contents  from
        all the files but the last one is used for saving.

        --hsts can be used several times in a command line

        Example:
         curl --hsts cache.txt https://example.com

        See also --proto. Added in 7.74.0.

Non-existing cmdline option

$ curl -h --foo
Incorrect option name to show help for, see curl -h

@bagder bagder added cmdline tool feature-window A merge of this requires an open feature window documentation labels Jun 24, 2024
@github-actions github-actions bot added the tests label Jun 24, 2024
@bagder bagder marked this pull request as ready for review June 24, 2024 14:42
@bagder
Copy link
Member Author

bagder commented Jun 25, 2024

I did a quick comparison with brotli and zstd to see how big the gains would be if we would compress the data differently - since most/many builds already use those compression libs.

It turns out the differences are not revolutionary. When using -9 compression for each on the text version of the manpage as of right now:

size file
274917 curl.txt
72019 curl.txt.gz
66328 curl.txt.zstd
63572 curl.txt.br

@bagder bagder force-pushed the bagder/help-option branch 4 times, most recently from 0ea2d5c to 42acd1a Compare June 29, 2024 21:37
@bagder bagder self-assigned this Jun 30, 2024
src/tool_help.c Outdated Show resolved Hide resolved
@bagder
Copy link
Member Author

bagder commented Jul 5, 2024

Left for future improvement: the displayed manpage section ends with a newline too many.

@yedayak
Copy link
Contributor

yedayak commented Jul 5, 2024

It seems it's impossible to show the help for options that are negated in the documentation, since they aren't kept that way in the aliases list. If for example you search for --alpn, than it doesn't find it since it doesn't exist in huge_help, and --no-alpn doesn't match one of the aliases so it fails before searching in the help.

Another side affect of this is that when you look for --keepalive, which appears negated in the man page, it finds --keepalive-cnt, which start matches --keepalive. This specifically can be prevented by adding a space at the end of the search string:

msnprintf(cmdbuf, sizeof(cmdbuf), "\n    %s ", category);

@bagder
Copy link
Member Author

bagder commented Jul 5, 2024

It seems it's impossible to show the help for options that are negated in the documentation, since they aren't kept that way in the aliases list. If for example you search for --alpn, than it doesn't find it since it doesn't exist in huge_help, and --no-alpn doesn't match one of the aliases so it fails before searching in the help.

Oh, so it needs some extra magic. I'll add this as a TODO to fix.

Another side affect of this is that when you look for --keepalive, which appears negated in the man page, it finds --keepalive-cnt, which start matches --keepalive. This specifically can be prevented by adding a space at the end of the search string:

Actually, that trick only works if there actually is a space afterwards in the manpage, which for example --create-dirs does not. So it needs a better fix.

bagder added a commit that referenced this pull request Jul 5, 2024
bagder added a commit that referenced this pull request Jul 5, 2024
bagder added a commit that referenced this pull request Jul 5, 2024
Since the documentation text blob might be gzipped, it needs to search
for what to output in a streaming manner. It then first searches for
"\nALL OPTIONS".

Then, it looks for the start to display at "\n    -[option]" and stops
again at "\n    -". Except for the last option in the man page, which
ends at "\nFILES" - the subtitle for the section following all options
in the manpage.

Test 1707 to 1710 verify

Closes #13997
bagder added a commit that referenced this pull request Jul 5, 2024
Since the documentation text blob might be gzipped, it needs to search
for what to output in a streaming manner. It then first searches for
"\nALL OPTIONS".

Then, it looks for the start to display at "\n    -[option]" and stops
again at "\n    -". Except for the last option in the man page, which
ends at "\nFILES" - the subtitle for the section following all options
in the manpage.

Test 1707 to 1710 verify

Closes #13997
@dfandrich
Copy link
Contributor

Analysis of PR #13997:
Test 1705 failed,
which has NOT been flaky recently, so there could be a real issue in the PR.

Generated by Testclutch

Since the documentation text blob might be gzipped, it needs to search
for what to output in a streaming manner. It then first searches for
"\nALL OPTIONS".

Then, it looks for the start to display at "\n    -[option]" and stops
again at "\n    -". Except for the last option in the man page, which
ends at "\nFILES" - the subtitle for the section following all options
in the manpage.

Test 1707 to 1710 verify

Closes #13997
@bagder bagder closed this in 9a0cf56 Aug 4, 2024
@bagder bagder deleted the bagder/help-option branch August 25, 2024 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cmdline tool documentation feature-window A merge of this requires an open feature window tests
Development

Successfully merging this pull request may close these issues.

3 participants