用 go 实现的 git 快速提交代码的小工具。
package main
/*
这是一个用 go 实现的 git 快速提交代码的小工具
将该代码编译成可执行文件,然后加入到系统环境变量中去
然后就可以直接使用类似:
g '这是一个测试'
快速的提交代码了
*/
import (
    "fmt"
    "os"
    "os/exec"
    "strings"
)
func main() {
    argLen := len(os.Args)
    file := "."
    if argLen < 2 {
        fmt.Println("必须输入提交说明!")
        os.Exit(0)
    } else if argLen > 2 {
        file = ""
        for key, value := range os.Args {
            if key < 2 {
                continue
            }
            file += value + " "
        }
        file = strings.TrimRight(file, " ")
    }
    execCommmand("git", "add", file)
    execCommmand("git", "commit", "-m", os.Args[1])
    execCommmand("git", "push")
}
func execCommmand(command string, arg ...string) {
    cmd := exec.Command(command, arg...)
    out, _ := cmd.CombinedOutput()
    cmd.Run()
    fmt.Print(string(out))
    if err != nil {
        log.Fatalf("cmd.Run() failed with %s\n", err)
    }
}