cod
cod copied to clipboard
cod should be able to learn man-pages
While the output of --help
is usually instructive, it is less-well-formatted than most man
pages.
It might be useful to have a mode where cod
can learn from man pages, instead of or in-addition-to the --help
output.
Yes, it would be nice feature to have.
Acually fish shell has update_completions script.
It does similar job and we can use it as inspiration.
I just installed cod
and I'm really impressed. If the man pages were imported during install, how much of a benefit would that be?
How would this man-page learning work? Once we decode the man page, how do we inject it into cod
?
Hey! Thanks for your feedback.
How would this man-page learning work? Once we decode the man page, how do we inject it into cod?
Maybe I don't understand question, but learning man pages don't differs much from learning --help
output. We should parse man page (we can be inspired by parser from fish shell) and store discovered flags in our database of known flags.
Since man pages are kept in well known places we can also parse them in background without user request. But before doing so we should resolve somehow #9
I assume many of the commands that have man pages are already have good completion provided by shell and we should not override it with our completion/ Unfortunately I don't know the good way to know if command has completion or not.
Bash has the ability to list all completions:
complete -p
According to this zsh is:
for command completion in ${(kv)_comps:#-*(-|-,*)}
do
printf "%-32s %s\n" $command $completion
done | sort
I guess my question was asking: If I took the task to help with this, seems like the steps are:
- [ ] Run the steps above to determine what man pages to scan
- [ ] In the background, decode the man page to slurp out the parameters
- [ ] Feed results into
cod
I can see how to do the first/second steps, but was asking for some guidance on the last step. How do you do this?
Bash has the ability to list all completions:
Unfortunately it's not that easy. There is popular package bash-completeion. It provides completions for great variety of programs but loads them on the fly. E.g. complete -p
doesn't show these completions until you use them.
See example: https://asciinema.org/a/Tbj8R8yDwjI4riNASZUhB2iXK
Since this package is really good and popular I believe that cod
has to support it.
According to this zsh is:
I briefly looked at it and it looks like it might be working solution, thanks!
I'll keep digging into bash-completions and see if I can find the lazy loading ones...
I'll think a little bit about the plan for this issue and come back with answer.
For now you can play a little bit with parsers. I think that cod
should be able to parse man pages itself without external tools.
Here is the interface parsers must implement. You can see here examples of --help
parsers: one, two.
Function ParseHelp actually chooses what parser to use and runs it (right now parser selection is really stupid).