本文整理汇总了Golang中github.com/Masterminds/glide/cfg.Dependency.Subpackages方法的典型用法代码示例。如果您正苦于以下问题:Golang Dependency.Subpackages方法的具体用法?Golang Dependency.Subpackages怎么用?Golang Dependency.Subpackages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/Masterminds/glide/cfg.Dependency
的用法示例。
在下文中一共展示了Dependency.Subpackages方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestAddPkgsToConfig
func TestAddPkgsToConfig(t *testing.T) {
// Route output to discard so it's not displayed with the test output.
o := msg.Default.Stderr
msg.Default.Stderr = ioutil.Discard
conf := new(cfg.Config)
dep := new(cfg.Dependency)
dep.Name = "github.com/Masterminds/cookoo"
dep.Subpackages = append(dep.Subpackages, "convert")
conf.Imports = append(conf.Imports, dep)
names := []string{
"github.com/Masterminds/cookoo/fmt",
"github.com/Masterminds/semver",
}
addPkgsToConfig(conf, names, false, true)
if !conf.HasDependency("github.com/Masterminds/semver") {
t.Error("addPkgsToConfig failed to add github.com/Masterminds/semver")
}
d := conf.Imports.Get("github.com/Masterminds/cookoo")
found := false
for _, s := range d.Subpackages {
if s == "fmt" {
found = true
}
}
if !found {
t.Error("addPkgsToConfig failed to add subpackage to existing import")
}
// Restore messaging to original location
msg.Default.Stderr = o
}
示例2: addPkgsToConfig
// addPkgsToConfig adds the given packages to the config file.
//
// Along the way it:
// - ensures that this package is not in the ignore list
// - checks to see if this is already in the dependency list.
// - splits version of of package name and adds the version attribute
// - separates repo from packages
// - sets up insecure repo URLs where necessary
// - generates a list of subpackages
func addPkgsToConfig(conf *cfg.Config, names []string, insecure, nonInteract, testDeps bool) (int, error) {
if len(names) == 1 {
msg.Info("Preparing to install %d package.", len(names))
} else {
msg.Info("Preparing to install %d packages.", len(names))
}
numAdded := 0
for _, name := range names {
var version string
parts := strings.Split(name, "#")
if len(parts) > 1 {
name = parts[0]
version = parts[1]
}
msg.Info("Attempting to get package %s", name)
root, subpkg := util.NormalizeName(name)
if len(root) == 0 {
return 0, fmt.Errorf("Package name is required for %q.", name)
}
if conf.HasDependency(root) {
var moved bool
var dep *cfg.Dependency
// Move from DevImports to Imports
if !testDeps && !conf.Imports.Has(root) && conf.DevImports.Has(root) {
dep = conf.DevImports.Get(root)
conf.Imports = append(conf.Imports, dep)
conf.DevImports = conf.DevImports.Remove(root)
moved = true
numAdded++
msg.Info("--> Moving %s from testImport to import", root)
} else if testDeps && conf.Imports.Has(root) {
msg.Warn("--> Test dependency %s already listed as import", root)
}
// Check if the subpackage is present.
if subpkg != "" {
if dep == nil {
dep = conf.Imports.Get(root)
if dep == nil && testDeps {
dep = conf.DevImports.Get(root)
}
}
if dep.HasSubpackage(subpkg) {
if !moved {
msg.Warn("--> Package %q is already in glide.yaml. Skipping", name)
}
} else {
dep.Subpackages = append(dep.Subpackages, subpkg)
msg.Info("--> Adding sub-package %s to existing import %s", subpkg, root)
numAdded++
}
} else if !moved {
msg.Warn("--> Package %q is already in glide.yaml. Skipping", root)
}
continue
}
if conf.HasIgnore(root) {
msg.Warn("--> Package %q is set to be ignored in glide.yaml. Skipping", root)
continue
}
dep := &cfg.Dependency{
Name: root,
}
// When retriving from an insecure location set the repo to the
// insecure location.
if insecure {
dep.Repository = "http://" + root
}
if version != "" {
dep.Reference = version
} else if !nonInteract {
getWizard(dep)
}
if len(subpkg) > 0 {
dep.Subpackages = []string{subpkg}
}
if dep.Reference != "" {
msg.Info("--> Adding %s to your configuration with the version %s", dep.Name, dep.Reference)
} else {
msg.Info("--> Adding %s to your configuration", dep.Name)
//.........这里部分代码省略.........