本文整理汇总了Golang中github.com/Masterminds/glide/msg.Info函数的典型用法代码示例。如果您正苦于以下问题:Golang Info函数的具体用法?Golang Info怎么用?Golang Info使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Info函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: MirrorsList
// MirrorsList displays a list of currently setup mirrors.
func MirrorsList() error {
home := gpath.Home()
op := filepath.Join(home, "mirrors.yaml")
if _, err := os.Stat(op); os.IsNotExist(err) {
msg.Info("No mirrors exist. No mirrors.yaml file not found")
return nil
}
ov, err := mirrors.ReadMirrorsFile(op)
if err != nil {
msg.Die("Unable to read mirrors.yaml file: %s", err)
}
if len(ov.Repos) == 0 {
msg.Info("No mirrors found")
return nil
}
msg.Info("Mirrors...")
for _, r := range ov.Repos {
if r.Vcs == "" {
msg.Info("--> %s replaced by %s", r.Original, r.Repo)
} else {
msg.Info("--> %s replaced by %s (%s)", r.Original, r.Repo, r.Vcs)
}
}
return nil
}
示例2: Install
// Install installs the dependencies from a Lockfile.
func (i *Installer) Install(lock *cfg.Lockfile, conf *cfg.Config) (*cfg.Config, error) {
// Create a config setup based on the Lockfile data to process with
// existing commands.
newConf := &cfg.Config{}
newConf.Name = conf.Name
newConf.Imports = make(cfg.Dependencies, len(lock.Imports))
for k, v := range lock.Imports {
newConf.Imports[k] = cfg.DependencyFromLock(v)
}
newConf.DevImports = make(cfg.Dependencies, len(lock.DevImports))
for k, v := range lock.DevImports {
newConf.DevImports[k] = cfg.DependencyFromLock(v)
}
newConf.DeDupe()
if len(newConf.Imports) == 0 && len(newConf.DevImports) == 0 {
msg.Info("No dependencies found. Nothing installed.")
return newConf, nil
}
msg.Info("Downloading dependencies. Please wait...")
err := LazyConcurrentUpdate(newConf.Imports, i, newConf)
if err != nil {
return newConf, err
}
err = LazyConcurrentUpdate(newConf.DevImports, i, newConf)
return newConf, err
}
示例3: Parse
// Parse parses a GPM-flavored Godeps file.
func Parse(dir string) ([]*cfg.Dependency, error) {
path := filepath.Join(dir, "Godeps")
if i, err := os.Stat(path); err != nil {
return []*cfg.Dependency{}, nil
} else if i.IsDir() {
msg.Info("Godeps is a directory. This is probably a Godep project.\n")
return []*cfg.Dependency{}, nil
}
msg.Info("Found Godeps file.\n")
buf := []*cfg.Dependency{}
file, err := os.Open(path)
if err != nil {
return buf, err
}
scanner := bufio.NewScanner(file)
for scanner.Scan() {
parts, ok := parseGodepsLine(scanner.Text())
if ok {
dep := &cfg.Dependency{Name: parts[0]}
if len(parts) > 1 {
dep.Reference = parts[1]
}
buf = append(buf, dep)
}
}
if err := scanner.Err(); err != nil {
msg.Warn("Scan failed: %s\n", err)
return buf, err
}
return buf, nil
}
示例4: Install
// Install installs a vendor directory based on an existing Glide configuration.
func Install(installer *repo.Installer, stripVendor bool) {
cache.SystemLock()
base := "."
// Ensure GOPATH
EnsureGopath()
EnsureVendorDir()
conf := EnsureConfig()
// Lockfile exists
if !gpath.HasLock(base) {
msg.Info("Lock file (glide.lock) does not exist. Performing update.")
Update(installer, false, stripVendor)
return
}
// Load lockfile
lock, err := cfg.ReadLockFile(filepath.Join(base, gpath.LockFile))
if err != nil {
msg.Die("Could not load lockfile.")
}
// Verify lockfile hasn't changed
hash, err := conf.Hash()
if err != nil {
msg.Die("Could not load lockfile.")
} else if hash != lock.Hash {
fmt.Println(hash, lock.Hash)
foo, _ := conf.Marshal()
fmt.Println(string(foo))
msg.Warn("Lock file may be out of date. Hash check of YAML failed. You may need to run 'update'")
}
// Install
newConf, err := installer.Install(lock, conf)
if err != nil {
msg.Die("Failed to install: %s", err)
}
msg.Info("Setting references.")
// Set reference
if err := repo.SetReference(newConf, installer.ResolveTest); err != nil {
msg.Die("Failed to set references: %s (Skip to cleanup)", err)
}
err = installer.Export(newConf)
if err != nil {
msg.Die("Unable to export dependencies to vendor directory: %s", err)
}
if stripVendor {
msg.Info("Removing nested vendor and Godeps/_workspace directories...")
err := gpath.StripVendor()
if err != nil {
msg.Err("Unable to strip vendor directories: %s", err)
}
}
}
示例5: MirrorsSet
// MirrorsSet sets a mirror to use
func MirrorsSet(o, r, v string) error {
if o == "" || r == "" {
msg.Err("Both the original and mirror values are required")
return nil
}
home := gpath.Home()
op := filepath.Join(home, "mirrors.yaml")
var ov *mirrors.Mirrors
if _, err := os.Stat(op); os.IsNotExist(err) {
msg.Info("No mirrors.yaml file exists. Creating new one")
ov = &mirrors.Mirrors{
Repos: make(mirrors.MirrorRepos, 0),
}
} else {
ov, err = mirrors.ReadMirrorsFile(op)
if err != nil {
msg.Die("Error reading existing mirrors.yaml file: %s", err)
}
}
found := false
for i, re := range ov.Repos {
if re.Original == o {
found = true
msg.Info("%s found in mirrors. Replacing with new settings", o)
ov.Repos[i].Repo = r
ov.Repos[i].Vcs = v
}
}
if !found {
nr := &mirrors.MirrorRepo{
Original: o,
Repo: r,
Vcs: v,
}
ov.Repos = append(ov.Repos, nr)
}
msg.Info("%s being set to %s", o, r)
err := ov.WriteFile(op)
if err != nil {
msg.Err("Error writing mirrors.yaml file: %s", err)
} else {
msg.Info("mirrors.yaml written with changes")
}
return nil
}
示例6: Install
// Install installs the dependencies from a Lockfile.
func (i *Installer) Install(lock *cfg.Lockfile, conf *cfg.Config) (*cfg.Config, error) {
cwd, err := gpath.Vendor()
if err != nil {
return conf, err
}
// Create a config setup based on the Lockfile data to process with
// existing commands.
newConf := &cfg.Config{}
newConf.Name = conf.Name
newConf.Imports = make(cfg.Dependencies, len(lock.Imports))
for k, v := range lock.Imports {
newConf.Imports[k] = &cfg.Dependency{
Name: v.Name,
Reference: v.Version,
Repository: v.Repository,
VcsType: v.VcsType,
Subpackages: v.Subpackages,
Arch: v.Arch,
Os: v.Os,
}
}
newConf.DevImports = make(cfg.Dependencies, len(lock.DevImports))
for k, v := range lock.DevImports {
newConf.DevImports[k] = &cfg.Dependency{
Name: v.Name,
Reference: v.Version,
Repository: v.Repository,
VcsType: v.VcsType,
Subpackages: v.Subpackages,
Arch: v.Arch,
Os: v.Os,
}
}
newConf.DeDupe()
if len(newConf.Imports) == 0 {
msg.Info("No dependencies found. Nothing installed.\n")
return newConf, nil
}
msg.Info("Downloading dependencies. Please wait...")
ConcurrentUpdate(newConf.Imports, cwd, i, newConf)
ConcurrentUpdate(newConf.DevImports, cwd, i, newConf)
return newConf, nil
}
示例7: Parse
// Parse parses a GB-flavored manifest file.
func Parse(dir string) ([]*cfg.Dependency, error) {
path := filepath.Join(dir, "vendor/manifest")
if fi, err := os.Stat(path); err != nil || fi.IsDir() {
return []*cfg.Dependency{}, nil
}
msg.Info("Found GB manifest file in %s", gpath.StripBasepath(dir))
msg.Info("--> Parsing GB metadata...")
buf := []*cfg.Dependency{}
file, err := os.Open(path)
if err != nil {
return buf, err
}
defer file.Close()
man := Manifest{}
dec := json.NewDecoder(file)
if err := dec.Decode(&man); err != nil {
return buf, err
}
seen := map[string]bool{}
for _, d := range man.Dependencies {
pkg, sub := util.NormalizeName(d.Importpath)
if _, ok := seen[pkg]; ok {
if len(sub) == 0 {
continue
}
for _, dep := range buf {
if dep.Name == pkg {
dep.Subpackages = append(dep.Subpackages, sub)
}
}
} else {
seen[pkg] = true
dep := &cfg.Dependency{
Name: pkg,
Reference: d.Revision,
Repository: d.Repository,
}
if len(sub) > 0 {
dep.Subpackages = []string{sub}
}
buf = append(buf, dep)
}
}
return buf, nil
}
示例8: Create
// Create creates/initializes a new Glide repository.
//
// This will fail if a glide.yaml already exists.
//
// By default, this will scan the present source code directory for dependencies.
//
// If skipImport is set to true, this will not attempt to import from an existing
// GPM, Godep, or GB project if one should exist. However, it will still attempt
// to read the local source to determine required packages.
func Create(base string, skipImport, nonInteractive bool) {
glidefile := gpath.GlideFile
// Guard against overwrites.
guardYAML(glidefile)
// Guess deps
conf := guessDeps(base, skipImport)
// Write YAML
msg.Info("Writing configuration file (%s)", glidefile)
if err := conf.WriteFile(glidefile); err != nil {
msg.Die("Could not save %s: %s", glidefile, err)
}
var res bool
if !nonInteractive {
msg.Info("Would you like Glide to help you find ways to improve your glide.yaml configuration?")
msg.Info("If you want to revisit this step you can use the config-wizard command at any time.")
msg.Info("Yes (Y) or No (N)?")
res = msg.PromptUntilYorN()
if res {
ConfigWizard(base)
}
}
if !res {
msg.Info("You can now edit the glide.yaml file. Consider:")
msg.Info("--> Using versions and ranges. See https://glide.sh/docs/versions/")
msg.Info("--> Adding additional metadata. See https://glide.sh/docs/glide.yaml/")
msg.Info("--> Running the config-wizard command to improve the versions in your configuration")
}
}
示例9: Parse
// Parse parses a Godep's Godeps file.
//
// It returns the contents as a dependency array.
func Parse(dir string) ([]*cfg.Dependency, error) {
path := filepath.Join(dir, "Godeps/Godeps.json")
if _, err := os.Stat(path); err != nil {
return []*cfg.Dependency{}, nil
}
msg.Info("Found Godeps.json file in %s", gpath.StripBasepath(dir))
msg.Info("--> Parsing Godeps metadata...")
buf := []*cfg.Dependency{}
godeps := &Godeps{}
// Get a handle to the file.
file, err := os.Open(path)
if err != nil {
return buf, err
}
defer file.Close()
dec := json.NewDecoder(file)
if err := dec.Decode(godeps); err != nil {
return buf, err
}
seen := map[string]bool{}
for _, d := range godeps.Deps {
pkg, sub := util.NormalizeName(d.ImportPath)
if _, ok := seen[pkg]; ok {
if len(sub) == 0 {
continue
}
// Modify existing dep with additional subpackages.
for _, dep := range buf {
if dep.Name == pkg {
dep.Subpackages = append(dep.Subpackages, sub)
}
}
} else {
seen[pkg] = true
dep := &cfg.Dependency{Name: pkg, Reference: d.Rev}
if sub != "" {
dep.Subpackages = []string{sub}
}
buf = append(buf, dep)
}
}
return buf, nil
}
示例10: LazyConcurrentUpdate
// LazyConcurrentUpdate updates only deps that are not already checkout out at the right version.
//
// This is only safe when updating from a lock file.
func LazyConcurrentUpdate(deps []*cfg.Dependency, cwd string, i *Installer, c *cfg.Config) error {
newDeps := []*cfg.Dependency{}
for _, dep := range deps {
destPath := filepath.Join(i.VendorPath(), dep.Name)
// Get a VCS object for this directory
repo, err := dep.GetRepo(destPath)
if err != nil {
newDeps = append(newDeps, dep)
continue
}
ver, err := repo.Version()
if err != nil {
newDeps = append(newDeps, dep)
continue
}
if ver == dep.Reference {
msg.Info("--> Found desired version %s %s!", dep.Name, dep.Reference)
continue
}
msg.Debug("--> Queue %s for update (%s != %s).", dep.Name, ver, dep.Reference)
newDeps = append(newDeps, dep)
}
if len(newDeps) > 0 {
return ConcurrentUpdate(newDeps, cwd, i, c)
}
return nil
}
示例11: waitOnLock
func waitOnLock() error {
var announced bool
for {
fi, err := os.Stat(lockFileName)
if err != nil && os.IsNotExist(err) {
return nil
} else if err != nil {
return err
}
diff := time.Now().Sub(fi.ModTime())
if diff.Seconds() > 15 {
return nil
}
if !announced {
announced = true
msg.Info("Waiting on Glide global cache access")
}
// Check on the lock file every 15 seconds.
// TODO(mattfarina): should this be a different length?
time.Sleep(time.Second)
}
}
示例12: VendoredCleanup
// VendoredCleanup cleans up vendored codebases after an update.
//
// This should _only_ be run for installations that do not want VCS repos inside
// of the vendor/ directory.
func VendoredCleanup(conf *cfg.Config) error {
vend, err := gpath.Vendor()
if err != nil {
return err
}
for _, dep := range conf.Imports {
if dep.UpdateAsVendored == true {
msg.Info("Cleaning up vendored package %s\n", dep.Name)
// Remove the VCS directory
cwd := filepath.Join(vend, dep.Name)
repo, err := dep.GetRepo(cwd)
if err != nil {
msg.Err("Error cleaning up %s:%s", dep.Name, err)
continue
}
t := repo.Vcs()
err = os.RemoveAll(cwd + string(os.PathSeparator) + "." + string(t))
if err != nil {
msg.Err("Error cleaning up VCS dir for %s:%s", dep.Name, err)
}
}
}
return nil
}
示例13: List
func (i *Installer) List(conf *cfg.Config) []*cfg.Dependency {
base := "."
vpath := i.VendorPath()
ic := newImportCache()
v := &VersionHandler{
Destination: vpath,
Use: ic,
Imported: make(map[string]bool),
Conflicts: make(map[string]bool),
Config: conf,
}
// Update imports
res, err := dependency.NewResolver(base)
if err != nil {
msg.Die("Failed to create a resolver: %s", err)
}
res.Config = conf
res.VersionHandler = v
msg.Info("Resolving imports")
_, err = allPackages(conf.Imports, res)
if err != nil {
msg.Die("Failed to retrieve a list of dependencies: %s", err)
}
msg.Warn("devImports not resolved.")
return conf.Imports
}
示例14: NotFound
func (m *MissingPackageHandler) NotFound(pkg string) (bool, error) {
root := util.GetRootFromPackage(pkg)
// Skip any references to the root package.
if root == m.RootPackage {
return false, nil
}
dest := filepath.Join(m.destination, root)
// This package may have been placed on the list to look for when it wasn't
// downloaded but it has since been downloaded before coming to this entry.
if _, err := os.Stat(dest); err == nil {
return true, nil
}
msg.Info("Fetching %s into %s", pkg, m.destination)
d := m.Config.Imports.Get(root)
// If the dependency is nil it means the Config doesn't yet know about it.
if d == nil {
d = m.Use.Get(root)
// We don't know about this dependency so we create a basic instance.
if d == nil {
d = &cfg.Dependency{Name: root}
}
m.Config.Imports = append(m.Config.Imports, d)
}
if err := VcsGet(d, dest, m.home, m.cache, m.cacheGopath, m.useGopath); err != nil {
return false, err
}
return true, nil
}
示例15: OnGopath
func (m *MissingPackageHandler) OnGopath(pkg string) (bool, error) {
// If useGopath is false, we fall back to the strategy of fetching from
// remote.
if !m.useGopath {
return m.NotFound(pkg)
}
root := util.GetRootFromPackage(pkg)
// Skip any references to the root package.
if root == m.RootPackage {
return false, nil
}
msg.Info("Copying package %s from the GOPATH.", pkg)
dest := filepath.Join(m.destination, pkg)
// Find package on Gopath
for _, gp := range gpath.Gopaths() {
src := filepath.Join(gp, pkg)
// FIXME: Should probably check if src is a dir or symlink.
if _, err := os.Stat(src); err == nil {
if err := os.MkdirAll(dest, os.ModeDir|0755); err != nil {
return false, err
}
if err := gpath.CopyDir(src, dest); err != nil {
return false, err
}
return true, nil
}
}
msg.Error("Could not locate %s on the GOPATH, though it was found before.", pkg)
return false, nil
}