示例#1
0
文件: main.go 项目: swasd/dpm
func doRemove(c *cli.Context) {
	home := os.Getenv("HOME")
	packageName := c.Args().First()
	e, err := repo.LoadIndex(filepath.Join(home, ".dpm", "index", "dpm.index"))
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	entry := e.FindByName(packageName)
	if entry == nil {
		fmt.Println("Cannot find package in the index")
		os.Exit(1)
	}

	packageFile := filepath.Join(home, "/.dpm/cache/", entry.Filename)
	_, err = os.Stat(packageFile)
	if err != nil {
		// not existed
		doInstall(c)
	}

	p, err := build.LoadPackage(packageFile)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	packageSpec, err := p.Spec()
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	provisionFile := filepath.Join(home, "/.dpm/workspace", entry.Hash, packageSpec.Provision)
	provSpec, err := provision.LoadFromFile(provisionFile)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	err = provSpec.RemoveMachines()
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
}
示例#2
0
文件: main.go 项目: swasd/dpm
func doInfo(c *cli.Context) {
	home := os.Getenv("HOME")
	packageName := c.Args().First()
	e, err := repo.LoadIndex(filepath.Join(home, ".dpm", "index", "dpm.index"))

	entry := e.FindByName(packageName)
	if entry == nil {
		fmt.Println("Cannot find package in the index")
		os.Exit(1)
	}

	packageFile := filepath.Join(home, "/.dpm/cache/", entry.Filename)
	_, err = os.Stat(packageFile)
	if err != nil {
		// not existed
		doInstall(c)
	}

	p, err := build.LoadPackage(packageFile)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	packageSpec, err := p.Spec()
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	fmt.Println("Package Information:")
	fmt.Printf("  Title:   %s\n", packageSpec.Title)
	fmt.Printf("  Name:    %s\n", packageSpec.Name)
	fmt.Printf("  Version: %s\n", packageSpec.Version)
	fmt.Printf("  SHA256:  %s\n", p.Sha256())
	fmt.Printf("  %s\n", packageSpec.Description)
}