Command to check if Erlang docs are installed, non-interactively?

How can I check if erlang docs are installed, non-interactively? This is what I have so far, which crashes. :sweat_smile:

erl -eval 'h(lists).' -noshell
1 Like
  1. erl -man lists
$ erl -man lists
No manual entry for lists
$ echo $?
16

in OTP 27rc3, this always errors because it tries to look up the docs for -- as well, so a test can look for some expected output:

$ PAGER=cat erl -man fake 2>/dev/null | grep -q NAME && echo "have docs"
$ PAGER=cat erl -man lists 2>/dev/null | grep -q NAME && echo "have docs"
have docs
  1. shell_docs:get_doc/1. This throws an exception on modules that don’t exist, but not on modules without documentation, so you should check the return:
# on install without docs
$ erl -eval 'erlang:display(shell_docs:get_doc(lists)), halt().' -noshell
[{p,[],[<<"There is no documentation for ">>,<<"lists">>]}]

# on install with docs
$ erl -eval 'erlang:display(shell_docs:get_doc(lists)), halt().' -noshell                                                                      
[{pre,[],[<<76,105,115,116,32,112,...omitted
  1. look for docs on the filesystem:
$ erl -eval 'erlang:display(file:open(filename:join([code:root_dir(),"man","man3","lists.3"]), [read])), halt().' -noshell
{ok,<0.82.0>}

# or without docs
$ erl -eval 'erlang:display(file:open(filename:join([code:root_dir(),"man","man3","lists.3"]), [read])), halt().' -noshell
{error,enoent}
2 Likes

I went with #2 and threw a grep behind it matching the specific doc, like this:

erl -eval 'erlang:display(shell_docs:get_doc(lists)), halt().' -noshell | grep "List processing functions."

Thanks so much for the thoroughness of your reply, as well as giving me several options to choose from! Hopefully this will benefit someone else too!

There are two different types of docs that you are mixing together :slight_smile:

  1. The man pages, that can be accessed using man 3 lists or erl -man lists
  2. The shell docs, that can be accessed through h(Module).

To check if the man pages are available, you can use something similar to @jrfondren’s first suggestion and check the error code. As man pages are removed from Erlang/OTP 27, that command will always fail there.

The shell docs should be checked by calling code:get_doc(lists). shell_docs:get_doc/1 is an internal API and should not be used.