Skip to content

Vendored Cobra is used in weave-blueprint #143

@felzix

Description

@felzix

This might not count as an issue but it seems like a bad practice for a project designed to teach others how to use Loom.

I built a contract and now want to test it with a cli so I copied weave-blueprint's cli and edited to fit my contract. However, cli.ContractCallCommand() returns a cobra.Command from the vendored version of the "cobra" package. Since it's vendored, it can't be imported by anything outside of "go-loom", including by my package... I can't import "cobra" because that version and the vendored version are treated as completely different.

The only workaround I see is to copy-paste go-loom/cli/cli.go into my package and import that. This seems bad to me. I should be able to use library packages anywhere.

I don't think there should be any imports at all unless they're easy to use. Not for a tutorial. But if there are then they should be designed to be imported by newbie developers. This can be done (I think) by exporting a value that's just &cobra.Command or making a method that returns it. The "weave-blueprint" package should then use that exported value instead of importing "cobra" itself.

BTW I'm very not-confident here because my IDE sees the same problem with "weave-blueprint" as with my package. I assume building "weave-blueprint" would give me the same error as with my own package. Here's the error when I try to build my package's cli:

./cli.go:54:20: cannot use callCmd (type *"github.com/loomnetwork/go-loom/vendor/github.com/spf13/cobra".Command) as type *"github.com/spf13/cobra".Command in argument to rootCmd.AddCommand

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions