WIP: 编写 git 和 go 的相关命令函数

main
熊二 3 months ago
parent 9fc1f83003
commit 571f1b95fe
  1. 7
      misc/chdir.go
  2. 28
      misc/git_clone.go
  3. 14
      misc/git_pull.go
  4. 14
      misc/git_reset.go
  5. 14
      misc/go_build.go
  6. 14
      misc/go_mod_tidy.go
  7. 14
      misc/go_test.go

@ -0,0 +1,7 @@
package misc
import "os"
func Chdir(codepath string) error {
return os.Chdir(codepath)
}

@ -0,0 +1,28 @@
package misc
import (
"os"
"os/exec"
)
func GitClone() error {
cmd := exec.Command("git", "clone", "https://github.com/HupeHup/hupe.git", "gittemp")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
if err := cmd.Run(); err != nil {
return err
}
cmd = exec.Command("mv", "gittemp/.git", ".")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return err
}
cmd = exec.Command("rm", "-rf", "gittemp")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}

@ -0,0 +1,14 @@
package misc
import (
"os"
"os/exec"
)
func GitPull() error {
cmd := exec.Command("git", "pull")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
return cmd.Run()
}

@ -0,0 +1,14 @@
package misc
import (
"os"
"os/exec"
)
func GitRest() error {
cmd := exec.Command("git", "reset", "--hard", "origin/main")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
return cmd.Run()
}

@ -0,0 +1,14 @@
package misc
import (
"os"
"os/exec"
)
func GoBuild() error {
cmd := exec.Command("go", "build", "-ldflags", "\"-w-s\"", "-trimpath", "path/to/main.go", "-o", "main")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
return cmd.Run()
}

@ -0,0 +1,14 @@
package misc
import (
"os"
"os/exec"
)
func GoModTidy() error {
cmd := exec.Command("go", "mod", "tidy")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
return cmd.Run()
}

@ -0,0 +1,14 @@
package misc
import (
"os"
"os/exec"
)
func GoTest() error {
cmd := exec.Command("go", "test", "-v")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
return cmd.Run()
}
Loading…
Cancel
Save