One of the things I find myself doing a lot is dropping into the terminal, firing up iex and then using the help system (e.g. h Enum.count) to get information about a routine. Then I kill the shell and go on about my day.
Is there already an elixir command line tool that prints the help for a module or function directly from the shell prompt? (starts iex implicitly, runs help, then returns to the shell)
I am thinking of something kinda like ‘ri’ in the Ruby universe.
I suppose you could make an escript that calls the Code.get_docs function. IEx.helpers.h is a set of fancy functions that ultimately end up calling Code.get_docs(modulename, :docs) and/or Code.get_docs(Enum, :moduledoc). You can see the relevant code from IEx here: https://github.com/elixir-lang/elixir/blob/master/lib/iex/lib/iex/introspection.ex and you can experiement with Code.get_docs from inside iex to see how that is the real powerhouse here
I know this is not directly an answer, but I use Dash on macOS for quickly looking up documentation. It works really really well with Elixir’s documentation.
Obviously, writing the above line every time you want to look up the Elixir documentation for a module or function is very tedious, so instead you could create an executable shell script – say exdoc – then add it to your PATH.
Example Script
Note: Don’t forget to chmod u+x on it.
#!/bin/bash
if [[ -z "$1" ]]; then
echo "USAGE: $(basename $0) [name]"
exit 1
fi
elixir -e "require IEx.Helpers; IEx.Helpers.h($1)"