用 go 实现的 git 快速提交代码的小工具

 
更多

用 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, err := cmd.CombinedOutput()
	cmd.Run()
	fmt.Print(string(out))
	if err != nil {
		log.Fatalf("cmd.Run() failed with %s\n", err)
	}
}
打赏

本文固定链接: https://www.cxy163.net/archives/3005 | 绝缘体

该日志由 绝缘体.. 于 2024年01月30日 发表在 未分类 分类下, 你可以发表评论,并在保留原文地址及作者的情况下引用到你的网站或博客。
原创文章转载请注明: 用 go 实现的 git 快速提交代码的小工具 | 绝缘体
关键字: , , , ,

用 go 实现的 git 快速提交代码的小工具:等您坐沙发呢!

发表评论


快捷键:Ctrl+Enter