diff options
| author | Shulhan <ms@kilabit.info> | 2025-07-06 16:19:22 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2025-07-06 16:19:22 +0700 |
| commit | 76e44f0c738325ec7c1a64b2302a08320a8102b3 (patch) | |
| tree | 9df3b5851c20d062815329b1463bfffbe8a80fff | |
| parent | bae56a2010ece755e3fb664b2428d0aaf73b4a9b (diff) | |
| download | beku-76e44f0c738325ec7c1a64b2302a08320a8102b3.tar.xz | |
all: replace module github.com/shuLhan/share with pakakeh.go
| -rw-r--r-- | beku.go | 4 | ||||
| -rw-r--r-- | beku_test.go | 5 | ||||
| -rw-r--r-- | cmd/beku/command.go | 3 | ||||
| -rw-r--r-- | cmd/beku/command_test.go | 2 | ||||
| -rw-r--r-- | common_test.go | 2 | ||||
| -rw-r--r-- | env.go | 45 | ||||
| -rw-r--r-- | env_test.go | 15 | ||||
| -rw-r--r-- | go.mod | 11 | ||||
| -rw-r--r-- | go.sum | 16 | ||||
| -rw-r--r-- | package.go | 31 | ||||
| -rw-r--r-- | package_git.go | 5 | ||||
| -rw-r--r-- | package_git_test.go | 2 | ||||
| -rw-r--r-- | package_test.go | 22 | ||||
| -rw-r--r-- | testdata/src/github.com/username/package/dummy.go | 0 |
14 files changed, 87 insertions, 76 deletions
@@ -59,6 +59,10 @@ const ( gitDir = ".git" ) +// Debug flag to debug running command. +// Set from environment variable BEKU_DEBUG. +var Debug int64 = 0 + // List of error messages. var ( ErrGOROOT = errors.New("GOROOT is not defined") diff --git a/beku_test.go b/beku_test.go index 7b23cc3..f0e9445 100644 --- a/beku_test.go +++ b/beku_test.go @@ -12,8 +12,7 @@ import ( "path/filepath" "testing" - "github.com/shuLhan/share/lib/debug" - "github.com/shuLhan/share/lib/test/mock" + "git.sr.ht/~shulhan/pakakeh.go/lib/test/mock" ) const ( @@ -72,7 +71,7 @@ func TestMain(m *testing.M) { testGitRepoSrcLocal = "file://" + wd + testGitRepoSrcLocal testGitPkgInstall.RemoteURL = testGitRepoSrcLocal - if debug.Value >= 1 { + if Debug >= 1 { fmt.Printf("test env : %+v\n", *testEnv) fmt.Printf("testGitPkgCur: %+v\n", *testGitPkgCur) fmt.Printf("testGitPkgNew: %+v\n", *testGitPkgNew) diff --git a/cmd/beku/command.go b/cmd/beku/command.go index 1cf85f8..58937a4 100644 --- a/cmd/beku/command.go +++ b/cmd/beku/command.go @@ -10,7 +10,6 @@ import ( "os" "github.com/shuLhan/beku" - "github.com/shuLhan/share/lib/debug" ) var ( @@ -415,7 +414,7 @@ func newCommand() (cmd *command, err error) { } } - if debug.Value >= 2 { + if beku.Debug >= 2 { fmt.Printf("Environment: %s", cmd.env.String()) } diff --git a/cmd/beku/command_test.go b/cmd/beku/command_test.go index 92f922f..da1734e 100644 --- a/cmd/beku/command_test.go +++ b/cmd/beku/command_test.go @@ -9,7 +9,7 @@ import ( "os" "testing" - "github.com/shuLhan/share/lib/test" + "git.sr.ht/~shulhan/pakakeh.go/lib/test" ) func TestParseFlags(t *testing.T) { diff --git a/common_test.go b/common_test.go index 0ca0fea..d774f54 100644 --- a/common_test.go +++ b/common_test.go @@ -7,7 +7,7 @@ package beku import ( "testing" - "github.com/shuLhan/share/lib/test" + "git.sr.ht/~shulhan/pakakeh.go/lib/test" ) func TestGetCompareURL(t *testing.T) { @@ -13,11 +13,11 @@ 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" + "git.sr.ht/~shulhan/pakakeh.go/lib/ini" + libos "git.sr.ht/~shulhan/pakakeh.go/lib/os" ) // Env contains the environment of Go including GOROOT source directory, @@ -58,6 +58,11 @@ func NewEnvironment(noDeps bool) (env *Env, err error) { return nil, ErrGOROOT } + var envBekuDebug = os.Getenv(`BEKU_DEBUG`) + if envBekuDebug != `` { + Debug, _ = strconv.ParseInt(envBekuDebug, 10, 64) + } + env = &Env{ path: os.Getenv(envPATH), prefix: build.Default.GOPATH, @@ -190,7 +195,7 @@ func (env *Env) GetLocalPackage(importPath string) (pkg *Package, err error) { _, err = os.Stat(dirGit) if err != nil { - if libio.IsDirEmpty(fullPath) { + if libos.IsDirEmpty(fullPath) { err = nil } else { err = fmt.Errorf(errDirNotEmpty, fullPath) @@ -352,7 +357,7 @@ func (env *Env) scanStdPackages(srcPath string) error { // scanPackages will traverse each directory in `src` recursively until // it's found VCS metadata, e.g. `.git` directory. func (env *Env) scanPackages(srcPath string) (err error) { - if debug.Value >= 1 { + if Debug >= 1 { fmt.Println("[ENV] scanPackages >>>", srcPath) } @@ -420,7 +425,7 @@ func (env *Env) newPackage(fullPath string) (err error) { return } - if debug.Value >= 1 { + if Debug >= 1 { fmt.Println("[ENV] newPackage >>>", pkg.ImportPath) } @@ -488,7 +493,7 @@ func (env *Env) Load(file string) (err error) { env.dbFile = file } - if debug.Value >= 1 { + if Debug >= 1 { fmt.Println("[ENV] Load >>>", env.dbFile) } @@ -600,7 +605,7 @@ func (env *Env) Rescan(firstTime bool) (ok bool, err error) { fmt.Println() if !env.NoConfirm { - ok = libio.ConfirmYesNo(os.Stdin, msgContinue, false) + ok = libos.ConfirmYesNo(os.Stdin, msgContinue, false) if !ok { return } @@ -676,7 +681,7 @@ This package is required by, } if !env.NoConfirm { - ok := libio.ConfirmYesNo(os.Stdin, msgContinue, false) + ok := libos.ConfirmYesNo(os.Stdin, msgContinue, false) if !ok { return } @@ -691,7 +696,7 @@ This package is required by, pkgImportPath := filepath.Join(env.dirPkg, importPath) - if debug.Value >= 1 { + if Debug >= 1 { fmt.Println("[ENV] Remove >>> Removing", pkgImportPath) } @@ -701,7 +706,7 @@ This package is required by, return } - _ = libio.RmdirEmptyAll(pkgImportPath) + _ = libos.RmdirEmptyAll(pkgImportPath) } return nil @@ -809,7 +814,7 @@ func (env *Env) Save(file string) (err error) { } } - if debug.Value >= 1 { + if Debug >= 1 { fmt.Println("[ENV] Save >>>", file) } @@ -890,10 +895,10 @@ func (env *Env) String() string { // If destination directory is not empty, it will ask for user confirmation to // clean the directory first. func (env *Env) install(pkg *Package) (ok bool, err error) { - if !libio.IsDirEmpty(pkg.FullPath) { + if !libos.IsDirEmpty(pkg.FullPath) { fmt.Printf("[ENV] install >>> Directory %s is not empty.\n", pkg.FullPath) if !env.NoConfirm { - ok = libio.ConfirmYesNo(os.Stdin, msgCleanDir, false) + ok = libos.ConfirmYesNo(os.Stdin, msgCleanDir, false) if !ok { return } @@ -929,7 +934,7 @@ func (env *Env) update(curPkg, newPkg *Package) (ok bool, err error) { } } - if debug.Value >= 1 { + if Debug >= 1 { fmt.Println("[ENV] update >>>", newPkg) } @@ -943,7 +948,7 @@ func (env *Env) update(curPkg, newPkg *Package) (ok bool, err error) { curPkg.String(), newPkg.String()) if !env.NoConfirm { - ok = libio.ConfirmYesNo(os.Stdin, msgUpdateView, false) + ok = libos.ConfirmYesNo(os.Stdin, msgUpdateView, false) if ok { err = curPkg.CompareVersion(newPkg) if err != nil { @@ -953,7 +958,7 @@ func (env *Env) update(curPkg, newPkg *Package) (ok bool, err error) { } if !env.NoConfirm { - ok = libio.ConfirmYesNo(os.Stdin, msgUpdateProceed, true) + ok = libos.ConfirmYesNo(os.Stdin, msgUpdateProceed, true) if !ok { return } @@ -1002,7 +1007,7 @@ func (env *Env) installMissing(pkg *Package) (err error) { func (env *Env) updateMissing(newPkg *Package, addAsDep bool) { var updated bool - if debug.Value >= 1 { + if Debug >= 1 { fmt.Println("[ENV] updateMissing >>>", newPkg.ImportPath) } @@ -1119,7 +1124,7 @@ func (env *Env) SyncAll() (err error) { fmt.Println("[ENV] SyncAll >>> Updating all packages ...") for _, pkg := range env.pkgs { - if libio.IsDirEmpty(pkg.FullPath) { + if libos.IsDirEmpty(pkg.FullPath) { fmt.Printf("[ENV] SyncAll %s >>> Installing\n", pkg.ImportPath) @@ -1165,7 +1170,7 @@ func (env *Env) SyncAll() (err error) { fmt.Println(buf.String()) if !env.NoConfirm { - ok := libio.ConfirmYesNo(os.Stdin, msgContinue, false) + ok := libos.ConfirmYesNo(os.Stdin, msgContinue, false) if !ok { return } diff --git a/env_test.go b/env_test.go index 9c565f1..9f7cbb3 100644 --- a/env_test.go +++ b/env_test.go @@ -10,10 +10,9 @@ import ( "path/filepath" "testing" - "github.com/shuLhan/share/lib/debug" - "github.com/shuLhan/share/lib/test" - "github.com/shuLhan/share/lib/test/mock" - "github.com/shuLhan/share/lib/text/diff" + "git.sr.ht/~shulhan/pakakeh.go/lib/test" + "git.sr.ht/~shulhan/pakakeh.go/lib/test/mock" + "git.sr.ht/~shulhan/pakakeh.go/lib/text/diff" ) func TestEnvAddExclude(t *testing.T) { @@ -135,8 +134,8 @@ func TestEnvExclude(t *testing.T) { }, expPkgsLen: 48, expPkg: &Package{ - ImportPath: "github.com/shuLhan/share", - FullPath: filepath.Join(testEnv.dirSrc, "github.com/shuLhan/share"), + ImportPath: "git.sr.ht/~shulhan/pakakeh.go", + FullPath: filepath.Join(testEnv.dirSrc, "git.sr.ht/~shulhan/pakakeh.go"), RemoteName: "origin", RemoteURL: "git@github.com:shuLhan/share.git", RemoteBranch: "master", @@ -321,7 +320,7 @@ github.com/shuLhan/go-bindata eb5746d github.com/shuLhan/gontacts d4786e8 github.com/shuLhan/haminer 42be4cb github.com/shuLhan/numerus 104dd6b -github.com/shuLhan/share b2c8fd7 +git.sr.ht/~shulhan/pakakeh.go b2c8fd7 github.com/shuLhan/tabula 14d5c16 github.com/shuLhan/tekstus 651065d github.com/sirupsen/logrus 68cec9f @@ -449,7 +448,7 @@ func TestEnvSave(t *testing.T) { t.Fatal(err) } - if debug.Value >= 1 { + if Debug >= 1 { fmt.Printf("diffs: %s\n", diffs) } } @@ -1,12 +1,15 @@ module github.com/shuLhan/beku -go 1.18 +go 1.23.4 require ( - github.com/shuLhan/share v0.44.0 - golang.org/x/tools v0.1.12 + git.sr.ht/~shulhan/pakakeh.go v0.60.1 + golang.org/x/tools/go/vcs v0.1.0-deprecated ) -require golang.org/x/sys v0.5.0 // indirect +require ( + golang.org/x/exp v0.0.0-20250408133849-7e4ce0ab07d0 // indirect + golang.org/x/sys v0.32.0 // indirect +) //replace github.com/shuLhan/share => ../share @@ -1,6 +1,10 @@ -github.com/shuLhan/share v0.44.0 h1:Afom8pQrzNYtUZM53y+eqlZw5lkFm7bgl3QjZ3ARsgg= -github.com/shuLhan/share v0.44.0/go.mod h1:BnjohSsgDFMeYQ0/ws7kzb1oABZdVbEwDNGbUhOLee4= -golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +git.sr.ht/~shulhan/pakakeh.go v0.60.1 h1:JGke3BIh40tK+d9eHg0jYi/W+GVixWcGwFkAcynSBSY= +git.sr.ht/~shulhan/pakakeh.go v0.60.1/go.mod h1:8t/pEqWDrEcyr26qR5sXJkF1M5tFhrs3Jzr5aYoZdIo= +golang.org/x/exp v0.0.0-20250408133849-7e4ce0ab07d0 h1:R84qjqJb5nVJMxqWYb3np9L5ZsaDtB+a39EqjV0JSUM= +golang.org/x/exp v0.0.0-20250408133849-7e4ce0ab07d0/go.mod h1:S9Xr4PYopiDyqSyp5NjCrhFrqg6A5zA2E/iPHPhqnS8= +golang.org/x/net v0.39.0 h1:ZCu7HMWDxpXpaiKdhzIfaltL9Lp31x/3fCP11bc6/fY= +golang.org/x/net v0.39.0/go.mod h1:X7NRbYVEA+ewNkCNyJ513WmMdQ3BineSwVtN2zD/d+E= +golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20= +golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/tools/go/vcs v0.1.0-deprecated h1:cOIJqWBl99H1dH5LWizPa+0ImeeJq3t3cJjaeOWUAL4= +golang.org/x/tools/go/vcs v0.1.0-deprecated/go.mod h1:zUrvATBAvEI9535oC0yWYsLsHIV4Z7g63sNPVMtuBy8= @@ -16,10 +16,9 @@ import ( "golang.org/x/tools/go/vcs" - "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" + "git.sr.ht/~shulhan/pakakeh.go/lib/git" + "git.sr.ht/~shulhan/pakakeh.go/lib/ini" + libos "git.sr.ht/~shulhan/pakakeh.go/lib/os" ) const ( @@ -47,7 +46,7 @@ type Package struct { // NewPackage create a package set the package version, tag status, and // dependencies. func NewPackage(gopathSrc, name, importPath string) (pkg *Package, err error) { - repoRoot, err := vcs.RepoRootForImportPath(name, debug.Value >= 1) + repoRoot, err := vcs.RepoRootForImportPath(name, Debug > 0) if err != nil { fmt.Fprintf(defStderr, "[PKG] NewPackage >>> error: %s\n", err.Error()) return @@ -67,7 +66,7 @@ func NewPackage(gopathSrc, name, importPath string) (pkg *Package, err error) { state: packageStateNew, } - if debug.Value >= 2 { + if Debug >= 2 { fmt.Printf("[PKG] NewPackage >>> %+v\n", pkg) } @@ -208,7 +207,7 @@ func (pkg *Package) Remove() (err error) { return fmt.Errorf(`%s: %w`, logp, err) } - if debug.Value >= 1 { + if Debug >= 1 { fmt.Printf("%s: %s >>> %s\n", logp, pkg.ImportPath, pkg.FullPath) } @@ -217,7 +216,7 @@ func (pkg *Package) Remove() (err error) { return fmt.Errorf(`%s: %w`, logp, err) } - _ = libio.RmdirEmptyAll(pkg.FullPath) + _ = libos.RmdirEmptyAll(pkg.FullPath) return } @@ -260,7 +259,7 @@ func (pkg *Package) Scan() (err error) { // ScanDeps will scan package dependencies, removing standard packages, keep // only external dependencies. func (pkg *Package) ScanDeps(env *Env) (err error) { - if debug.Value >= 1 { + if Debug >= 1 { fmt.Println("[PKG] ScanDeps", pkg.ImportPath) } @@ -285,7 +284,7 @@ func (pkg *Package) GetRecursiveImports(env *Env) ( cmd.Dir = pkg.FullPath cmd.Stderr = defStderr - if debug.Value >= 1 { + if Debug >= 1 { fmt.Printf("= GetRecursiveImports %s %s\n", cmd.Dir, cmd.Args) } @@ -341,7 +340,7 @@ func (pkg *Package) addDep(env *Env, importPath string) bool { // (1) if strings.HasPrefix(importPath, pkg.ImportPath) { - if debug.Value >= 2 { + if Debug >= 2 { fmt.Printf("[PKG] addDep %s >>> skip self import: %s\n", pkg.ImportPath, importPath) } @@ -364,7 +363,7 @@ func (pkg *Package) addDep(env *Env, importPath string) bool { if pkgs[0] != env.pkgsStd[x] { continue } - if debug.Value >= 2 { + if Debug >= 2 { fmt.Printf("[PKG] addDep %s >>> skip std: %s\n", pkg.ImportPath, importPath) } @@ -383,7 +382,7 @@ func (pkg *Package) addDep(env *Env, importPath string) bool { return true } - if debug.Value >= 2 { + if Debug >= 2 { fmt.Printf("[PKG] addDep %s >>> missing: %s\n", pkg.ImportPath, importPath) } @@ -427,7 +426,7 @@ func (pkg *Package) load(sec *ini.Section) { // non-interactive shell (e.g. buildbot). func (pkg *Package) GoInstall(envPath string) (err error) { cmd := exec.Command("go", "install") - if debug.Value >= 2 { + if Debug >= 2 { cmd.Args = append(cmd.Args, "-v") } cmd.Args = append(cmd.Args, "./...") @@ -444,7 +443,7 @@ func (pkg *Package) GoInstall(envPath string) (err error) { cmd.Stdout = defStdout cmd.Stderr = defStderr - if debug.Value == 0 { + if Debug == 0 { fmt.Printf("= GoInstall %s\n", cmd.Dir) } else { fmt.Printf("= GoInstall %s\n%s\n%s\n", cmd.Dir, cmd.Env, cmd.Args) @@ -558,7 +557,7 @@ func (pkg *Package) pushDep(importPath string) { pkg.Deps = append(pkg.Deps, importPath) - if debug.Value >= 2 { + if Debug >= 2 { fmt.Printf("[PKG] pushDep %s >>> %s\n", pkg.ImportPath, importPath) } diff --git a/package_git.go b/package_git.go index 200c04f..ec69fe2 100644 --- a/package_git.go +++ b/package_git.go @@ -8,8 +8,7 @@ import ( "fmt" "strings" - "github.com/shuLhan/share/lib/debug" - "github.com/shuLhan/share/lib/git" + "git.sr.ht/~shulhan/pakakeh.go/lib/git" ) // gitFreeze set the package remote name and URL, branch, and revision. @@ -130,7 +129,7 @@ func (pkg *Package) gitGetBranch() (err error) { } else if len(branches) > 0 { pkg.RemoteBranch = branches[len(branches)-1] } - if debug.Value >= 1 { + if Debug >= 1 { fmt.Printf("= gitGetBranch: %s\n", pkg.RemoteBranch) } return nil diff --git a/package_git_test.go b/package_git_test.go index 01224d2..f4850ad 100644 --- a/package_git_test.go +++ b/package_git_test.go @@ -7,7 +7,7 @@ package beku import ( "testing" - "github.com/shuLhan/share/lib/test" + "git.sr.ht/~shulhan/pakakeh.go/lib/test" ) func TestGitScan(t *testing.T) { diff --git a/package_test.go b/package_test.go index 85253ca..50396f8 100644 --- a/package_test.go +++ b/package_test.go @@ -11,9 +11,9 @@ import ( "strings" "testing" - "github.com/shuLhan/share/lib/ini" - "github.com/shuLhan/share/lib/test" - "github.com/shuLhan/share/lib/test/mock" + "git.sr.ht/~shulhan/pakakeh.go/lib/ini" + "git.sr.ht/~shulhan/pakakeh.go/lib/test" + "git.sr.ht/~shulhan/pakakeh.go/lib/test/mock" ) func TestPackageRemove(t *testing.T) { @@ -200,31 +200,31 @@ func TestAddDep(t *testing.T) { envPkgs: []*Package{{ ImportPath: "github.com/shuLhan/beku", }, { - ImportPath: "github.com/shuLhan/share", + ImportPath: "git.sr.ht/~shulhan/pakakeh.go", }}, - importPath: "github.com/shuLhan/share/lib/test", + importPath: "git.sr.ht/~shulhan/pakakeh.go/lib/test", exp: true, expDeps: []string{ - "github.com/shuLhan/share", + "git.sr.ht/~shulhan/pakakeh.go", }, }, { desc: "Is exist on environment (again)", envPkgs: []*Package{{ ImportPath: "github.com/shuLhan/beku", }, { - ImportPath: "github.com/shuLhan/share", + ImportPath: "git.sr.ht/~shulhan/pakakeh.go", }}, - importPath: "github.com/shuLhan/share/lib/test", + importPath: "git.sr.ht/~shulhan/pakakeh.go/lib/test", exp: true, expDeps: []string{ - "github.com/shuLhan/share", + "git.sr.ht/~shulhan/pakakeh.go", }, }, { desc: "Is not exist on environment (missing)", importPath: "github.com/shuLhan/tekstus", exp: true, expDeps: []string{ - "github.com/shuLhan/share", + "git.sr.ht/~shulhan/pakakeh.go", }, expDepsMissing: []string{ "github.com/shuLhan/tekstus", @@ -237,7 +237,7 @@ func TestAddDep(t *testing.T) { importPath: "github.com/shuLhan/tekstus", exp: true, expDeps: []string{ - "github.com/shuLhan/share", + "git.sr.ht/~shulhan/pakakeh.go", }, expDepsMissing: []string{ "github.com/shuLhan/tekstus", diff --git a/testdata/src/github.com/username/package/dummy.go b/testdata/src/github.com/username/package/dummy.go deleted file mode 100644 index e69de29..0000000 --- a/testdata/src/github.com/username/package/dummy.go +++ /dev/null |
