Skip to content
This repository was archived by the owner on Aug 25, 2025. It is now read-only.
This repository was archived by the owner on Aug 25, 2025. It is now read-only.

wire: add "subtract" command #8

Open

Description

@zombiezen

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.

Activity

  1. changed the title [-]goose: add "subtract" command[/-] [+]wire: add "subtract" command[/+] on May 31, 2018
  2. transferred this issue fromgoogle/go-cloudon Nov 28, 2018
  3. added this to the Unplanned milestone on Nov 28, 2018
  4. vangent commented on Mar 22, 2019

    @vangent
    Contributor

    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),
      )
    
  5. michaellee8 commented on Jul 12, 2022

    @michaellee8

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

  6. giautm commented on Jul 14, 2022

    @giautm
    Contributor

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

  7. zombiezen commented on Jul 17, 2022

    @zombiezen
    ContributorAuthor

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

  8. vangent commented on Jul 18, 2022

    @vangent
    Contributor

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

  9. jayzhuang commented on Jul 31, 2022

    @jayzhuang

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions