Beispiel #1
0
func (f *FetchCommand) Execute(args []string) error {
	if len(args) == 0 {
		return &utils.ErrArgument{}
	} else if len(args) > 1 {
		return &utils.ErrProxy{}
	}

	if len(strings.Split(args[0], "/")) != 1 {
		return &utils.ErrProxy{}
	}

	users := strings.Split(args[0], ",")
	remotes, err := utils.Remotes()

	if err != nil {
		return err
	}

	remoteAdd := &remote.AddCommand{}

	for _, user := range users {
		if _, ok := remotes[user]; !ok {
			remoteAdd.Execute([]string{user})
		}
	}

	if err := utils.Git(append([]string{"fetch", "--multiple"}, users...)...); err != nil {
		return err
	}

	utils.HandleInfo("Fetched from remotes " + args[0])

	return nil
}
Beispiel #2
0
func (d *DestroyCommand) Execute(args []string) error {
	config.Set("user", "")
	config.Set("token", "")

	utils.HandleInfo("You are now in `public` mode")

	return nil
}
Beispiel #3
0
func (a *AddCommand) Execute(args []string) error {
	if len(args) == 2 {
		Set(args[0], args[1])
		utils.HandleInfo("Configuration changed successfully")
	} else {
		return &utils.ErrArgument{}
	}

	return nil
}
Beispiel #4
0
func (r *ReadmeCommand) Execute(args []string) error {
	if len(args) > 1 {
		return &utils.ErrArgument{}
	}

	var user string
	name, err := utils.RepoName()

	if err != nil {
		return err
	}

	if len(args) == 1 {
		user = args[0]
	} else {
		user = config.Get("user")
	}

	name = user + "/" + name

	root, _ := utils.RepoRoot()
	readme := filepath.Join(root, "README.md")

	read, err := ioutil.ReadFile(readme)

	if err != nil {
		return err
	}

	data := string(read[:])

	data = data + "\n## Installation\n\n```bash\n$\n```\n\n"
	data = data + "## Usage\n\n```bash\n$\n```\n\n"
	data = data + "If you like this project, please watch this and follow me.\n\n"
	data = data + "### Testing\n\n```bash\n$\n```\n\n"
	data = data + "## Contributors\nHere is a list of [Contributors](http://github.com/" + name + "/contributors)\n\n"
	data = data + "### TODO\n\n__I accept pull requests and guarantee a reply back within a day__\n\n"
	data = data + "## License\nMIT/X11\n\n"
	data = data + "## Bug Reports\nReport [here](http://github.com/" + name + "/issues). __Guaranteed reply within a day__.\n\n"

	data = data + "## Contact\n" + config.Get("name") + " (" + config.Get("email") + ")\n\n"
	data = data + "Follow me on [github](https://github.com/users/follow?target=" + config.Get("user") + "), [twitter](http://twitter.com/" + config.Get("twitter") + ")\n"

	if err := ioutil.WriteFile(readme, []byte(data), 0644); err != nil {
		return err
	}

	if err := utils.Git([]string{"commit", "-am", "Updated readme"}...); err != nil {
		return err
	}

	utils.HandleInfo("Appended readme and committed successfully")

	return nil
}
Beispiel #5
0
func (u *UserCommand) Execute(args []string) error {
	if config.Get("token") != "" {
		return &utils.ErrModes{}
	}

	if len(args) == 1 {
		config.Set("user", args[0])
		utils.HandleInfo("You are now in `user` mode")
	} else {
		return &utils.ErrArgument{}
	}

	return nil
}
Beispiel #6
0
func (a *AddCommand) Execute(args []string) error {
	if len(args) == 0 {
		return &utils.ErrArgument{}
	} else if len(args) > 1 {
		return &utils.ErrProxy{}
	}

	var user, repo string

	if a.Private || args[0] == "origin" {
		repo = "git@" + config.Get("site") + ":"
	} else {
		repo = "git://" + config.Get("site") + "/"
	}

	if args[0] == "origin" {
		if config.Get("user") == "" {
			return &utils.ErrUserMode{}
		}

		user = config.Get("user")
	} else {
		user = args[0]
	}

	path := strings.Split(args[0], "/")

	if len(path) == 1 {
		name, err := utils.RepoName()

		if err != nil {
			return err
		}

		repo = repo + user + "/" + name
	} else {
		return &utils.ErrProxy{}
	}

	if err := utils.Git([]string{"remote", "add", args[0], repo}...); err != nil {
		return err
	}

	utils.HandleInfo("Added remote named `" + args[0] + "`")

	return nil
}
Beispiel #7
0
func (p *PushCommand) Execute(args []string) error {
	if len(args) != 2 {
		return &utils.ErrProxy{}
	}

	remotes := strings.Split(args[0], ",")

	if len(remotes) == 1 {
		return &utils.ErrProxy{}
	}

	for _, remote := range remotes {
		if err := utils.Git(append([]string{"push", remote}, args[1:]...)...); err != nil {
			return err
		}

		utils.HandleInfo("Pushed to `" + remote + "` remote")
	}

	return nil
}