Esempio n. 1
0
func search(mo *ModeOptions) {
	v := mo.Args[0]
	db := database.GetDatabase()
	rgx := regexp.MustCompile(v)
	fmt.Printf("Searching %#v...\n", v)
	ids := new(idArray)
	db.Packages().Each(func(i int, pe *database.PkgElement) {
		idx := rgx.FindStringIndex(pe.Name)
		if idx != nil {
			ids.Add(i)
		}
		idx = rgx.FindStringIndex(pe.FullName)
		if idx != nil {
			ids.Add(i)
		}
		idx = rgx.FindStringIndex(pe.Description)
		if idx != nil {
			ids.Add(i)
		}
	})
	for i := 0; i < ids.Size(); i++ {
		data := db.Packages().Get(ids.Get(i))
		fmt.Printf("\n%s [%s] – %s\n %s\n", data.FullName, data.Name, pkgTypeName[data.Type], data.Description)
	}
}
Esempio n. 2
0
File: info.go Progetto: Szewek/mcpm
func info(mo *ModeOptions) {
	pn := mo.Args[0]
	db := database.GetDatabase()
	if pkg := db.Packages().GetByName(pn); pkg != nil {
		pr, hte := util.DownloadPackageInfo(pkg.Type, pkg.ID, pkg.Name)
		util.Must(hte)
		defer pr.Close()

		var pi packageInfo
		jd := json.NewDecoder(pr)
		util.Must(jd.Decode(&pi))

		fmt.Printf("Name: %s\nAuthors: %s\nVersions:\n", pi.Title, pi.Authors)
		for k, v := range pi.Versions {
			fmt.Printf("  %s:\n", k)
			for i := 0; i < len(v); i++ {
				fmt.Printf("    %s; %s (%d) (%s)\n", v[i].Name, v[i].Type, v[i].Id, v[i].CreatedAt)
			}
		}
	}
}