本文整理汇总了Golang中github.com/Masterminds/glide/msg.Error函数的典型用法代码示例。如果您正苦于以下问题:Golang Error函数的具体用法?Golang Error怎么用?Golang Error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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.Error("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.Error("Error cleaning up VCS dir for %s:%s", dep.Name, err)
}
}
}
return nil
}
示例2: Get
// Get fetches one or more dependencies and installs.
//
// This includes resolving dependency resolution and re-generating the lock file.
func Get(names []string, installer *repo.Installer, insecure, skipRecursive bool) {
base := gpath.Basepath()
EnsureGopath()
EnsureVendorDir()
conf := EnsureConfig()
glidefile, err := gpath.Glide()
if err != nil {
msg.Die("Could not find Glide file: %s", err)
}
// Add the packages to the config.
if err := addPkgsToConfig(conf, names, insecure); err != nil {
msg.Die("Failed to get new packages: %s", err)
}
// Fetch the new packages. Can't resolve versions via installer.Update if
// get is called while the vendor/ directory is empty so we checkout
// everything.
installer.Checkout(conf, false)
// Prior to resolving dependencies we need to start working with a clone
// of the conf because we'll be making real changes to it.
confcopy := conf.Clone()
if !skipRecursive {
// Get all repos and update them.
// TODO: Can we streamline this in any way? The reason that we update all
// of the dependencies is that we need to re-negotiate versions. For example,
// if an existing dependency has the constraint >1.0 and this new package
// adds the constraint <2.0, then this may re-resolve the existing dependency
// to be between 1.0 and 2.0. But changing that dependency may then result
// in that dependency's dependencies changing... so we sorta do the whole
// thing to be safe.
err = installer.Update(confcopy)
if err != nil {
msg.Die("Could not update packages: %s", err)
}
}
// Set Reference
if err := repo.SetReference(confcopy); err != nil {
msg.Error("Failed to set references: %s", err)
}
// VendoredCleanup
if installer.UpdateVendored {
repo.VendoredCleanup(confcopy)
}
// Write YAML
if err := conf.WriteFile(glidefile); err != nil {
msg.Die("Failed to write glide YAML file: %s", err)
}
if !skipRecursive {
// Write lock
writeLock(conf, confcopy, base)
} else {
msg.Warn("Skipping lockfile generation because full dependency tree is not being calculated")
}
}
示例3: queueUnseen
// queueUnseenImports scans a package's imports and adds any new ones to the
// processing queue.
func (r *Resolver) queueUnseen(pkg string, queue *list.List) error {
// A pkg is marked "seen" as soon as we have inspected it the first time.
// Seen means that we have added all of its imports to the list.
// Already queued indicates that we've either already put it into the queue
// or intentionally not put it in the queue for fatal reasons (e.g. no
// buildable source).
deps, err := r.imports(pkg)
if err != nil && !strings.HasPrefix(err.Error(), "no buildable Go source") {
msg.Error("Could not find %s: %s", pkg, err)
return err
// NOTE: If we uncomment this, we get lots of "no buildable Go source" errors,
// which don't ever seem to be helpful. They don't actually indicate an error
// condition, and it's perfectly okay to run into that condition.
//} else if err != nil {
// msg.Warn(err.Error())
}
for _, d := range deps {
if _, ok := r.alreadyQ[d]; !ok {
r.alreadyQ[d] = true
queue.PushBack(d)
}
}
return nil
}
示例4: 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
}
示例5: EnsureGoVendor
// EnsureGoVendor ensures that the Go version is correct.
func EnsureGoVendor() {
// 6l was removed in 1.5, when vendoring was introduced.
cmd := exec.Command("go", "tool", "6l")
if _, err := cmd.CombinedOutput(); err == nil {
msg.Warn("You must install the Go 1.5 or greater toolchain to work with Glide.\n")
os.Exit(1)
}
// This works with 1.5 and >=1.6.
cmd = exec.Command("go", "env", "GO15VENDOREXPERIMENT")
if out, err := cmd.CombinedOutput(); err != nil {
msg.Error("Error looking for $GOVENDOREXPERIMENT: %s.\n", err)
os.Exit(1)
} else if strings.TrimSpace(string(out)) != "1" {
msg.Warn("To use Glide, you must set GO15VENDOREXPERIMENT=1\n")
os.Exit(1)
}
// Verify the setup isn't for the old version of glide. That is, this is
// no longer assuming the _vendor directory as the GOPATH. Inform of
// the change.
if _, err := os.Stat("_vendor/"); err == nil {
msg.Warn(`Your setup appears to be for the previous version of Glide.
Previously, vendor packages were stored in _vendor/src/ and
_vendor was set as your GOPATH. As of Go 1.5 the go tools
recognize the vendor directory as a location for these
files. Glide has embraced this. Please remove the _vendor
directory or move the _vendor/src/ directory to vendor/.` + "\n")
os.Exit(1)
}
}
示例6: Process
// Process imports dependencies for a package
func (d *VersionHandler) Process(pkg string) (e error) {
root := util.GetRootFromPackage(pkg)
// Skip any references to the root package.
if root == d.RootPackage {
return nil
}
// We have not tried to import, yet.
// Should we look in places other than the root of the project?
if d.Imported[root] == false {
d.Imported[root] = true
p := filepath.Join(d.Destination, root)
f, deps, err := importer.Import(p)
if f && err == nil {
for _, dep := range deps {
// The fist one wins. Would something smater than this be better?
exists := d.Use.Get(dep.Name)
if exists == nil && (dep.Reference != "" || dep.Repository != "") {
d.Use.Add(dep.Name, dep)
}
}
} else if err != nil {
msg.Error("Unable to import from %s. Err: %s", root, err)
e = err
}
}
return
}
示例7: Plugin
// Plugin attempts to find and execute a plugin based on a command.
//
// Exit code 99 means the plugin was never executed. Code 1 means the program
// exited badly.
func Plugin(command string, args []string) {
cwd, err := os.Getwd()
if err != nil {
msg.ExitCode(99)
msg.Die("Could not get working directory: %s", err)
}
cmd := "glide-" + command
var fullcmd string
if fullcmd, err = exec.LookPath(cmd); err != nil {
fullcmd = cwd + "/" + cmd
if _, err := os.Stat(fullcmd); err != nil {
msg.ExitCode(99)
msg.Die("Command %s does not exist.", cmd)
}
}
// Turning os.Args first argument from `glide` to `glide-command`
args[0] = cmd
// Removing the first argument (command)
removed := false
for i, v := range args {
if removed == false && v == command {
args = append(args[:i], args[i+1:]...)
removed = true
}
}
pa := os.ProcAttr{
Files: []*os.File{os.Stdin, os.Stdout, os.Stderr},
Dir: cwd,
}
msg.Debug("Delegating to plugin %s (%v)\n", fullcmd, args)
proc, err := os.StartProcess(fullcmd, args, &pa)
if err != nil {
msg.Error("Failed to execute %s: %s", cmd, err)
os.Exit(98)
}
if _, err := proc.Wait(); err != nil {
msg.Error(err.Error())
os.Exit(1)
}
}
示例8: NoVendor
// NoVendor generates a list of source code directories, excepting `vendor/`.
//
// If "onlyGo" is true, only folders that have Go code in them will be returned.
//
// If suffix is true, this will append `/...` to every directory.
func NoVendor(path string, onlyGo, suffix bool) {
// This is responsible for printing the results of noVend.
paths, err := noVend(path, onlyGo, suffix)
if err != nil {
msg.Error("Failed to walk file tree: %s", err)
msg.Warn("FIXME: NoVendor should exit with non-zero exit code.")
return
}
for _, p := range paths {
msg.Puts(p)
}
}
示例9: EnsureGopath
// EnsureGopath fails if GOPATH is not set, or if $GOPATH/src is missing.
//
// Otherwise it returns the value of GOPATH.
func EnsureGopath() string {
gp := os.Getenv("GOPATH")
if gp == "" {
msg.Die("$GOPATH is not set.")
}
_, err := os.Stat(path.Join(gp, "src"))
if err != nil {
msg.Error("Could not find %s/src.\n", gp)
msg.Info("As of Glide 0.5/Go 1.5, this is required.\n")
msg.Die("Wihtout src, cannot continue. %s", err)
}
return gp
}
示例10: main
func main() {
app := cli.NewApp()
app.Name = "glide"
app.Usage = usage
app.Version = version
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "yaml, y",
Value: "glide.yaml",
Usage: "Set a YAML configuration file.",
},
cli.BoolFlag{
Name: "quiet, q",
Usage: "Quiet (no info or debug messages)",
},
cli.BoolFlag{
Name: "debug",
Usage: "Print Debug messages (verbose)",
},
cli.StringFlag{
Name: "home",
Value: defaultGlideDir(),
Usage: "The location of Glide files",
EnvVar: "GLIDE_HOME",
},
cli.BoolFlag{
Name: "no-color",
Usage: "Turn off colored output for log messages",
},
}
app.CommandNotFound = func(c *cli.Context, command string) {
// TODO: Set some useful env vars.
action.Plugin(command, os.Args)
}
app.Before = startup
app.Commands = commands()
// Detect errors from the Before and After calls and exit on them.
if err := app.Run(os.Args); err != nil {
msg.Error(err.Error())
os.Exit(1)
}
// If there was a Error message exit non-zero.
if msg.HasErrored() {
m := msg.Color(msg.Red, "An Error has occured")
msg.Msg(m)
os.Exit(2)
}
}
示例11: resolveList
// resolveList takes a list and resolves it.
func (r *Resolver) resolveList(queue *list.List) ([]string, error) {
var failedDep string
for e := queue.Front(); e != nil; e = e.Next() {
dep := e.Value.(string)
//msg.Warn("#### %s ####", dep)
//msg.Info("Seen Count: %d", len(r.seen))
// Catch the outtermost dependency.
failedDep = dep
err := filepath.Walk(dep, func(path string, fi os.FileInfo, err error) error {
if err != nil && err != filepath.SkipDir {
return err
}
// Skip files.
if !fi.IsDir() {
return nil
}
// Skip dirs that are not source.
if !srcDir(fi) {
//msg.Debug("Skip resource %s", fi.Name())
return filepath.SkipDir
}
// Anything that comes through here has already been through
// the queue.
r.alreadyQ[path] = true
e := r.queueUnseen(path, queue)
if err != nil {
failedDep = path
//msg.Error("Failed to fetch dependency %s: %s", path, err)
}
return e
})
if err != nil && err != filepath.SkipDir {
msg.Error("Dependency %s failed to resolve: %s.", failedDep, err)
return []string{}, err
}
}
res := make([]string, 0, queue.Len())
for e := queue.Front(); e != nil; e = e.Next() {
res = append(res, e.Value.(string))
}
return res, nil
}
示例12: Install
// Install installs a vendor directory based on an existing Glide configuration.
func Install(installer *repo.Installer) {
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)
return
}
// Load lockfile
lock, err := LoadLockfile(base, conf)
if err != nil {
msg.Die("Could not load lockfile.")
}
// Delete unused packages
if installer.DeleteUnused {
// It's unclear whether this should operate off of the lock, or off
// of the glide.yaml file. I'd think that doing this based on the
// lock would be much more reliable.
dependency.DeleteUnused(conf)
}
// 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); err != nil {
msg.Error("Failed to set references: %s (Skip to cleanup)", err)
}
// VendoredCleanup. This should ONLY be run if UpdateVendored was specified.
if installer.UpdateVendored {
repo.VendoredCleanup(newConf)
}
}
示例13: EnsureGopath
// EnsureGopath fails if GOPATH is not set, or if $GOPATH/src is missing.
//
// Otherwise it returns the value of GOPATH.
func EnsureGopath() string {
gps := gpath.Gopaths()
if len(gps) == 0 {
msg.Die("$GOPATH is not set.")
}
for _, gp := range gps {
_, err := os.Stat(path.Join(gp, "src"))
if err != nil {
msg.Warn("%s", err)
continue
}
return gp
}
msg.Error("Could not find any of %s/src.\n", strings.Join(gps, "/src, "))
msg.Info("As of Glide 0.5/Go 1.5, this is required.\n")
msg.Die("Wihtout src, cannot continue.")
return ""
}
示例14: Remove
func Remove(packages []string, inst *repo.Installer) {
base := gpath.Basepath()
EnsureGopath()
EnsureVendorDir()
conf := EnsureConfig()
glidefile, err := gpath.Glide()
if err != nil {
msg.Die("Could not find Glide file: %s", err)
}
msg.Info("Preparing to remove %d packages.", len(packages))
conf.Imports = rmDeps(packages, conf.Imports)
conf.DevImports = rmDeps(packages, conf.DevImports)
// Copy used to generate locks.
confcopy := conf.Clone()
confcopy.Imports = inst.List(confcopy)
if err := repo.SetReference(confcopy); err != nil {
msg.Error("Failed to set references: %s", err)
}
// TODO: Right now, there is no flag to enable this, so this will never be
// run. I am not sure whether we should allow this in a rm op or not.
if inst.UpdateVendored {
repo.VendoredCleanup(confcopy)
}
// Write glide.yaml
if err := conf.WriteFile(glidefile); err != nil {
msg.Die("Failed to write glide YAML file: %s", err)
}
// Write glide lock
writeLock(conf, confcopy, base)
}
示例15: Update
// Update updates repos and the lock file from the main glide yaml.
func Update(installer *repo.Installer, skipRecursive bool) {
base := "."
EnsureGopath()
EnsureVendorDir()
conf := EnsureConfig()
// Delete unused packages
if installer.DeleteUnused {
dependency.DeleteUnused(conf)
}
// Try to check out the initial dependencies.
if err := installer.Checkout(conf, false); err != nil {
msg.Die("Failed to do initial checkout of config: %s", err)
}
// Set the versions for the initial dependencies so that resolved dependencies
// are rooted in the correct version of the base.
if err := repo.SetReference(conf); err != nil {
msg.Die("Failed to set initial config references: %s", err)
}
// Prior to resolving dependencies we need to start working with a clone
// of the conf because we'll be making real changes to it.
confcopy := conf.Clone()
if !skipRecursive {
// Get all repos and update them.
err := installer.Update(confcopy)
if err != nil {
msg.Die("Could not update packages: %s", err)
}
// TODO: There is no support here for importing Godeps, GPM, and GB files.
// I think that all we really need to do now is hunt for these files, and then
// roll their version numbers into the config file.
// Set references. There may be no remaining references to set since the
// installer set them as it went to make sure it parsed the right imports
// from the right version of the package.
msg.Info("Setting references for remaining imports")
if err := repo.SetReference(confcopy); err != nil {
msg.Error("Failed to set references: %s (Skip to cleanup)", err)
}
}
// Vendored cleanup
// VendoredCleanup. This should ONLY be run if UpdateVendored was specified.
if installer.UpdateVendored {
repo.VendoredCleanup(confcopy)
}
// Write glide.yaml (Why? Godeps/GPM/GB?)
// I think we don't need to write a new Glide file because update should not
// change anything important. It will just generate information about
// transative dependencies, all of which belongs exclusively in the lock
// file, not the glide.yaml file.
// TODO(mattfarina): Detect when a new dependency has been added or removed
// from the project. A removed dependency should warn and an added dependency
// should be added to the glide.yaml file. See issue #193.
if !skipRecursive {
// Write lock
hash, err := conf.Hash()
if err != nil {
msg.Die("Failed to generate config hash. Unable to generate lock file.")
}
lock := cfg.NewLockfile(confcopy.Imports, hash)
if err := lock.WriteFile(filepath.Join(base, gpath.LockFile)); err != nil {
msg.Error("Could not write lock file to %s: %s", base, err)
return
}
msg.Info("Project relies on %d dependencies.", len(confcopy.Imports))
} else {
msg.Warn("Skipping lockfile generation because full dependency tree is not being calculated")
}
}