aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2023-03-03 00:19:39 +0700
committerShulhan <ms@kilabit.info>2023-03-03 00:19:39 +0700
commit4b4e44bed548115f2c46f4521e8fe2971eb12fc5 (patch)
tree8ccb45f975472da84a440f88b461f49bd0c5cad8
parentb49ef8b92d182759a5b9312428bea3d5095ddeaf (diff)
downloadbeku-4b4e44bed548115f2c46f4521e8fe2971eb12fc5.tar.xz
all: reformat all .go files with Go 1.19 gofmt
-rw-r--r--cmd/beku/command.go2
-rw-r--r--cmd/beku/main.go2
-rw-r--r--common.go8
-rw-r--r--env.go60
-rw-r--r--go/vcs/vcs.go1
-rw-r--r--package.go46
-rw-r--r--package_git.go8
7 files changed, 0 insertions, 127 deletions
diff --git a/cmd/beku/command.go b/cmd/beku/command.go
index d82eb24..1cf85f8 100644
--- a/cmd/beku/command.go
+++ b/cmd/beku/command.go
@@ -265,9 +265,7 @@ func (cmd *command) parseLongFlags(arg string) (op operation, err error) {
return op, nil
}
-//
// parseFlags for multiple operations, invalid options, or empty targets.
-//
func (cmd *command) parseFlags(args []string) (err error) { //nolint: gocognit
if len(args) == 0 {
return errNoOperation
diff --git a/cmd/beku/main.go b/cmd/beku/main.go
index 72ca3a8..3156312 100644
--- a/cmd/beku/main.go
+++ b/cmd/beku/main.go
@@ -2,14 +2,12 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-//
// Beku is a command line program to manage packages in user's environment
// (GOPATH) directory. Beku provide syntax like `pacman`.
//
// See README in root of this repository for user manual [1].
//
// [1] https://github.com/shuLhan/beku
-//
package main
import (
diff --git a/common.go b/common.go
index fa49846..c90219f 100644
--- a/common.go
+++ b/common.go
@@ -10,7 +10,6 @@ import (
"strings"
)
-//
// GetCompareURL return the URL that compare two versions of package from
// given remote URL. Remote URL can be in git format
// ("git@github.com:<username>/<reponame>") or in HTTP format.
@@ -18,7 +17,6 @@ import (
// On package that hosted on Github, the compare URL format is,
//
// https://github.com/<username>/<reponame>/compare/<old-version>...<new-version>
-//
func GetCompareURL(remoteURL, oldVer, newVer string) (url string) {
if len(remoteURL) == 0 {
return
@@ -60,10 +58,8 @@ func GetCompareURL(remoteURL, oldVer, newVer string) (url string) {
return url
}
-//
// IsIgnoredDir will return true if directory start with "_" or ".", or
// equal with "vendor" or "testdata"; otherwise it will return false.
-//
func IsIgnoredDir(name string) bool {
prefix := name[0]
@@ -77,10 +73,8 @@ func IsIgnoredDir(name string) bool {
return false
}
-//
// IsTagVersion return true if "version" prefixed with "v" or contains at
// least one dot "." character.
-//
func IsTagVersion(version string) bool {
version = strings.TrimSpace(version)
if len(version) == 0 {
@@ -95,10 +89,8 @@ func IsTagVersion(version string) bool {
return false
}
-//
// parsePkgVersion given the following package-version format "pkg@v1.0.0", it
// will return "pkg" and "v1.0.0".
-//
func parsePkgVersion(pkgVersion string) (pkgName, version string) {
if len(pkgVersion) == 0 {
return
diff --git a/env.go b/env.go
index 57f9097..6969847 100644
--- a/env.go
+++ b/env.go
@@ -2,10 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-//
// Package beku provide library for managing Go packages in user's environment
// (GOPATH directory).
-//
package beku
import (
@@ -22,11 +20,9 @@ import (
libio "github.com/shuLhan/share/lib/io"
)
-//
// Env contains the environment of Go including GOROOT source directory,
// package root directory (prefix), list of packages, list of standard
// packages, and list of missing packages.
-//
type Env struct {
path string
prefix string // Equal to GOPATH.
@@ -56,9 +52,7 @@ type Env struct {
noDeps bool
}
-//
// NewEnvironment will gather all information in user system.
-//
func NewEnvironment(noDeps bool) (env *Env, err error) {
if len(build.Default.GOROOT) == 0 {
return nil, ErrGOROOT
@@ -93,11 +87,9 @@ func NewEnvironment(noDeps bool) (env *Env, err error) {
func (env *Env) initGopath() {
}
-//
// addExclude will add package to list of excluded packages. It will return
// true if importPath is not already exist in list; otherwise it will return
// false.
-//
func (env *Env) addExclude(importPath string) bool {
if len(importPath) == 0 {
return false
@@ -112,9 +104,7 @@ func (env *Env) addExclude(importPath string) bool {
return true
}
-//
// Exclude mark list of packages to be excluded from future operations.
-//
func (env *Env) Exclude(importPaths []string) {
exPkg := new(Package)
@@ -136,10 +126,8 @@ func (env *Env) Exclude(importPaths []string) {
}
}
-//
// Freeze all packages in database. Install all registered packages in
// database and remove non-registered from "src" and "pkg" directories.
-//
func (env *Env) Freeze() (err error) {
var localPkg *Package
@@ -189,9 +177,7 @@ out:
return nil
}
-//
// GetLocalPackage will return installed package from system.
-//
func (env *Env) GetLocalPackage(importPath string) (pkg *Package, err error) {
fullPath := filepath.Join(env.dirSrc, importPath)
dirGit := filepath.Join(fullPath, gitDir)
@@ -220,10 +206,8 @@ func (env *Env) GetLocalPackage(importPath string) (pkg *Package, err error) {
return
}
-//
// GetPackageFromDB will return index and package in database.
// If no package found, it will return -1 and nil.
-//
func (env *Env) GetPackageFromDB(importPath, remoteURL string) (int, *Package) {
for x := 0; x < len(env.pkgs); x++ {
if remoteURL == env.pkgs[x].RemoteURL {
@@ -243,10 +227,8 @@ func (env *Env) GetPackageFromDB(importPath, remoteURL string) (int, *Package) {
return -1, nil
}
-//
// GetUnused will get all non-registered packages from "src" directory,
// without including all excluded packages.
-//
func (env *Env) GetUnused(srcPath string) (err error) {
fis, err := ioutil.ReadDir(srcPath)
if err != nil {
@@ -306,10 +288,8 @@ func (env *Env) GetUnused(srcPath string) (err error) {
return nil
}
-//
// IsExcluded will return true if import path is registered as one of excluded
// package; otherwise it will return false.
-//
func (env *Env) IsExcluded(importPath string) bool {
if len(importPath) == 0 {
return true
@@ -322,9 +302,7 @@ func (env *Env) IsExcluded(importPath string) bool {
return false
}
-//
// Scan will gather all package information in user system to start `beku`-ing.
-//
func (env *Env) Scan() (err error) {
err = env.scanPackages(env.dirSrc)
if err != nil {
@@ -341,11 +319,9 @@ func (env *Env) Scan() (err error) {
return
}
-//
// scanStdPackages will traverse each directory in GOROOT `src` recursively
// until no subdirectory found. All path to subdirectories will be saved on
// Environment `pkgsStd`.
-//
func (env *Env) scanStdPackages(srcPath string) error {
fis, err := ioutil.ReadDir(srcPath)
if err != nil {
@@ -373,10 +349,8 @@ func (env *Env) scanStdPackages(srcPath string) error {
return nil
}
-//
// 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 {
fmt.Println("[ENV] scanPackages >>>", srcPath)
@@ -432,10 +406,8 @@ func (env *Env) scanPackages(srcPath string) (err error) {
return nil
}
-//
// newPackage will append the directory at path as a package only if
// its contain version information.
-//
func (env *Env) newPackage(fullPath string) (err error) {
pkgName := strings.TrimPrefix(fullPath, env.dirSrc+"/")
@@ -496,10 +468,8 @@ func (env *Env) addPackage(pkg *Package) {
}
}
-//
// addPackageMissing will add import path to list of missing package only if
// not exist yet.
-//
func (env *Env) addPackageMissing(importPath string) {
for x := 0; x < len(env.pkgsMissing); x++ {
if importPath == env.pkgsMissing[x] {
@@ -510,9 +480,7 @@ func (env *Env) addPackageMissing(importPath string) {
env.pkgsMissing = append(env.pkgsMissing, importPath)
}
-//
// Load will read saved dependencies from file.
-//
func (env *Env) Load(file string) (err error) {
if len(file) == 0 {
env.dbFile = env.dbDefFile
@@ -561,10 +529,8 @@ func (env *Env) loadPackages() {
}
}
-//
// Query the package database. If package is not empty, it will only show the
// information about that package.
-//
func (env *Env) Query(pkgs []string) {
format := fmt.Sprintf("%%-%ds %%s\n", env.fmtMaxPath)
@@ -588,9 +554,7 @@ func (env *Env) Query(pkgs []string) {
}
}
-//
// Rescan for new packages.
-//
func (env *Env) Rescan(firstTime bool) (ok bool, err error) {
err = env.Scan()
if err != nil {
@@ -667,10 +631,8 @@ func (env *Env) Rescan(firstTime bool) (ok bool, err error) {
return true, nil
}
-//
// Remove package from environment. If recursive is true, it will also remove
// their dependencies, as long as they are not required by other package.
-//
func (env *Env) Remove(rmPkg string, recursive bool) (err error) {
if env.IsExcluded(rmPkg) {
fmt.Printf(errExcluded, rmPkg)
@@ -788,10 +750,8 @@ func (env *Env) filterUnusedDeps(pkg *Package, tobeRemoved map[string]bool) {
}
}
-//
// removePackage from list environment (including source and installed archive
// or binary). This also remove in other packages "RequiredBy" if exist.
-//
func (env *Env) removePackage(importPath string) (err error) {
pkgIdx, pkg := env.GetPackageFromDB(importPath, "")
if pkg == nil {
@@ -809,10 +769,8 @@ func (env *Env) removePackage(importPath string) (err error) {
return
}
-//
// removePkgFromDBByIdx remove package from database by package index in the
// list.
-//
func (env *Env) removePkgFromDBByIdx(idx int) {
if idx < 0 {
return
@@ -827,9 +785,7 @@ func (env *Env) removePkgFromDBByIdx(idx int) {
env.dirty = true
}
-//
// removeRequiredBy will remove import path in package required-by.
-//
func (env *Env) removeRequiredBy(importPath string) {
for x := 0; x < len(env.pkgs); x++ {
ok := env.pkgs[x].RemoveRequiredBy(importPath)
@@ -839,9 +795,7 @@ func (env *Env) removeRequiredBy(importPath string) {
}
}
-//
// Save the dependencies to `file` only if it's dirty flag is true.
-//
func (env *Env) Save(file string) (err error) {
if !env.dirty {
return
@@ -907,9 +861,7 @@ func (env *Env) savePackages() {
}
}
-//
// String return formatted output of the environment instance.
-//
func (env *Env) String() string {
var buf bytes.Buffer
@@ -934,11 +886,9 @@ func (env *Env) String() string {
return buf.String()
}
-//
// install a package.
// 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) {
fmt.Printf("[ENV] install >>> Directory %s is not empty.\n", pkg.FullPath)
@@ -1019,9 +969,7 @@ func (env *Env) update(curPkg, newPkg *Package) (ok bool, err error) {
return true, nil
}
-//
// installMissing will install all missing packages.
-//
func (env *Env) installMissing(pkg *Package) (err error) {
if env.noDeps {
return
@@ -1048,11 +996,9 @@ func (env *Env) installMissing(pkg *Package) (err error) {
return
}
-//
// updateMissing will remove missing package if it's already provided by new
// package. If "addAsDep" is true and the new package provide the missing one,
// then it will be added as one of package dependencies.
-//
func (env *Env) updateMissing(newPkg *Package, addAsDep bool) {
var updated bool
@@ -1080,10 +1026,8 @@ func (env *Env) updateMissing(newPkg *Package, addAsDep bool) {
env.pkgsMissing = newMissings
}
-//
// Sync will download and install a package including their dependencies. If
// the importPath is defined, it will be downloaded into that directory.
-//
func (env *Env) Sync(pkgName, importPath string) (err error) {
err = ErrPackageName
@@ -1148,9 +1092,7 @@ func (env *Env) Sync(pkgName, importPath string) (err error) {
return nil
}
-//
// SyncMany packages at once.
-//
func (env *Env) SyncMany(pkgs []string) (err error) {
for _, pkg := range pkgs {
err = env.Sync(pkg, "")
@@ -1162,9 +1104,7 @@ func (env *Env) SyncMany(pkgs []string) (err error) {
return
}
-//
// SyncAll packages into latest version (tag or commit).
-//
func (env *Env) SyncAll() (err error) {
var (
countUpdate int
diff --git a/go/vcs/vcs.go b/go/vcs/vcs.go
index 2e2df04..12c2382 100644
--- a/go/vcs/vcs.go
+++ b/go/vcs/vcs.go
@@ -11,7 +11,6 @@
// for developers who want to write tools with similar semantics.
// It needs to be manually kept in sync with upstream when changes are
// made to cmd/go/internal/get; see https://golang.org/issue/11490.
-//
package vcs
import (
diff --git a/package.go b/package.go
index 2249a39..db3790d 100644
--- a/package.go
+++ b/package.go
@@ -26,10 +26,8 @@ const (
VCSModeGit = "git"
)
-//
// Package define Go package information: path to package, version, whether is
// tag or not, and VCS mode.
-//
type Package struct {
ImportPath string
FullPath string
@@ -46,10 +44,8 @@ type Package struct {
isTag bool
}
-//
// 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)
if err != nil {
@@ -78,9 +74,7 @@ func NewPackage(gopathSrc, name, importPath string) (pkg *Package, err error) {
return
}
-//
// CheckoutVersion will set the package version to new version.
-//
func (pkg *Package) CheckoutVersion(newVersion string) (err error) {
if pkg.vcsMode == VCSModeGit {
if len(pkg.RemoteBranch) == 0 {
@@ -94,9 +88,7 @@ func (pkg *Package) CheckoutVersion(newVersion string) (err error) {
return
}
-//
// CompareVersion will compare package version using current package as base.
-//
func (pkg *Package) CompareVersion(newPkg *Package) (err error) {
if pkg.vcsMode == VCSModeGit {
err = git.LogRevisions(pkg.FullPath, pkg.Version, newPkg.Version)
@@ -105,10 +97,8 @@ func (pkg *Package) CompareVersion(newPkg *Package) (err error) {
return
}
-//
// FetchLatestVersion will try to update the package and get the latest
// version (tag or commit).
-//
func (pkg *Package) FetchLatestVersion() (err error) {
if pkg.vcsMode == VCSModeGit {
err = git.FetchAll(pkg.FullPath)
@@ -132,9 +122,7 @@ func (pkg *Package) Freeze() (err error) {
return
}
-//
// GoClean will remove the package binaries and archives.
-//
func (pkg *Package) GoClean() (err error) {
_, err = os.Stat(pkg.FullPath)
if err != nil {
@@ -162,10 +150,8 @@ func (pkg *Package) GoClean() (err error) {
return
}
-//
// Install a package. Clone package "src" directory, set to the latest tag if
// exist or to the latest commit, and scan dependencies.
-//
func (pkg *Package) Install() (err error) {
if pkg.vcsMode == VCSModeGit {
err = pkg.gitInstall()
@@ -174,11 +160,9 @@ func (pkg *Package) Install() (err error) {
return
}
-//
// IsEqual will return true if current package have the same import path,
// remote name, remote URL, and version with other package; otherwise it will
// return false.
-//
func (pkg *Package) IsEqual(other *Package) bool {
if other == nil {
return false
@@ -202,11 +186,9 @@ func (pkg *Package) IsEqual(other *Package) bool {
return true
}
-//
// IsNewer will return true if current package is using tag and have newer
// version that other package. If current package is not using tag, it's
// always return true.
-//
func (pkg *Package) IsNewer(older *Package) bool {
if !pkg.isTag {
return true
@@ -214,9 +196,7 @@ func (pkg *Package) IsNewer(older *Package) bool {
return pkg.Version >= older.Version
}
-//
// Remove package installed binaries, archives, and source.
-//
func (pkg *Package) Remove() (err error) {
err = pkg.GoClean()
if err != nil {
@@ -240,11 +220,9 @@ func (pkg *Package) Remove() (err error) {
return
}
-//
// RemoveRequiredBy will remove package importPath from list of required-by.
// It will return true if importPath is removed from list, otherwise it will
// return false.
-//
func (pkg *Package) RemoveRequiredBy(importPath string) (ok bool) {
var requiredBy []string
@@ -261,10 +239,8 @@ func (pkg *Package) RemoveRequiredBy(importPath string) (ok bool) {
return
}
-//
// Scan will set the package version, `isTag` status, and remote URL using
// metadata in package repository.
-//
func (pkg *Package) Scan() (err error) {
if pkg.vcsMode == VCSModeGit {
err = pkg.gitScan()
@@ -279,10 +255,8 @@ func (pkg *Package) Scan() (err error) {
return
}
-//
// ScanDeps will scan package dependencies, removing standard packages, keep
// only external dependencies.
-//
func (pkg *Package) ScanDeps(env *Env) (err error) {
if debug.Value >= 1 {
fmt.Println("[PKG] ScanDeps", pkg.ImportPath)
@@ -300,10 +274,8 @@ func (pkg *Package) ScanDeps(env *Env) (err error) {
return
}
-//
// GetRecursiveImports will get all import path recursively using `go list`
// and return it as slice of string without any duplication.
-//
func (pkg *Package) GetRecursiveImports(env *Env) (
imports []string, err error,
) {
@@ -343,7 +315,6 @@ func (pkg *Package) GetRecursiveImports(env *Env) (
return imports, nil
}
-//
// addDep will add `importPath` to package dependencies only if it's,
//
// (0) not empty
@@ -360,7 +331,6 @@ func (pkg *Package) GetRecursiveImports(env *Env) (
//
// It will return true if import path is added as dependencies or as missing
// one; otherwise it will return false.
-//
func (pkg *Package) addDep(env *Env, importPath string) bool {
// (0)
if len(importPath) == 0 {
@@ -423,9 +393,7 @@ func (pkg *Package) addDep(env *Env, importPath string) bool {
return true
}
-//
// load package metadata from database (INI Section).
-//
func (pkg *Package) load(sec *ini.Section) {
pkg.vcsMode = VCSModeGit
@@ -451,12 +419,10 @@ func (pkg *Package) load(sec *ini.Section) {
}
}
-//
// GoInstall a package recursively ("./...").
//
// Set PATH to let go install that require gcc work when invoked from
// non-interactive shell (e.g. buildbot).
-//
func (pkg *Package) GoInstall(envPath string) (err error) {
cmd := exec.Command("go", "install")
if debug.Value >= 2 {
@@ -487,9 +453,7 @@ func (pkg *Package) GoInstall(envPath string) (err error) {
return
}
-//
// String return formatted output of the package instance.
-//
func (pkg *Package) String() string {
var buf bytes.Buffer
@@ -513,10 +477,8 @@ func (pkg *Package) String() string {
return buf.String()
}
-//
// Update the current package to the new package. The new package may contain
// new remote or new version.
-//
func (pkg *Package) Update(newPkg *Package) (err error) {
if pkg.ImportPath != newPkg.ImportPath {
err = os.Rename(pkg.FullPath, newPkg.FullPath)
@@ -551,7 +513,6 @@ func (pkg *Package) Update(newPkg *Package) (err error) {
return nil
}
-//
// UpdateMissingDep will remove missing package if it's already provided by
// new package import-path.
//
@@ -561,7 +522,6 @@ func (pkg *Package) Update(newPkg *Package) (err error) {
//
// It will return true if new package solve the missing deps on current
// package, otherwise it will return false.
-//
func (pkg *Package) UpdateMissingDep(newPkg *Package, addAsDep bool) (found bool) {
var missing []string
for x := 0; x < len(pkg.DepsMissing); x++ {
@@ -585,10 +545,8 @@ func (pkg *Package) UpdateMissingDep(newPkg *Package, addAsDep bool) (found bool
return
}
-//
// pushDep will append import path into list of dependencies only if it's not
// exist.
-//
func (pkg *Package) pushDep(importPath string) {
for x := 0; x < len(pkg.Deps); x++ {
if importPath == pkg.Deps[x] {
@@ -604,9 +562,7 @@ func (pkg *Package) pushDep(importPath string) {
}
}
-//
// pushMissing import path only if not exist yet.
-//
func (pkg *Package) pushMissing(importPath string) {
for x := 0; x < len(pkg.DepsMissing); x++ {
if pkg.DepsMissing[x] == importPath {
@@ -616,9 +572,7 @@ func (pkg *Package) pushMissing(importPath string) {
pkg.DepsMissing = append(pkg.DepsMissing, importPath)
}
-//
// pushRequiredBy add the import path as required by current package.
-//
func (pkg *Package) pushRequiredBy(importPath string) bool {
for x := 0; x < len(pkg.RequiredBy); x++ {
if importPath == pkg.RequiredBy[x] {
diff --git a/package_git.go b/package_git.go
index 6e88fb6..904e31f 100644
--- a/package_git.go
+++ b/package_git.go
@@ -12,9 +12,7 @@ import (
"github.com/shuLhan/share/lib/git"
)
-//
// gitFreeze set the package remote name and URL, branch, and revision.
-//
func (pkg *Package) gitFreeze() (err error) {
err = git.RemoteChange(pkg.FullPath, pkg.RemoteName, pkg.RemoteName,
pkg.RemoteURL)
@@ -39,9 +37,7 @@ func (pkg *Package) gitFreeze() (err error) {
return
}
-//
// gitInstall the package into source directory.
-//
func (pkg *Package) gitInstall() (err error) {
err = git.Clone(pkg.RemoteURL, pkg.FullPath)
if err != nil {
@@ -83,9 +79,7 @@ func (pkg *Package) gitInstall() (err error) {
return nil
}
-//
// gitScan will scan the package version and remote URL.
-//
func (pkg *Package) gitScan() (err error) {
pkg.Version, err = git.LatestVersion(pkg.FullPath)
if err != nil {
@@ -143,10 +137,8 @@ func (pkg *Package) gitGetBranch() (err error) {
return nil
}
-//
// gitUpdate will change the currrent package remote name, URL, or version
// based on new package information.
-//
func (pkg *Package) gitUpdate(newPkg *Package) (err error) {
if pkg.RemoteName != newPkg.RemoteName || pkg.RemoteURL != newPkg.RemoteURL {
err = git.RemoteChange(pkg.FullPath, pkg.RemoteName,