示例#1
0
文件: main.go 项目: zmarcantel/hearth
//==================================================
// remove action
//==================================================
func action_remove_package(ctx *cli.Context) {
	conf, err := config.Open()
	if err != nil {
		log.Fatal(err)
	}

	args := ctx.Args()
	if len(args) == 0 {
		log.Fatalf("no package name given.")
	}

	for _, p := range args {
		if _, exists := conf.Packages[p]; exists == false {
			log.Printf("pakage %s does not exist", p)
			continue
		}

		dir := path.Join(conf.BaseDirectory, p)
		err = os.RemoveAll(dir)
		if err != nil {
			log.Fatal(err)
		}

		delete(conf.Packages, p)
	}

	if err := conf.Write(config.Path()); err != nil {
		log.Fatal(err)
	}
}
示例#2
0
文件: main.go 项目: zmarcantel/hearth
//==================================================
// modify action
//==================================================
func action_modify_package(ctx *cli.Context) {
	conf, err := config.Open()
	if err != nil {
		log.Fatal(err)
	}

	args := ctx.Args()
	if len(args) == 0 {
		log.Fatalf("no package name given.")
	}

	for _, p := range args {
		pack, exists := conf.Packages[p]
		if exists == false {
			log.Printf("pakage %s does not exist", p)
			continue
		}

		target := ctx.String("target")
		cmd := ctx.String("cmd")
		pre_cmd := ctx.String("pre")
		post_cmd := ctx.String("post")

		if len(target) > 0 {
			home_path := os.Getenv("HOME")
			if strings.HasPrefix(target, home_path) {
				pack.Target = path.Join("~", target[len(home_path):])
			} else {
				pack.Target = target
			}
		} else if cmd != "" {
			pack.InstallCmd.Cmd = cmd

			if pre_cmd != "" {
				pack.InstallCmd.PreCmd = pre_cmd
			}

			if post_cmd != "" {
				pack.InstallCmd.PostCmd = post_cmd
			}
		}

		conf.Packages[p] = pack
	}

	if err := conf.Write(config.Path()); err != nil {
		log.Fatal(err)
	}
}
示例#3
0
文件: repo.go 项目: zmarcantel/hearth
// Open the managed repository. Opens the config, gets the repo directory, and
// fills all the necessary data
func Open() (Repository, error) {
	var repo Repository
	conf, err := config.Open()
	if err != nil {
		return repo, err
	}

	conf_path := conf.BaseDirectory
	if strings.HasPrefix(conf_path, "~/") {
		conf_path = path.Join(os.Getenv("HOME"), conf_path[2:])
	}

	repo_raw, err := git.OpenRepository(conf_path)
	if err != nil {
		return repo, fmt.Errorf("could not open git repository: %s", err)
	}
	repo = Repository{repo_raw, conf_path, conf}

	return repo, nil
}