Example #1
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
}
Example #2
0
File: add.go Project: pksunkara/hub
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
}
Example #3
0
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)
	}
}
Example #4
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
}
Example #5
0
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}...)
}