wire: rename from Goose (google/go-cloud#59)

Rename Goose to wire, making it more obvious what the package does, and look more like the stdlib.

Fixes google/go-cloud#8
This commit is contained in:
Ross Light
2018-05-31 15:34:15 -07:00
parent 3e60790b34
commit 6345348d86
131 changed files with 285 additions and 293 deletions

View File

@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// goose is a compile-time dependency injection tool.
// gowire is a compile-time dependency injection tool.
//
// See README.md for an overview.
package main
@@ -30,7 +30,7 @@ import (
"strconv"
"strings"
"github.com/google/go-cloud/goose/internal/goose"
"github.com/google/go-cloud/wire/internal/wire"
"golang.org/x/tools/go/types/typeutil"
)
@@ -48,17 +48,17 @@ func main() {
case len(os.Args) == 3 && os.Args[1] == "gen":
err = generate(os.Args[2])
default:
fmt.Fprintln(os.Stderr, "goose: usage: goose [gen] [PKG] | goose show [...]")
fmt.Fprintln(os.Stderr, "gowire: usage: gowire [gen] [PKG] | gowire show [...]")
os.Exit(64)
}
if err != nil {
fmt.Fprintln(os.Stderr, "goose:", err)
fmt.Fprintln(os.Stderr, "gowire:", err)
os.Exit(1)
}
}
// generate runs the gen subcommand. Given a package, gen will create
// the goose_gen.go file.
// the wire_gen.go file.
func generate(pkg string) error {
wd, err := os.Getwd()
if err != nil {
@@ -68,16 +68,16 @@ func generate(pkg string) error {
if err != nil {
return err
}
out, err := goose.Generate(&build.Default, wd, pkg)
out, err := wire.Generate(&build.Default, wd, pkg)
if err != nil {
return err
}
if len(out) == 0 {
// No Goose directives, don't write anything.
fmt.Fprintln(os.Stderr, "goose: no injector found for", pkg)
// No Wire directives, don't write anything.
fmt.Fprintln(os.Stderr, "gowire: no injector found for", pkg)
return nil
}
p := filepath.Join(pkgInfo.Dir, "goose_gen.go")
p := filepath.Join(pkgInfo.Dir, "wire_gen.go")
if err := ioutil.WriteFile(p, out, 0666); err != nil {
return err
}
@@ -94,11 +94,11 @@ func show(pkgs ...string) error {
if err != nil {
return err
}
info, err := goose.Load(&build.Default, wd, pkgs)
info, err := wire.Load(&build.Default, wd, pkgs)
if err != nil {
return err
}
keys := make([]goose.ProviderSetID, 0, len(info.Sets))
keys := make([]wire.ProviderSetID, 0, len(info.Sets))
for k := range info.Sets {
keys = append(keys, k)
}
@@ -130,11 +130,11 @@ func show(pkgs ...string) error {
out := make(map[string]token.Pos, outGroups[i].outputs.Len())
outGroups[i].outputs.Iterate(func(t types.Type, v interface{}) {
switch v := v.(type) {
case *goose.Provider:
case *wire.Provider:
out[types.TypeString(t, nil)] = v.Pos
case *goose.Value:
case *wire.Value:
out[types.TypeString(t, nil)] = v.Pos
case *goose.IfaceBinding:
case *wire.IfaceBinding:
out[types.TypeString(t, nil)] = v.Pos
default:
panic("unreachable")
@@ -152,19 +152,19 @@ func show(pkgs ...string) error {
type outGroup struct {
name string
inputs *typeutil.Map // values are not important
outputs *typeutil.Map // values are *goose.Provider, *goose.Value, or *goose.IfaceBinding
outputs *typeutil.Map // values are *wire.Provider, *wire.Value, or *wire.IfaceBinding
}
// gather flattens a provider set into outputs grouped by the inputs
// required to create them. As it flattens the provider set, it records
// the visited named provider sets as imports.
func gather(info *goose.Info, key goose.ProviderSetID) (_ []outGroup, imports map[string]struct{}) {
func gather(info *wire.Info, key wire.ProviderSetID) (_ []outGroup, imports map[string]struct{}) {
hash := typeutil.MakeHasher()
// Map types to providers and bindings.
pm := new(typeutil.Map)
pm.SetHasher(hash)
next := []*goose.ProviderSet{info.Sets[key]}
visited := make(map[*goose.ProviderSet]struct{})
next := []*wire.ProviderSet{info.Sets[key]}
visited := make(map[*wire.ProviderSet]struct{})
imports = make(map[string]struct{})
for len(next) > 0 {
curr := next[len(next)-1]
@@ -214,7 +214,7 @@ func gather(info *goose.Info, key goose.ProviderSetID) (_ []outGroup, imports ma
case nil:
// This is an input.
inputVisited.Set(curr, -1)
case *goose.Provider:
case *wire.Provider:
// Try to see if any args haven't been visited.
allPresent := true
for _, arg := range p.Args {
@@ -258,7 +258,7 @@ func gather(info *goose.Info, key goose.ProviderSetID) (_ []outGroup, imports ma
inputs: in,
outputs: out,
})
case *goose.Value:
case *wire.Value:
for i := range groups {
if groups[i].inputs.Len() == 0 {
groups[i].outputs.Set(p.Out, p)
@@ -276,7 +276,7 @@ func gather(info *goose.Info, key goose.ProviderSetID) (_ []outGroup, imports ma
inputs: in,
outputs: out,
})
case *goose.IfaceBinding:
case *wire.IfaceBinding:
i, ok := inputVisited.At(p.Provided).(int)
if !ok {
stk = append(stk, curr, p.Provided)