cod icon indicating copy to clipboard operation
cod copied to clipboard

cod should be able to learn man-pages

Open zachriggle opened this issue 5 years ago • 8 comments

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.

zachriggle avatar Feb 18 '20 01:02 zachriggle

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.

dim-an avatar Feb 18 '20 09:02 dim-an

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?

drmikecrowe avatar Jan 27 '21 23:01 drmikecrowe

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.

dim-an avatar Feb 01 '21 10:02 dim-an

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

drmikecrowe avatar Feb 01 '21 10:02 drmikecrowe

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?

drmikecrowe avatar Feb 01 '21 11:02 drmikecrowe

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!

dim-an avatar Feb 01 '21 11:02 dim-an

I'll keep digging into bash-completions and see if I can find the lazy loading ones...

drmikecrowe avatar Feb 01 '21 11:02 drmikecrowe

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).

dim-an avatar Feb 01 '21 11:02 dim-an