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

wire: add "subtract" command #8

Open
zombiezen opened this issue May 31, 2018 · 6 comments · May be fixed by #382
Open

wire: add "subtract" command #8

zombiezen opened this issue May 31, 2018 · 6 comments · May be fixed by #382
Labels
enhancement New feature or request
Milestone

Comments

@zombiezen
Copy link
Collaborator

If someone wants to "override" a set of providers from a larger set, it would be helpful to have the gowire tool output the minimal code to create a new provider set that "carves out" the given provider from the set. Ideal workflow:

$ gowire subtract github.com/google/go-cloud/gcp/gcpcloud.GCP github.com/google/go-cloud/gcp.ProjectID
import (
  "github.com/google/go-cloud/gcp"
  "github.com/google/go-cloud/gcp/gcpcloud"
  "github.com/google/go-cloud/wire"
)

var Set = wire.NewSet(
  gcpcloud.Services,
  gcp.CredentialsTokenSource,
  gcp.DefaultCredentials,
)

Perhaps this would include an interactive mode that shows you everything in the provider set and lets you pick which types to remove by menu, since typing type names is arduous.

@zombiezen zombiezen changed the title goose: add "subtract" command wire: add "subtract" command May 31, 2018
@zombiezen zombiezen transferred this issue from google/go-cloud Nov 28, 2018
@zombiezen zombiezen added this to the Unplanned milestone Nov 28, 2018
@zombiezen zombiezen added the enhancement New feature or request label Nov 28, 2018
@vangent
Copy link
Contributor

vangent commented Mar 22, 2019

Another idea is to have wire.Subtract be a wire directive, used to wrap a ProviderSet in a wire.NewSet or a wire.Build.

Use cases might be:

  1. I want to make a Set AB that unions 2 other sets A and B, but there's a type T that's the same between A and B.
var SetAB = wire.NewSet(A, B)
  • Today, you'd get an error that there's two providers for T and you'd be kind of hosed.
  • With wire.Subtract, you could do:
var SetAB = wire.NewSet(A, wire.Subtract(B, T))
  1. I want to use an existing ProviderSet, but want to override one of the types it provides. For example, azureblob defines a Set that has NewPipeline and Options{} in it. Today, this code would produce an error because Options is provided twice, once by the injector function parameter and once by azureblob.Set.
func azureBucket(bucketName string, opts *azureblob.Options) *blob.Bucket {
  wire.Build(
    azureblob.DefaultIdentity,
    azureblob.Set,
  )

Again, you'd be kind of hosed; you'd have to explicitly add all of the providers in azureblob.Set that you need. With wire.Subtract, you would do:

func azureBucket(bucketName string, opts *azureblob.Options) *blob.Bucket {
  wire.Build(
    azureblob.DefaultIdentity,
    wire.Subtract(azureblob.Set, azureblob.Options),
  )

@michaellee8
Copy link

michaellee8 commented Jul 12, 2022

@zombiezen Any chance this will be worked on? Will a PR be accepted if I implement this? This one seems useful for mocking purpose for me.

@giautm
Copy link
Contributor

giautm commented Jul 14, 2022

I have same issue here, Just want to change the timeout value in the default server's driver. :(

@zombiezen
Copy link
Collaborator Author

This seems reasonable to me, but I haven't been working on Wire for a while. @vangent, WDYT?

@vangent
Copy link
Contributor

vangent commented Jul 18, 2022

@eliben can you add the new owners for this repo?

@jayzhuang
Copy link
Collaborator

wire.Subtract sounds good, I'm happy to help review and merge a PR (new owner here :D)

@giautm giautm linked a pull request Apr 21, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants