示例#1
0
// InfoPackageCommand implements the command:
//    info package [*name* ]
// which show information about a package or lists all packages.
func InfoPackageSubcmd(args []string) {
	if len(args) > 2 {
		for _, pkg_name := range args[2:len(args)] {
			if pkg := gub.Program().PackagesByName[pkg_name]; pkg != nil {
				gub.Msg("Package %s: \"%s\"", pkg_name, pkg.Object.Path())
				gub.Section("Package members:")
				var names []string
				for k, _ := range pkg.Members {
					names = append(names, k)
				}
				sort.Strings(names)
				opts := columnize.DefaultOptions()
				opts.DisplayWidth = gub.Maxwidth
				opts.LinePrefix = "  "
				mems := strings.TrimRight(columnize.Columnize(names, opts),
					"\n")
				gub.Msg(mems)

			} else {
				gub.Errmsg("Package %s not imported", pkg_name)
			}
		}
	} else {
		pkgNames := []string{}
		for pkg := range gub.Program().PackagesByName {
			pkgNames = append(pkgNames, pkg)
		}
		gub.PrintSorted("All imported packages", pkgNames)
	}
}
示例#2
0
func printReflectTypeMap(title string, m map[string]reflect.Type) {
	if len(m) > 0 {
		list := []string{}
		for item := range m {
			list = append(list, item)
		}
		gub.PrintSorted(title, list)
	}
}