diff --git a/cmd/dep/ensure.go b/cmd/dep/ensure.go index 6ed07aca0f..22d48898e1 100644 --- a/cmd/dep/ensure.go +++ b/cmd/dep/ensure.go @@ -16,6 +16,7 @@ import ( "strings" "github.com/golang/dep" + "github.com/golang/dep/internal" "github.com/pkg/errors" "github.com/sdboyer/gps" "github.com/sdboyer/gps/pkgtree" @@ -205,7 +206,7 @@ func applyEnsureArgs(args []string, overrides stringSlice, p *dep.Project, sm *g // TODO(sdboyer): for this case - or just in general - do we want to // add project args to the requires list temporarily for this run? if _, has := p.Manifest.Dependencies[pc.Ident.ProjectRoot]; !has { - logf("No constraint or alternate source specified for %q, omitting from manifest", pc.Ident.ProjectRoot) + internal.Logf("No constraint or alternate source specified for %q, omitting from manifest", pc.Ident.ProjectRoot) } // If it's already in the manifest, no need to log continue diff --git a/cmd/dep/init.go b/cmd/dep/init.go index 7609aca265..87b5af5383 100644 --- a/cmd/dep/init.go +++ b/cmd/dep/init.go @@ -13,6 +13,7 @@ import ( "strings" "github.com/golang/dep" + "github.com/golang/dep/internal" "github.com/pkg/errors" "github.com/sdboyer/gps" "github.com/sdboyer/gps/pkgtree" @@ -89,12 +90,12 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error { if err != nil { return errors.Wrap(err, "determineProjectRoot") } - vlogf("Finding dependencies for %q...", cpr) + internal.Vlogf("Finding dependencies for %q...", cpr) pkgT, err := pkgtree.ListPackages(root, cpr) if err != nil { return errors.Wrap(err, "gps.ListPackages") } - vlogf("Found %d dependencies.", len(pkgT.Packages)) + internal.Vlogf("Found %d dependencies.", len(pkgT.Packages)) sm, err := ctx.SourceManager() if err != nil { return errors.Wrap(err, "getSourceManager") @@ -135,7 +136,7 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error { } if len(pd.notondisk) > 0 { - vlogf("Solving...") + internal.Vlogf("Solving...") params := gps.SolveParameters{ RootDir: root, RootPackageTree: pkgT, @@ -161,7 +162,7 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error { l = dep.LockFromInterface(soln) } - vlogf("Writing manifest and lock files.") + internal.Vlogf("Writing manifest and lock files.") var sw dep.SafeWriter sw.Prepare(m, nil, l, dep.VendorAlways) @@ -236,7 +237,7 @@ func getProjectData(ctx *dep.Ctx, pkgT pkgtree.PackageTree, cpr string, sm *gps. return projectData{}, nil } - vlogf("Building dependency graph...") + internal.Vlogf("Building dependency graph...") // Exclude stdlib imports from the list returned from Flatten(). const omitStdlib = false for _, ip := range rm.Flatten(omitStdlib) { @@ -252,13 +253,13 @@ func getProjectData(ctx *dep.Ctx, pkgT pkgtree.PackageTree, cpr string, sm *gps. } go syncDep(pr, sm) - vlogf("Found import of %q, analyzing...", ip) + internal.Vlogf("Found import of %q, analyzing...", ip) dependencies[pr] = []string{ip} v, err := ctx.VersionInWorkspace(pr) if err != nil { notondisk[pr] = true - vlogf("Could not determine version for %q, omitting from generated manifest", pr) + internal.Vlogf("Could not determine version for %q, omitting from generated manifest", pr) continue } @@ -275,7 +276,7 @@ func getProjectData(ctx *dep.Ctx, pkgT pkgtree.PackageTree, cpr string, sm *gps. constraints[pr] = pp } - vlogf("Analyzing transitive imports...") + internal.Vlogf("Analyzing transitive imports...") // Explore the packages we've found for transitive deps, either // completing the lock or identifying (more) missing projects that we'll // need to ask gps to solve for us. @@ -294,7 +295,7 @@ func getProjectData(ctx *dep.Ctx, pkgT pkgtree.PackageTree, cpr string, sm *gps. dft = func(pkg string) error { switch colors[pkg] { case white: - vlogf("Analyzing %q...", pkg) + internal.Vlogf("Analyzing %q...", pkg) colors[pkg] = grey pr, err := sm.DeduceProjectRoot(pkg) diff --git a/cmd/dep/main.go b/cmd/dep/main.go index 92c6d21a25..3ae0f38703 100644 --- a/cmd/dep/main.go +++ b/cmd/dep/main.go @@ -14,6 +14,7 @@ import ( "text/tabwriter" "github.com/golang/dep" + "github.com/golang/dep/internal" ) var ( @@ -114,6 +115,8 @@ func main() { os.Exit(1) } + internal.Verbose = *verbose + // Set up the dep context. ctx, err := dep.NewContext() if err != nil { @@ -167,7 +170,7 @@ func resetUsage(fs *flag.FlagSet, name, args, longHelp string) { } } -// parseArgs determines the name of the dep command and wether the user asked for +// parseArgs determines the name of the dep command and whether the user asked for // help to be printed. func parseArgs(args []string) (cmdName string, printCmdUsage bool, exit bool) { isHelpArg := func() bool { @@ -192,15 +195,3 @@ func parseArgs(args []string) (cmdName string, printCmdUsage bool, exit bool) { } return cmdName, printCmdUsage, exit } - -func logf(format string, args ...interface{}) { - // TODO: something else? - fmt.Fprintf(os.Stderr, "dep: "+format+"\n", args...) -} - -func vlogf(format string, args ...interface{}) { - if !*verbose { - return - } - logf(format, args...) -} diff --git a/cmd/dep/remove.go b/cmd/dep/remove.go index ae7caec56c..b3bd5db8f9 100644 --- a/cmd/dep/remove.go +++ b/cmd/dep/remove.go @@ -11,6 +11,7 @@ import ( "strings" "github.com/golang/dep" + "github.com/golang/dep/internal" "github.com/pkg/errors" "github.com/sdboyer/gps" "github.com/sdboyer/gps/pkgtree" @@ -91,7 +92,7 @@ func (cmd *removeCommand) Run(ctx *dep.Ctx, args []string) error { // not being able to detect the root for an import path that's // actually in the import list is a deeper problem. However, // it's not our direct concern here, so we just warn. - logf("could not infer root for %q", pr) + internal.Logf("could not infer root for %q", pr) continue } otherroots[pr] = true @@ -106,7 +107,7 @@ func (cmd *removeCommand) Run(ctx *dep.Ctx, args []string) error { } if len(rm) == 0 { - logf("nothing to do") + internal.Logf("nothing to do") return nil } } else { diff --git a/internal/internal.go b/internal/internal.go new file mode 100644 index 0000000000..12e35f729f --- /dev/null +++ b/internal/internal.go @@ -0,0 +1,25 @@ +// Copyright 2016 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package internal + +import ( + "fmt" + "os" +) + +// Verbose specifies if verbose logging is enabled. +var Verbose bool + +func Logf(format string, args ...interface{}) { + // TODO: something else? + fmt.Fprintf(os.Stderr, "dep: "+format+"\n", args...) +} + +func Vlogf(format string, args ...interface{}) { + if !Verbose { + return + } + Logf(format, args...) +}