aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2018-09-14 04:12:49 +0700
committerShulhan <ms@kilabit.info>2018-09-14 04:12:49 +0700
commit4690dcc618467ccb9a1d474d710c863ec6cffdc1 (patch)
treeb88fbf0c08c2246f5479b95c5c4fe075c6baad2f
parent063617ef0271519fded1e60146f708a9e919a4ab (diff)
downloadbeku-4690dcc618467ccb9a1d474d710c863ec6cffdc1.tar.xz
Replace local debug variable with debug package
-rw-r--r--beku.go9
-rw-r--r--cmd/beku/command.go3
-rw-r--r--debugmode.go13
-rw-r--r--env.go19
-rw-r--r--go.mod2
-rw-r--r--go.sum6
-rw-r--r--package.go23
7 files changed, 27 insertions, 48 deletions
diff --git a/beku.go b/beku.go
index 628ae37..8890249 100644
--- a/beku.go
+++ b/beku.go
@@ -25,8 +25,7 @@ const (
dirTestdata = "testdata"
dirVendor = "vendor"
- envDEBUG = "BEKU_DEBUG"
- envPATH = "PATH"
+ envPATH = "PATH"
msgCleanDir = "Clean destination directory?"
msgContinue = "Continue?"
@@ -62,12 +61,6 @@ var (
)
var (
- // Debug level for this package. Set from environment variable
- // BEKU_DEBUG.
- Debug debugMode
-)
-
-var (
defStdout = os.Stdout
defStderr = os.Stderr
diff --git a/cmd/beku/command.go b/cmd/beku/command.go
index e9a21c9..71f5dea 100644
--- a/cmd/beku/command.go
+++ b/cmd/beku/command.go
@@ -10,6 +10,7 @@ import (
"os"
"github.com/shuLhan/beku"
+ "github.com/shuLhan/share/lib/debug"
)
const (
@@ -441,7 +442,7 @@ func newCommand() (cmd *command, err error) {
}
}
- if beku.Debug >= beku.DebugL2 {
+ if debug.Value >= 2 {
fmt.Printf("Environment: %s", cmd.env.String())
}
diff --git a/debugmode.go b/debugmode.go
deleted file mode 100644
index e4d0c44..0000000
--- a/debugmode.go
+++ /dev/null
@@ -1,13 +0,0 @@
-// Copyright 2018, Shulhan <ms@kilabit.info>. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package beku
-
-type debugMode uint
-
-// List of debug levels.
-const (
- DebugL1 debugMode = 1 << iota
- DebugL2
-)
diff --git a/env.go b/env.go
index 67d1d18..af234dc 100644
--- a/env.go
+++ b/env.go
@@ -15,9 +15,9 @@ import (
"io/ioutil"
"os"
"path/filepath"
- "strconv"
"strings"
+ "github.com/shuLhan/share/lib/debug"
"github.com/shuLhan/share/lib/ini"
libio "github.com/shuLhan/share/lib/io"
)
@@ -64,9 +64,6 @@ func NewEnvironment(vendor, noDeps bool) (env *Env, err error) {
return nil, ErrGOROOT
}
- debug, _ := strconv.Atoi(os.Getenv(envDEBUG))
- Debug = debugMode(debug)
-
env = &Env{
path: os.Getenv(envPATH),
dirGoRootSrc: filepath.Join(build.Default.GOROOT, dirSrc),
@@ -436,7 +433,7 @@ func (env *Env) scanStdPackages(srcPath string) error {
// (2) skip directory without `.git`
//
func (env *Env) scanPackages(srcPath string) (err error) {
- if Debug >= DebugL2 {
+ if debug.Value >= 2 {
fmt.Println("[ENV] scanPackages >>>", srcPath)
}
@@ -507,7 +504,7 @@ func (env *Env) newPackage(fullPath string) (err error) {
return
}
- if Debug >= DebugL2 {
+ if debug.Value >= 2 {
fmt.Println("[ENV] newPackage >>>", pkg.ImportPath)
}
@@ -575,7 +572,7 @@ func (env *Env) Load(file string) (err error) {
env.dbFile = file
}
- if Debug >= DebugL1 {
+ if debug.Value >= 1 {
fmt.Println("[ENV] Load >>>", env.dbFile)
}
@@ -802,7 +799,7 @@ This package is required by,
pkgImportPath := filepath.Join(env.dirPkg, importPath)
- if Debug >= DebugL1 {
+ if debug.Value >= 1 {
fmt.Println("[ENV] Remove >>> Removing", pkgImportPath)
}
@@ -928,7 +925,7 @@ func (env *Env) Save(file string) (err error) {
}
}
- if Debug >= DebugL1 {
+ if debug.Value >= 1 {
fmt.Println("[ENV] Save >>>", file)
}
@@ -1056,7 +1053,7 @@ func (env *Env) update(curPkg, newPkg *Package) (ok bool, err error) {
newPkg.isTag = curPkg.isTag
}
- if Debug >= DebugL1 {
+ if debug.Value >= 1 {
fmt.Println("[ENV] update >>>", newPkg)
}
@@ -1137,7 +1134,7 @@ func (env *Env) installMissing(pkg *Package) (err error) {
func (env *Env) updateMissing(newPkg *Package, addAsDep bool) {
var updated bool
- if Debug >= DebugL1 {
+ if debug.Value >= 1 {
fmt.Println("[ENV] updateMissing >>>", newPkg.ImportPath)
}
diff --git a/go.mod b/go.mod
index a42a982..0d52526 100644
--- a/go.mod
+++ b/go.mod
@@ -2,7 +2,7 @@ module github.com/shuLhan/beku
require (
github.com/shuLhan/numerus v0.1.0 // indirect
- github.com/shuLhan/share v0.0.0-20180912202720-29654838d11a
+ github.com/shuLhan/share v0.0.0-20180913210900-92fd877512f9
github.com/shuLhan/tekstus v0.1.0
golang.org/x/tools v0.0.0-20180911133044-677d2ff680c1
)
diff --git a/go.sum b/go.sum
index 19801c4..d566773 100644
--- a/go.sum
+++ b/go.sum
@@ -1,9 +1,9 @@
github.com/shuLhan/numerus v0.1.0 h1:oCywZLE3iTb/9T8qhFCkANg59Qy4cJ3nES5+S8WO6/U=
github.com/shuLhan/numerus v0.1.0/go.mod h1:zF6WAVSsJebxdZxwyHWhqibDiCXnfitT4oHfcHve7+Y=
-github.com/shuLhan/share v0.0.0-20180912202720-29654838d11a h1:TA6JhhXYj2Pb1D8XW4kZc9lpbAdRKYg3UjeIMfEyy4Y=
-github.com/shuLhan/share v0.0.0-20180912202720-29654838d11a/go.mod h1:iFVEXaCAWMpiS3yOJySqq5kCyTCuIxO849OcEATHi7E=
+github.com/shuLhan/share v0.0.0-20180913210900-92fd877512f9 h1:IRzwXGjrgNU3F8ODr5WRVVJwOEtXneVJzaqm18vIw8Q=
+github.com/shuLhan/share v0.0.0-20180913210900-92fd877512f9/go.mod h1:L4OhM+hxrUdsb+Im+o06N/wz4hzfu29/R9lqueL4HJI=
github.com/shuLhan/tekstus v0.1.0 h1:O08rXaR8yEZhVTKtgpLfZhEvkRe4svhMhm532tPn4Is=
github.com/shuLhan/tekstus v0.1.0/go.mod h1:Pn7xUNXikqBQ1Fqtx2XFZEL1u8nZZPYxfP/8M4+LxaE=
-golang.org/x/sys v0.0.0-20180906133057-8cf3aee42992/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/tools v0.0.0-20180911133044-677d2ff680c1 h1:dzEuQYa6+a3gROnSlgly5ERUm4SZKJt+dh+4iSbO+bI=
golang.org/x/tools v0.0.0-20180911133044-677d2ff680c1/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
diff --git a/package.go b/package.go
index a32edc8..ee24d93 100644
--- a/package.go
+++ b/package.go
@@ -14,6 +14,7 @@ import (
"sort"
"strings"
+ "github.com/shuLhan/share/lib/debug"
"github.com/shuLhan/share/lib/git"
"github.com/shuLhan/share/lib/ini"
libio "github.com/shuLhan/share/lib/io"
@@ -51,14 +52,14 @@ type Package struct {
func NewPackage(env *Env, pkgName, importPath string) (
pkg *Package, err error,
) {
- repoRoot, err := vcs.RepoRootForImportPath(importPath, Debug >= DebugL2)
+ repoRoot, err := vcs.RepoRootForImportPath(importPath, debug.Value >= 2)
if err != nil {
fmt.Fprintf(defStderr, "[PKG] NewPackage >>> error: %s\n", err.Error())
fmt.Fprintf(defStderr, "[PKG] NewPackage >>> skip %s\n", pkgName)
return
}
- if Debug >= DebugL2 {
+ if debug.Value >= 2 {
fmt.Printf("[PKG] NewPackage >>> %+v\n", *repoRoot)
}
@@ -143,7 +144,7 @@ func (pkg *Package) GoClean() (err error) {
cmd.Stdout = defStdout
cmd.Stderr = defStderr
- if Debug >= DebugL1 {
+ if debug.Value >= 1 {
fmt.Printf("[PKG] GoClean %s >>> %s %s\n", pkg.ImportPath, cmd.Dir, cmd.Args)
}
@@ -208,7 +209,7 @@ func (pkg *Package) Remove() (err error) {
return
}
- if Debug >= DebugL1 {
+ if debug.Value >= 1 {
fmt.Printf("[PKG] Remove %s >>> %s\n", pkg.ImportPath,
pkg.FullPath)
}
@@ -298,7 +299,7 @@ func (pkg *Package) Scan() (err error) {
// only external dependencies.
//
func (pkg *Package) ScanDeps(env *Env) (err error) {
- if Debug >= DebugL1 {
+ if debug.Value >= 1 {
fmt.Println("[PKG] ScanDeps", pkg.ImportPath)
}
@@ -330,7 +331,7 @@ func (pkg *Package) GetRecursiveImports(env *Env) (
cmd.Dir = pkg.ScanPath
}
- if Debug >= DebugL1 {
+ if debug.Value >= 1 {
fmt.Printf("[PKG] GetRecursiveImports %s >>> %s %s\n",
pkg.ImportPath, cmd.Dir, cmd.Args)
}
@@ -393,7 +394,7 @@ func (pkg *Package) addDep(env *Env, importPath string) bool {
// (1)
if strings.HasPrefix(importPath, pkg.ImportPath) {
- if Debug >= DebugL2 {
+ if debug.Value >= 2 {
fmt.Printf("[PKG] addDep %s >>> skip self import: %s\n",
pkg.ImportPath, importPath)
}
@@ -416,7 +417,7 @@ func (pkg *Package) addDep(env *Env, importPath string) bool {
if pkgs[0] != env.pkgsStd[x] {
continue
}
- if Debug >= DebugL2 {
+ if debug.Value >= 2 {
fmt.Printf("[PKG] addDep %s >>> skip std: %s\n",
pkg.ImportPath, importPath)
}
@@ -435,7 +436,7 @@ func (pkg *Package) addDep(env *Env, importPath string) bool {
return true
}
- if Debug >= DebugL2 {
+ if debug.Value >= 2 {
fmt.Printf("[PKG] addDep %s >>> missing: %s\n",
pkg.ImportPath, importPath)
}
@@ -486,7 +487,7 @@ func (pkg *Package) load(sec *ini.Section) {
func (pkg *Package) GoInstall(env *Env) (err error) {
//nolint:gas
cmd := exec.Command("go", "install")
- if Debug >= DebugL2 {
+ if debug.Value >= 2 {
cmd.Args = append(cmd.Args, "-v")
}
cmd.Args = append(cmd.Args, "./...")
@@ -610,7 +611,7 @@ func (pkg *Package) pushDep(importPath string) bool {
pkg.Deps = append(pkg.Deps, importPath)
- if Debug >= DebugL2 {
+ if debug.Value >= 2 {
fmt.Printf("[PKG] pushDep %s >>> %s\n", pkg.ImportPath,
importPath)
}