Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Commit 9e4c058

Browse files
authored
Merge pull request #459 from carolynvs/internal-logging
Move logging functions into internal package
2 parents e025682 + 5361a50 commit 9e4c058

File tree

5 files changed

+44
-25
lines changed

5 files changed

+44
-25
lines changed

cmd/dep/ensure.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"strings"
1717

1818
"github.com/golang/dep"
19+
"github.com/golang/dep/internal"
1920
"github.com/pkg/errors"
2021
"github.com/sdboyer/gps"
2122
"github.com/sdboyer/gps/pkgtree"
@@ -205,7 +206,7 @@ func applyEnsureArgs(args []string, overrides stringSlice, p *dep.Project, sm *g
205206
// TODO(sdboyer): for this case - or just in general - do we want to
206207
// add project args to the requires list temporarily for this run?
207208
if _, has := p.Manifest.Dependencies[pc.Ident.ProjectRoot]; !has {
208-
logf("No constraint or alternate source specified for %q, omitting from manifest", pc.Ident.ProjectRoot)
209+
internal.Logf("No constraint or alternate source specified for %q, omitting from manifest", pc.Ident.ProjectRoot)
209210
}
210211
// If it's already in the manifest, no need to log
211212
continue

cmd/dep/init.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"strings"
1414

1515
"github.com/golang/dep"
16+
"github.com/golang/dep/internal"
1617
"github.com/pkg/errors"
1718
"github.com/sdboyer/gps"
1819
"github.com/sdboyer/gps/pkgtree"
@@ -89,12 +90,12 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {
8990
if err != nil {
9091
return errors.Wrap(err, "determineProjectRoot")
9192
}
92-
vlogf("Finding dependencies for %q...", cpr)
93+
internal.Vlogf("Finding dependencies for %q...", cpr)
9394
pkgT, err := pkgtree.ListPackages(root, cpr)
9495
if err != nil {
9596
return errors.Wrap(err, "gps.ListPackages")
9697
}
97-
vlogf("Found %d dependencies.", len(pkgT.Packages))
98+
internal.Vlogf("Found %d dependencies.", len(pkgT.Packages))
9899
sm, err := ctx.SourceManager()
99100
if err != nil {
100101
return errors.Wrap(err, "getSourceManager")
@@ -135,7 +136,7 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {
135136
}
136137

137138
if len(pd.notondisk) > 0 {
138-
vlogf("Solving...")
139+
internal.Vlogf("Solving...")
139140
params := gps.SolveParameters{
140141
RootDir: root,
141142
RootPackageTree: pkgT,
@@ -161,7 +162,7 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {
161162
l = dep.LockFromInterface(soln)
162163
}
163164

164-
vlogf("Writing manifest and lock files.")
165+
internal.Vlogf("Writing manifest and lock files.")
165166

166167
var sw dep.SafeWriter
167168
sw.Prepare(m, nil, l, dep.VendorAlways)
@@ -236,7 +237,7 @@ func getProjectData(ctx *dep.Ctx, pkgT pkgtree.PackageTree, cpr string, sm *gps.
236237
return projectData{}, nil
237238
}
238239

239-
vlogf("Building dependency graph...")
240+
internal.Vlogf("Building dependency graph...")
240241
// Exclude stdlib imports from the list returned from Flatten().
241242
const omitStdlib = false
242243
for _, ip := range rm.Flatten(omitStdlib) {
@@ -252,13 +253,13 @@ func getProjectData(ctx *dep.Ctx, pkgT pkgtree.PackageTree, cpr string, sm *gps.
252253
}
253254
go syncDep(pr, sm)
254255

255-
vlogf("Found import of %q, analyzing...", ip)
256+
internal.Vlogf("Found import of %q, analyzing...", ip)
256257

257258
dependencies[pr] = []string{ip}
258259
v, err := ctx.VersionInWorkspace(pr)
259260
if err != nil {
260261
notondisk[pr] = true
261-
vlogf("Could not determine version for %q, omitting from generated manifest", pr)
262+
internal.Vlogf("Could not determine version for %q, omitting from generated manifest", pr)
262263
continue
263264
}
264265

@@ -275,7 +276,7 @@ func getProjectData(ctx *dep.Ctx, pkgT pkgtree.PackageTree, cpr string, sm *gps.
275276
constraints[pr] = pp
276277
}
277278

278-
vlogf("Analyzing transitive imports...")
279+
internal.Vlogf("Analyzing transitive imports...")
279280
// Explore the packages we've found for transitive deps, either
280281
// completing the lock or identifying (more) missing projects that we'll
281282
// need to ask gps to solve for us.
@@ -294,7 +295,7 @@ func getProjectData(ctx *dep.Ctx, pkgT pkgtree.PackageTree, cpr string, sm *gps.
294295
dft = func(pkg string) error {
295296
switch colors[pkg] {
296297
case white:
297-
vlogf("Analyzing %q...", pkg)
298+
internal.Vlogf("Analyzing %q...", pkg)
298299
colors[pkg] = grey
299300

300301
pr, err := sm.DeduceProjectRoot(pkg)

cmd/dep/main.go

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"text/tabwriter"
1515

1616
"github.com/golang/dep"
17+
"github.com/golang/dep/internal"
1718
)
1819

1920
var (
@@ -114,6 +115,8 @@ func main() {
114115
os.Exit(1)
115116
}
116117

118+
internal.Verbose = *verbose
119+
117120
// Set up the dep context.
118121
ctx, err := dep.NewContext()
119122
if err != nil {
@@ -167,7 +170,7 @@ func resetUsage(fs *flag.FlagSet, name, args, longHelp string) {
167170
}
168171
}
169172

170-
// parseArgs determines the name of the dep command and wether the user asked for
173+
// parseArgs determines the name of the dep command and whether the user asked for
171174
// help to be printed.
172175
func parseArgs(args []string) (cmdName string, printCmdUsage bool, exit bool) {
173176
isHelpArg := func() bool {
@@ -192,15 +195,3 @@ func parseArgs(args []string) (cmdName string, printCmdUsage bool, exit bool) {
192195
}
193196
return cmdName, printCmdUsage, exit
194197
}
195-
196-
func logf(format string, args ...interface{}) {
197-
// TODO: something else?
198-
fmt.Fprintf(os.Stderr, "dep: "+format+"\n", args...)
199-
}
200-
201-
func vlogf(format string, args ...interface{}) {
202-
if !*verbose {
203-
return
204-
}
205-
logf(format, args...)
206-
}

cmd/dep/remove.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"strings"
1212

1313
"github.com/golang/dep"
14+
"github.com/golang/dep/internal"
1415
"github.com/pkg/errors"
1516
"github.com/sdboyer/gps"
1617
"github.com/sdboyer/gps/pkgtree"
@@ -91,7 +92,7 @@ func (cmd *removeCommand) Run(ctx *dep.Ctx, args []string) error {
9192
// not being able to detect the root for an import path that's
9293
// actually in the import list is a deeper problem. However,
9394
// it's not our direct concern here, so we just warn.
94-
logf("could not infer root for %q", pr)
95+
internal.Logf("could not infer root for %q", pr)
9596
continue
9697
}
9798
otherroots[pr] = true
@@ -106,7 +107,7 @@ func (cmd *removeCommand) Run(ctx *dep.Ctx, args []string) error {
106107
}
107108

108109
if len(rm) == 0 {
109-
logf("nothing to do")
110+
internal.Logf("nothing to do")
110111
return nil
111112
}
112113
} else {

internal/internal.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2016 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package internal
6+
7+
import (
8+
"fmt"
9+
"os"
10+
)
11+
12+
// Verbose specifies if verbose logging is enabled.
13+
var Verbose bool
14+
15+
func Logf(format string, args ...interface{}) {
16+
// TODO: something else?
17+
fmt.Fprintf(os.Stderr, "dep: "+format+"\n", args...)
18+
}
19+
20+
func Vlogf(format string, args ...interface{}) {
21+
if !Verbose {
22+
return
23+
}
24+
Logf(format, args...)
25+
}

0 commit comments

Comments
 (0)