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

provide command line info on plugins #29

Open
rogpeppe opened this issue Aug 23, 2017 · 15 comments
Open

provide command line info on plugins #29

rogpeppe opened this issue Aug 23, 2017 · 15 comments

Comments

@rogpeppe
Copy link

It would be nice to be able to list the available plugins from the command line
and find out information on individual plugins, including the expected
function signature.

@awalterschulze
Copy link
Owner

Sounds easy enough to emit a list, but the function signature depends on the input parameters. How would the user provide these on the command line?

@rogpeppe
Copy link
Author

I'd just document it like:

The copy plugin generates a function of the form:

      func deriveCopy(dst, src T)

  for some type T, which copies the contents of src into dst.
  T must be a pointer or a map. Its contents are copied according to
  the following rules: .... etc

@awalterschulze
Copy link
Owner

May I ask why, since there are already godocs and examples available on github.
Is this for some type of integration?

@rogpeppe
Copy link
Author

I'd prefer not to go to github every time I wonder what plugins are available or when I'm wondering what a particular plugin does (in the same way that I often use "go doc" rather than going online to the Go documentation). Also, I'm not always online.

The help for a given plugin could just copy some of the package doc comment from github.com/awalterschulze/goderive/plugin/$pluginname and print that, I guess, to
avoid too much textual duplication.

@awalterschulze
Copy link
Owner

awalterschulze commented Aug 23, 2017

Interesting.

Ok so then how would that be different than running:

go doc ./plugin/fmap

Or

go doc github.com/awalterschulze/goderive/plugin/fmap

@rogpeppe
Copy link
Author

Not that much, apart from the fact that:

  • a user of goderive shouldn't need to know the canonical import path of goderive. Someone may have forked goderive and added more plugins, for example, or tweaked existing plugins.
  • the package declaration, the first paragraph of the package doc comment, and the information on the New function, are all irrelevant to the goderive user.
  • the user might not even have the goderive package installed, as they might have installed the command directly as a binary.

Note that the user will almost never be in the goderive root directory, so your first suggestion probably won't work most of the time.

@awalterschulze
Copy link
Owner

Good points.

Ok so for example fmap I would get a godoc like this

$ go doc github.com/awalterschulze/goderive/plugin/fmap
package fmap // import "github.com/awalterschulze/goderive/plugin/fmap"

Package fmap contains the implementation of the fmap plugin, which generates
the deriveFmap function.

The deriveFmap function applies a given function to each element of a list,
returning a list of results in the same order.

    deriveFmap(func(A) B, []A) []B
    deriveFmap(func(rune) B, string) []B

deriveFmap can also be applied to a function that returns a value and an
error.

    deriveFmap(func(A) B, func() (A, error)) (B, error)
    deriveFmap(func(A) (B, error), func() (A, error)) (func() (B, error), error)
    deriveFmap(func(A), func() (A, error)) error
    deriveFmap(func(A) (B, c, d, ...), func() (A, error)) (func() (B, c, d, ...), error)

deriveFmap will propogate the error and not apply the first function to the
result of the second function, if the second function returns an error.

func New(typesMap derive.TypesMap, p derive.Printer, deps map[string]derive.Dependency) derive.Generator
func NewPlugin() derive.Plugin

@awalterschulze
Copy link
Owner

But we would prefer

$ goderive doc fmap

The deriveFmap function applies a given function to each element of a list,
returning a list of results in the same order.

    deriveFmap(func(A) B, []A) []B
    deriveFmap(func(rune) B, string) []B

deriveFmap can also be applied to a function that returns a value and an
error.

    deriveFmap(func(A) B, func() (A, error)) (B, error)
    deriveFmap(func(A) (B, error), func() (A, error)) (func() (B, error), error)
    deriveFmap(func(A), func() (A, error)) error
    deriveFmap(func(A) (B, c, d, ...), func() (A, error)) (func() (B, c, d, ...), error)

deriveFmap will propogate the error and not apply the first function to the
result of the second function, if the second function returns an error.

@awalterschulze
Copy link
Owner

If so then we could generate this doc from the godoc as you suggested and avoid more duplication of documentation.
What do you think?

@rogpeppe
Copy link
Author

Yes, this looks nice.
I think I'd suggest naming the subcommand "help" rather than "doc".
Then we could have:

 goderive help (or --help):
     show information on command line flags and the available subcommands
 goderive help fmap
     show information on a particular command.
 goderive list
     show a brief description of each plugin (one line for each so it's greppable)

This has a potential ambiguity issue if the stdlib ever adds "help" or "list" packages, but I think we can be safe that even if they do, noone will actually want to run goderive on them :-)

@awalterschulze
Copy link
Owner

I think list should also take into account the pluginprefixes and print out a list of plugin name : prefix : first line of goderive help

fmap : deriveFmap : The deriveFmap function applies a given function to each element of a list, returning a list of results in the same order.

What do you think?

@rogpeppe
Copy link
Author

Perhaps. That seems a little verbose though. I suspect it might be nicer if each plugin provided a single line summary:

 fmap: map a function onto a list

It might be nice to be able to get list to show the function signatures too, similarly to how the godoc page for a package shows the function signatures at the top.

@awalterschulze
Copy link
Owner

Is this acceptable?

goderive --list
    show a brief description of each plugin (one line for each so it's greppable
goderive --doc=fmap
    show information on a particular command.

where doc is the print out we discussed before.
and --list becomes

$ goderive --list
...
equal: deriveEqual: checks for the equality of two values
fmap : deriveFmap : map a function onto a list.
...

So that we can also have:

$ goderive --list --pluginprefix="fmap=m"
...
equal: deriveEqual: checks for the equality of two values
fmap : m : map a function onto a list.
...

@saltbo
Copy link

saltbo commented Oct 19, 2022

Any update for goderive --list?

@awalterschulze
Copy link
Owner

No, but from the discussion I think the output format is decided.
Now we just need someone to implement it in such a way that the list is extendible with new plugins.

Looking for volunteers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants