Пример #1
0
// Display displays a tree view of the given project.
//
// FIXME: The output formatting could use some TLC.
func Display(b *util.BuildCtxt, basedir, myName string, level int, core bool, l *list.List) {
	deps := walkDeps(b, basedir, myName)
	for _, name := range deps {
		found := findPkg(b, name, basedir)
		if found.Loc == dependency.LocUnknown {
			m := "glide get " + found.Name
			msg.Puts("\t%s\t(%s)", found.Name, m)
			continue
		}
		if !core && found.Loc == dependency.LocGoroot || found.Loc == dependency.LocCgo {
			continue
		}
		msg.Print(strings.Repeat("|\t", level-1) + "|-- ")

		f := findInList(found.Name, l)
		if f == true {
			msg.Puts("(Recursion) %s   (%s)", found.Name, found.Path)
		} else {
			// Every branch in the tree is a copy to handle all the branches
			cl := copyList(l)
			cl.PushBack(found.Name)
			msg.Puts("%s   (%s)", found.Name, found.Path)
			Display(b, found.Path, found.Name, level+1, core, cl)
		}
	}
}
Пример #2
0
// Info prints information about a project based on a passed in format.
func Info(format string) {
	conf := EnsureConfig()
	var buffer bytes.Buffer
	varInit := false
	for _, varfmt := range format {
		if varInit {
			switch varfmt {
			case 'n':
				buffer.WriteString(conf.Name)
			case 'd':
				buffer.WriteString(conf.Description)
			case 'h':
				buffer.WriteString(conf.Home)
			case 'l':
				buffer.WriteString(conf.License)
			default:
				msg.Die("Invalid format %s", string(varfmt))
			}
		} else {
			switch varfmt {
			case '%':
				varInit = true
				continue
			default:
				buffer.WriteString(string(varfmt))
			}
		}
		varInit = false
	}
	msg.Puts(buffer.String())
}
Пример #3
0
func outputList(l PackageList, format string) {
	switch format {
	case textFormat:
		msg.Puts("INSTALLED packages:")
		for _, pkg := range l.Installed {
			msg.Puts("\t%s", pkg)
		}

		if len(l.Missing) > 0 {
			msg.Puts("\nMISSING packages:")
			for _, pkg := range l.Missing {
				msg.Puts("\t%s", pkg)
			}
		}
		if len(l.Gopath) > 0 {
			msg.Puts("\nGOPATH packages:")
			for _, pkg := range l.Gopath {
				msg.Puts("\t%s", pkg)
			}
		}
	case jsonFormat:
		json.NewEncoder(msg.Default.Stdout).Encode(l)
	case jsonPrettyFormat:
		b, err := json.MarshalIndent(l, "", "  ")
		if err != nil {
			msg.Die("could not unmarshal package list: %s", err)
		}
		msg.Puts(string(b))
	default:
		msg.Die("invalid output format: must be one of: json|json-pretty|text")
	}
}
Пример #4
0
// 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)
	}
}
Пример #5
0
// Tree prints a tree representing dependencies.
func Tree(basedir string, showcore bool) {
	buildContext, err := util.GetBuildContext()
	if err != nil {
		msg.Die("Failed to get a build context: %s", err)
	}
	myName := buildContext.PackageName(basedir)

	if basedir == "." {
		var err error
		basedir, err = os.Getwd()
		if err != nil {
			msg.Die("Could not get working directory")
		}
	}

	msg.Puts(myName)
	l := list.New()
	l.PushBack(myName)
	tree.Display(buildContext, basedir, myName, 1, showcore, l)
}
Пример #6
0
// Tree prints a tree representing dependencies.
func Tree(basedir string, showcore bool) {
	msg.Warn("The tree command is deprecated and will be removed in a future version")
	buildContext, err := util.GetBuildContext()
	if err != nil {
		msg.Die("Failed to get a build context: %s", err)
	}
	myName := buildContext.PackageName(basedir)

	if basedir == "." {
		var err error
		basedir, err = os.Getwd()
		if err != nil {
			msg.Die("Could not get working directory")
		}
	}

	msg.Puts(myName)
	l := list.New()
	l.PushBack(myName)
	tree.Display(buildContext, basedir, myName, 1, showcore, l)
}
Пример #7
0
// List lists all of the dependencies of the current project.
//
// Params:
//  - dir (string): basedir
//  - deep (bool): whether to do a deep scan or a shallow scan
func List(basedir string, deep bool) {

	basedir, err := filepath.Abs(basedir)
	if err != nil {
		msg.Die("Could not read directory: %s", err)
	}

	r, err := dependency.NewResolver(basedir)
	if err != nil {
		msg.Die("Could not create a resolver: %s", err)
	}
	h := &dependency.DefaultMissingPackageHandler{Missing: []string{}, Gopath: []string{}}
	r.Handler = h

	sortable, err := r.ResolveLocal(deep)
	if err != nil {
		msg.Die("Error listing dependencies: %s", err)
	}

	msg.Info("Sorting...")
	sort.Strings(sortable)

	msg.Puts("INSTALLED packages:")
	for _, k := range sortable {
		v, err := filepath.Rel(basedir, k)
		if err != nil {
			//msg.Warn("Failed to Rel path: %s", err)
			v = k
		}
		msg.Puts("\t%s", v)
	}

	if len(h.Missing) > 0 {
		msg.Puts("\nMISSING packages:")
		for _, pkg := range h.Missing {
			msg.Puts("\t%s", pkg)
		}
	}
	if len(h.Gopath) > 0 {
		msg.Puts("\nGOPATH packages:")
		for _, pkg := range h.Gopath {
			msg.Puts("\t%s", pkg)
		}
	}
}
Пример #8
0
// Name prints the name of the package, according to the glide.yaml file.
func Name() {
	conf := EnsureConfig()
	msg.Puts(conf.Name)
}
Пример #9
0
// About prints information about Glide.
func About() {
	msg.Puts(aboutMessage)
}