Exemple #1
0
//==================================================
// 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)
	}
}
Exemple #2
0
//==================================================
// 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)
	}
}
Exemple #3
0
//==================================================
// init action
//==================================================
func action_init(ctx *cli.Context) {
	// get the default repo path (overwritten below) and the forced config path
	repo_path := repository.DefaultPath()
	config_final_path := config.Path()

	// if the user wants a different repo, let them
	if ctx.IsSet("repo") {
		repo_path = opts.RepoPath
	}

	// create the repo (and starter config + any misc files)
	repo, err := repository.Create(repo_path, opts.RepoOrigin)
	if err != nil {
		log.Fatalf("could not initialize repository: %s", err.Error())
	}
	defer repo.Free()

	// symlink {REPO_DIR}/.hearthrc --> $HOME/.hearthrc
	config_src_path := path.Join(repo.Path, config.Name)
	if err := os.Symlink(config_src_path, config_final_path); err != nil {
		log.Fatalf("could not link hearth config into home directory: %s", err.Error())
	}
}