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 }
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 }
func main() { // Initiate parser parser := flags.NewParser(&Options, flags.HelpFlag|flags.PassDoubleDash) // Set usage string parser.Usage = "[-v]" // Load config for application config.ItExists() // Check for verbose mode utils.Verbose = &Options.Verbose // Parse the arguments args, err := parser.Parse() if err != nil { if config.Get("combine") == "1" { err := utils.Git(os.Args[1:]...) if err != nil { os.Exit(1) } else { os.Exit(0) } } if _, ok := err.(*exec.ExitError); ok { utils.HandleError(errors.New("Running git command is unsuccessful")) os.Exit(1) } if _, ok := err.(*flags.Error); ok { typ := err.(*flags.Error).Type if typ == flags.ErrUnknownCommand { err = errors.New("unknown command '" + args[0] + "'") } if typ == flags.ErrCommandRequired || typ == flags.ErrHelp { err = nil } } utils.HandleError(err) terminal.Stderr.Nl() parser.WriteHelp(os.Stderr) } }
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 }
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 }
func (c *CloneCommand) Execute(args []string) error { if len(args) == 0 { return &utils.ErrArgument{} } if strings.Index(args[0], ":") != -1 { return &utils.ErrProxy{} } var repo string if c.Private { repo = "git@" + config.Get("site") + ":" } else { repo = "git://" + config.Get("site") + "/" } path := strings.Split(args[0], "/") if len(path) == 1 { if config.Get("user") == "" { return &utils.ErrUserMode{} } if config.Get("token") != "" { repo = "git@" + config.Get("site") + ":" } repo = repo + config.Get("user") + "/" + path[0] } else if len(path) == 2 { repo = repo + args[0] } else { return &utils.ErrProxy{} } return utils.Git([]string{"clone", "--progress", repo}...) }