aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2018-06-05 16:59:50 +0700
committerShulhan <ms@kilabit.info>2018-06-05 16:59:50 +0700
commitd7f5cb4233394a0e810de15ecf2e97a79a9a3acd (patch)
tree2d2dabec9084ca6447ceb33868a2056427edea53
parent85e948e20fccd93fb34ea957e6d1a16a68b0d40d (diff)
downloadbeku-d7f5cb4233394a0e810de15ecf2e97a79a9a3acd.tar.xz
Add option to disable installing dependencies
-rw-r--r--README.md5
-rw-r--r--beku_test.go2
-rw-r--r--cmd/beku/command.go37
-rw-r--r--env.go10
4 files changed, 47 insertions, 7 deletions
diff --git a/README.md b/README.md
index c9546bf..47a0cc4 100644
--- a/README.md
+++ b/README.md
@@ -30,6 +30,11 @@ package database into "{prefix}/var/beku/beku.db".
No confirmation will be asked on any operation. Useful when running beku
inside a script.
+ --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
diff --git a/beku_test.go b/beku_test.go
index fa35ed3..c10c486 100644
--- a/beku_test.go
+++ b/beku_test.go
@@ -110,7 +110,7 @@ func TestMain(m *testing.M) {
os.Exit(1)
}
- testEnv, err = NewEnvironment(false)
+ testEnv, err = NewEnvironment(false, false)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
diff --git a/cmd/beku/command.go b/cmd/beku/command.go
index 71dde1a..a1ff0b3 100644
--- a/cmd/beku/command.go
+++ b/cmd/beku/command.go
@@ -29,6 +29,7 @@ const (
flagOperationSync = "Synchronize package. If no package is given, it will do rescan."
flagOptionNoConfirm = "No confirmation will be asked on any operation."
+ flagOptionNoDeps = "Do not install any missing dependencies."
flagOptionRecursive = "Remove package including their dependencies."
flagOptionSyncInto = "Download package into `directory`."
flagOptionUpdate = "Update all packages to latest version."
@@ -42,6 +43,7 @@ type command struct {
syncInto string
firstTime bool
noConfirm bool
+ noDeps bool
vendor bool
}
@@ -50,6 +52,8 @@ func (cmd *command) usage() {
common options:
--noconfirm
` + flagOptionNoConfirm + `
+ -d,--nodeps
+ ` + flagOptionNoDeps + `
-V,--vendor
` + flagOptionVendor + `
operations:
@@ -100,6 +104,20 @@ func (cmd *command) parseDatabaseFlags(arg string) (operation, error) {
return opNone, errInvalidOptions
}
+func (cmd *command) parseFreezeFlags(arg string) (operation, error) {
+ if len(arg) == 0 {
+ return opNone, nil
+ }
+
+ switch arg[0] {
+ case 'd':
+ cmd.noDeps = true
+ return opNone, nil
+ }
+
+ return opNone, errInvalidOptions
+}
+
func (cmd *command) parseSyncFlags(arg string) (operation, error) {
if len(arg) == 0 {
return opNone, nil
@@ -108,6 +126,9 @@ func (cmd *command) parseSyncFlags(arg string) (operation, error) {
switch arg[0] {
case 'u':
return opUpdate, nil
+ case 'd':
+ cmd.noDeps = true
+ return opNone, nil
}
return opNone, errInvalidOptions
@@ -140,6 +161,11 @@ func (cmd *command) parseShortFlags(arg string) (operation, error) {
)
switch arg[0] {
+ case 'd':
+ if len(arg) > 1 {
+ return opNone, errInvalidOptions
+ }
+ cmd.noDeps = true
case 's':
if len(arg) > 1 {
return opNone, errInvalidOptions
@@ -151,10 +177,11 @@ func (cmd *command) parseShortFlags(arg string) (operation, error) {
}
op = opHelp
case 'B':
- if len(arg) > 1 {
- return opNone, errInvalidOptions
+ op, err = cmd.parseFreezeFlags(arg[1:])
+ if err != nil {
+ return opNone, err
}
- op = opFreeze
+ op |= opFreeze
case 'D':
op, err = cmd.parseDatabaseFlags(arg[1:])
if err != nil {
@@ -209,6 +236,8 @@ func (cmd *command) parseLongFlags(arg string) (op operation, err error) {
op = opSyncInto
case "noconfirm":
cmd.noConfirm = true
+ case "nodeps":
+ cmd.noDeps = true
case "query":
op = opQuery
case "recursive":
@@ -364,7 +393,7 @@ func newCommand() (cmd *command, err error) {
return
}
- cmd.env, err = beku.NewEnvironment(cmd.vendor)
+ cmd.env, err = beku.NewEnvironment(cmd.vendor, cmd.noDeps)
if err != nil {
return
}
diff --git a/env.go b/env.go
index 6b5f1d0..bae51dd 100644
--- a/env.go
+++ b/env.go
@@ -45,13 +45,14 @@ type Env struct {
fmtMaxPath int
dirty bool
NoConfirm bool
+ noDeps bool
vendor bool
}
//
// NewEnvironment will gather all information in user system.
//
-func NewEnvironment(vendor bool) (env *Env, err error) {
+func NewEnvironment(vendor, noDeps bool) (env *Env, err error) {
if !vendor {
if len(build.Default.GOPATH) == 0 {
vendor = true
@@ -69,6 +70,7 @@ func NewEnvironment(vendor bool) (env *Env, err error) {
dirBin: filepath.Join(build.Default.GOPATH, dirBin),
dirPkg: filepath.Join(build.Default.GOPATH, dirPkg,
build.Default.GOOS+"_"+build.Default.GOARCH),
+ noDeps: noDeps,
vendor: vendor,
}
@@ -1095,7 +1097,11 @@ func (env *Env) update(curPkg, newPkg *Package) (ok bool, err error) {
// installMissing will install all missing packages.
//
func (env *Env) installMissing(pkg *Package) (err error) {
- fmt.Printf("[ENV] installMissing %s\n", pkg.ImportPath)
+ if env.noDeps {
+ return
+ }
+
+ fmt.Printf("[ENV] installMissing %s >>> %s\n", pkg.ImportPath, pkg.DepsMissing)
for _, misImportPath := range pkg.DepsMissing {
_, misPkg := env.GetPackageFromDB(misImportPath, "")