beku

package module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 5, 2018 License: BSD-3-Clause Imports: 15 Imported by: 0

README

Beku

Beku is a library and program to manage packages in user's environment (GOPATH or vendor directory).

For beku as library see the following GoDoc.

For beku as program see the below documentation or at GoDoc.

Beku program

Beku is command line program to manage packages in user's environment (GOPATH or vendor directory). Beku provide syntax like pacman.

Beku read and write the package database into a file named "beku.db".

At first execution, beku will try to open the package database in current directory. If no file found, it will try to open "{prefix}/var/beku/beku.db". When both locations does not provide package database, beku will scan entire "{prefix}/src" and write the package database into "{prefix}/var/beku/beku.db".

Global Options

--noconfirm

No confirmation will be asked on any operation. Useful when running beku inside a script.

-d, --nodeps

Do not install any missing dependencies. This options can be used on freeze or sync operations.

-V, --vendor

Operate in vendor mode. This option used only when first scanning (beku -V -S). Any operation after that, will use the "vendor" directory in current working directory as installation prefix.

Freeze Operation

-B, --freeze

Operate on the package database and user's environment. This operation will ensure that all packages listed on database file is installed with their specific version. Also, all packages that are not registered will be removed from "src" and "pkg" directories.

Database Operation

-D, --database

Modify the package database. This operation required one of the options below.

Options
-e, --exclude <pkg ...>

Remove list of package by import path from database and add mark it as excluded package. Excluded package will be ignored on future operations.

Examples
$ beku -De github.com/shuLhan/beku

Exclude package "github.com/shuLhan/beku" from future scanning, installation, or removal operations.

Query Operation

-Q, --query [pkg ...]

Query the package database.

Remove Operation

-R, --remove [pkg]

Remove package from environment, including source and installed binaries and archives.

Options
[-s,--recursive]

Also remove all target dependencies, as long as is not required by other packages.

Examples
$ beku -R github.com/shuLhan/beku

Remove package "github.com/shuLhan/beku" source in "{prefix}/src", their installed binaries in "{prefix}/bin", and their installed archives on "{prefix}/pkg/{GOOS}_{GOARCH}".

$ beku -R github.com/shuLhan/beku --recursive
$ beku -Rs github.com/shuLhan/beku

Remove package "github.com/shuLhan/beku" source in "{prefix}/src", their installed binaries in "{prefix}/bin", their installed archives on "{prefix}/pkg/{GOOS}_{GOARCH}", and all their dependencies.

Sync Operation

-S, --sync <pkg[@version]>

Synchronizes package. Given a package import path, beku will try to clone the package into source directory and set the package version to latest the tag. If no tag found, it will use the latest commit on master branch. A specific version can be set using "@version" suffix.

If package already exist, it will reset the HEAD to the version that is set on database file.

If no parameter is given, beku will do a rescan, checking for new packages.

After downloading a package, beku will check for known vendor files and run vendor command on the package directory to install their dependencies on package's vendor directory. The following vendor file will be detected,

  • Godeps, will invoke gdm
  • Gopkg.toml, will invoke dep
  • vendor/vendor.json, will invoke govendor

If no vendor files found, beku will install the dependencies manually.

Installation of vendor tools is not handled by beku automatically, user must install them manually, either by using go get or by using beku -S, e.g.

$ beku -S https://github.com/sparrc/gdm
$ beku -S https://github.com/golang/dep
$ beku -S https://github.com/kardianos/govendor
Options
[--into <destination>]

This option will install the package import path into custom directory. It is useful if you have the fork of the main package but want to install it to the legacy directory.

[-u,--update]

Fetch new tag or commit from remote repository. User will be asked for confirmation before upgrade.

Examples
$ beku -S golang.org/x/text

Download package golang.org/x/text into {prefix}/src/golang.org/x/text, and set their version to the latest commit on branch master.

$ beku -S github.com/golang/text --into golang.org/x/text

Download package github.com/golang/text into {prefix}/src/golang.org/x/text, and set their version to the latest commit on branch master.

$ beku -S golang.org/x/text@v0.3.0

Download package golang.org/x/text into {prefix}/src/golang.org/x/text and checkout the tag v0.3.0 as the working version.

$ beku -S golang.org/x/text@5c1cf69

Download package golang.org/x/text into {prefix}/src/golang.org/x/text and checkout the commit 5c1cf69 as the working version.

$ beku -Su

Update all packages in database to new tag or commits with approval from user.

Known Limitations

  • Only work with package hosted with Git on HTTPS or SSH.

  • Tested only on Git v2.17 or greater

References

[1] https://www.archlinux.org/pacman/

Documentation

Overview

Package beku provide library for managing Go packages in user's environment (GOPATH or vendor directory).

Index

Constants

View Source
const (
	DebugL1 debugMode = 1 << iota
	DebugL2
)

List of debug levels.

View Source
const (
	// DefDBName define default database name, where the dependencies will
	// be saved and loaded.
	DefDBName = "beku.db"
)
View Source
const (
	VCSModeGit = "git"
)

Variables

View Source
var (
	ErrGOROOT = errors.New("GOROOT is not defined")

	// ErrVersion define an error when directory have VCS metadata (e.g.
	// `.git` directory) but did not have any tag or commit.
	ErrVersion = errors.New("No tag or commit found")

	// ErrRemote define an error when package remote URL is empty or
	// invalid.
	ErrRemote = errors.New("Empty or invalid remote URL found")

	// ErrPackageName define an error if package name is empty or invalid.
	ErrPackageName = errors.New("Empty or invalid package name")
)

List of error messages.

View Source
var (
	// Debug level for this package. Set from environment variable
	// BEKU_DEBUG.
	Debug debugMode
)

Functions

func GetCompareURL

func GetCompareURL(remoteURL, oldVer, newVer string) (url string)

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.

On package that hosted on Github, the compare URL format is,

https://github.com/<username>/<reponame>/compare/<old-version>...<new-version>

func IsDirEmpty

func IsDirEmpty(dir string) (ok bool)

IsDirEmpty will return true if directory is not exist or empty; otherwise it will return false.

func IsFileExist added in v0.3.0

func IsFileExist(parent, relpath string) bool

IsFileExist will return true if relative path is exist on parent directory; otherwise it will return false.

func IsIgnoredDir

func IsIgnoredDir(name string) bool

IsIgnoredDir will return true if directory start with "_" or ".", or equal with "vendor" or "testdata"; otherwise it will return false.

func IsTagVersion

func IsTagVersion(version string) bool

IsTagVersion return true if "version" prefixed with "v" or contains at least one dot "." character.

func RmdirEmptyAll

func RmdirEmptyAll(path string) error

RmdirEmptyAll remove directory in path if it's empty until one of the parent is not empty.

Types

type Env

type Env struct {
	NoConfirm bool
	// contains filtered or unexported fields
}

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.

func NewEnvironment

func NewEnvironment(vendor, noDeps bool) (env *Env, err error)

NewEnvironment will gather all information in user system.

func (*Env) Exclude added in v0.2.0

func (env *Env) Exclude(importPaths []string)

Exclude mark list of packages to be excluded from future operations.

func (*Env) Freeze

func (env *Env) Freeze() (err error)

Freeze all packages in database. Install all registered packages in database and remove non-registered from "src" and "pkg" directories.

func (*Env) GetPackage

func (env *Env) GetPackage(importPath string) (pkg *Package, err error)

GetPackage will return installed package from system.

func (*Env) GetPackageFromDB

func (env *Env) GetPackageFromDB(importPath, remoteURL string) (int, *Package)

GetPackageFromDB will return index and pointer to package in database. If no package found, it will return -1 and nil.

func (*Env) GetUnused

func (env *Env) GetUnused(srcPath string) (err error)

GetUnused will get all non-registered packages from "src" directory, without including all excluded packages.

func (*Env) IsExcluded added in v0.2.0

func (env *Env) IsExcluded(importPath string) bool

IsExcluded will return true if import path is registered as one of excluded package; otherwise it will return false.

func (*Env) Load

func (env *Env) Load(file string) (err error)

Load will read saved dependencies from file.

func (*Env) Query

func (env *Env) Query(pkgs []string)

Query the package database. If package is not empty, it will only show the information about that package.

func (*Env) Remove

func (env *Env) Remove(rmPkg string, recursive bool) (err error)

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) Rescan

func (env *Env) Rescan(firstTime bool) (ok bool, err error)

Rescan for new packages.

func (*Env) Save

func (env *Env) Save(file string) (err error)

Save the dependencies to `file` only if it's dirty flag is true.

func (*Env) Scan

func (env *Env) Scan() (err error)

Scan will gather all package information in user system to start `beku`-ing.

func (*Env) String

func (env *Env) String() string

String return formatted output of the environment instance.

func (*Env) Sync

func (env *Env) Sync(pkgName, importPath string) (err error)

Sync will download and install a package including their dependencies. If the importPath is defined, it will be downloaded into that directory.

(1) First, we check if pkgName contains version. (2) And then we check if package already installed, by comparing with database. (2.1) If package already installed, do an update. (2.2) If package is not installed, clone the repository into `importPath`, and checkout the latest tag or the latest commit.

func (*Env) SyncAll

func (env *Env) SyncAll() (err error)

SyncAll packages into latest version (tag or commit).

func (*Env) SyncMany

func (env *Env) SyncMany(pkgs []string) (err error)

SyncMany packages at once.

type Package

type Package struct {
	ImportPath  string
	FullPath    string
	ScanPath    string
	RemoteName  string
	RemoteURL   string
	Version     string
	VersionNext string
	DepsMissing []string
	Deps        []string
	RequiredBy  []string
	// contains filtered or unexported fields
}

Package define Go package information: path to package, version, whether is tag or not, and VCS mode.

func NewPackage

func NewPackage(env *Env, pkgName, importPath string) (
	pkg *Package, err error,
)

NewPackage create a package set the package version, tag status, and dependencies.

func (*Package) CheckoutVersion

func (pkg *Package) CheckoutVersion(newVersion string) (err error)

CheckoutVersion will set the package version to new version.

func (*Package) CompareVersion

func (pkg *Package) CompareVersion(newPkg *Package) (err error)

CompareVersion will compare package version using current package as base.

func (*Package) Fetch

func (pkg *Package) Fetch() (err error)

Fetch will try to update the package and get the latest version (tag or commit).

func (*Package) GetRecursiveImports

func (pkg *Package) GetRecursiveImports(env *Env) (
	imports []string, err error,
)

GetRecursiveImports will get all import path recursively using `go list` and return it as slice of string without any duplication.

func (*Package) GoClean

func (pkg *Package) GoClean() (err error)

GoClean will remove the package binaries and archives.

func (*Package) GoInstall

func (pkg *Package) GoInstall(env *Env) (err error)

GoInstall a package recursively ("./...").

(1) Set PATH to let go install that require gcc work when invoked from non-interactive shell (e.g. buildbot).

func (*Package) Install

func (pkg *Package) Install() (err error)

Install a package. Clone package "src" directory, set to the latest tag if exist or to the latest commit, and scan dependencies.

func (*Package) IsEqual

func (pkg *Package) IsEqual(other *Package) bool

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 (*Package) Remove

func (pkg *Package) Remove() (err error)

Remove package installed binaries, archives, and source.

func (*Package) RemoveRequiredBy

func (pkg *Package) RemoveRequiredBy(importPath string) (ok bool)

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 (*Package) Run added in v0.3.0

func (pkg *Package) Run(env *Env, cmds []string) (err error)

Run command on package root directory.

func (*Package) Scan

func (pkg *Package) Scan() (err error)

Scan will set the package version, `isTag` status, and remote URL using metadata in package repository.

func (*Package) ScanBuild added in v0.3.0

func (pkg *Package) ScanBuild() (cmd vendorMode)

ScanBuild files on package root directory. The following build files is known by beku,

* Godeps: gdm * Gopkg.toml: dep

func (*Package) ScanDeps

func (pkg *Package) ScanDeps(env *Env) (err error)

ScanDeps will scan package dependencies, removing standard packages, keep only external dependencies.

func (*Package) String

func (pkg *Package) String() string

String return formatted output of the package instance.

func (*Package) Update

func (pkg *Package) Update(newPkg *Package) (err error)

Update the current package to the new package. The new package may contain new remote or new version.

func (*Package) UpdateMissingDep

func (pkg *Package) UpdateMissingDep(newPkg *Package, addAsDep bool) (found bool)

UpdateMissingDep will remove missing package if it's already provided by new package import-path.

If "addAsDep" is true, it will also, (1) add new package as one of package dependencies of current package, and (2) add current package as required by new package.

It will return true if new package solve the missing deps on current package, otherwise it will return false.

Directories

Path Synopsis
cmd
beku
Beku is a command line program to manage packages in user's environment (GOPATH or vendor) directory.
Beku is a command line program to manage packages in user's environment (GOPATH or vendor) directory.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL