From 1650edee19d0801b09642ec3dc7598528f4ba6ab Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Thu, 28 Apr 2016 11:29:58 -0700 Subject: [PATCH] Use goutils/die instead of kisom/die. Also removes the "logging" package from showimp, as this is intended primarily for server programs. --- cmd/certverify/main.go | 2 +- cmd/csrpubdump/pubdump.go | 2 +- cmd/fragment/fragment.go | 2 +- cmd/showimp/main.go | 37 ++++++++++++++++++++++--------------- cmd/tlskeypair/main.go | 2 +- 5 files changed, 26 insertions(+), 19 deletions(-) diff --git a/cmd/certverify/main.go b/cmd/certverify/main.go index 5bb66bd..9582c6c 100644 --- a/cmd/certverify/main.go +++ b/cmd/certverify/main.go @@ -10,7 +10,7 @@ import ( "github.com/cloudflare/cfssl/helpers" "github.com/cloudflare/cfssl/revoke" - "github.com/kisom/die" + "github.com/kisom/goutils/die" "github.com/kisom/goutils/lib" ) diff --git a/cmd/csrpubdump/pubdump.go b/cmd/csrpubdump/pubdump.go index 24c4475..53612f6 100644 --- a/cmd/csrpubdump/pubdump.go +++ b/cmd/csrpubdump/pubdump.go @@ -10,7 +10,7 @@ import ( "io/ioutil" "log" - "github.com/kisom/die" + "github.com/kisom/goutils/die" ) func main() { diff --git a/cmd/fragment/fragment.go b/cmd/fragment/fragment.go index 44452f3..c73d0d3 100644 --- a/cmd/fragment/fragment.go +++ b/cmd/fragment/fragment.go @@ -8,7 +8,7 @@ import ( "path/filepath" "strconv" - "github.com/kisom/die" + "github.com/kisom/goutils/die" ) func usage() { diff --git a/cmd/showimp/main.go b/cmd/showimp/main.go index d47c770..a8d291e 100644 --- a/cmd/showimp/main.go +++ b/cmd/showimp/main.go @@ -19,14 +19,29 @@ import ( var ( gopath string project string + debug bool ) var ( stdLibRegexp = regexp.MustCompile(`^\w+(/\w+)*$`) sourceRegexp = regexp.MustCompile(`^[^.].*\.go$`) - log = logging.Init() + log = logging.NewConsole() + imports = map[string]bool{} + fset = &token.FileSet{} ) +func debugf(format string, args ...interface{}) { + if debug { + fmt.Printf(format, args...) + } +} + +func debugln(args ...interface{}) { + if debug { + fmt.Println(args...) + } +} + func init() { gopath = os.Getenv("GOPATH") if gopath == "" { @@ -51,17 +66,12 @@ func init() { project = wd[len(gopath):] } -var ( - imports = map[string]bool{} - fset = &token.FileSet{} -) - func walkFile(path string, info os.FileInfo, err error) error { if !sourceRegexp.MatchString(path) { return nil } - log.Debug(path) + debugln(path) f, err := parser.ParseFile(fset, path, nil, parser.ImportsOnly) if err != nil { @@ -71,16 +81,16 @@ func walkFile(path string, info os.FileInfo, err error) error { for _, importSpec := range f.Imports { importPath := strings.Trim(importSpec.Path.Value, `"`) if stdLibRegexp.MatchString(importPath) { - log.Debug("standard lib:", importPath) + debugln("standard lib:", importPath) continue } else if strings.HasPrefix(importPath, project) { - log.Debug("internal import:", importPath) + debugln("internal import:", importPath) continue } else if strings.HasPrefix(importPath, "golang.org/") { - log.Debug("extended lib:", importPath) + debugln("extended lib:", importPath) continue } - log.Debug("import:", importPath) + debugln("import:", importPath) imports[importPath] = true } @@ -88,12 +98,9 @@ func walkFile(path string, info os.FileInfo, err error) error { } func main() { - verbose := flag.Bool("v", false, "log debugging information") + flag.BoolVar(&debug, "v", false, "log debugging information") flag.Parse() - if *verbose { - log.SetLevel(logging.LevelDebug) - } err := filepath.Walk(".", walkFile) die.If(err) diff --git a/cmd/tlskeypair/main.go b/cmd/tlskeypair/main.go index c4dc9b9..6e545dd 100644 --- a/cmd/tlskeypair/main.go +++ b/cmd/tlskeypair/main.go @@ -15,7 +15,7 @@ import ( "log" "os" - "github.com/kisom/die" + "github.com/kisom/goutils/die" ) var validPEMs = map[string]bool{