cmd.go 1012 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package scrpit
  2. import (
  3. "fmt"
  4. "log"
  5. "os"
  6. "os/exec"
  7. )
  8. // func main() {
  9. // exec.Command("git", "clone", "git@gitee.com:Anthony-Dong/template.git")
  10. //}
  11. func Git(str, dir string) {
  12. gitCmd := fmt.Sprintf("git clone %s %s", str, dir)
  13. Cmd(gitCmd)
  14. }
  15. func GitBranch(branch, str, dir string) {
  16. gitCmd := fmt.Sprintf("git clone -b %s %s %s", branch, str, dir)
  17. Cmd(gitCmd)
  18. }
  19. func Run(shell string) {
  20. gitCmd := fmt.Sprintf("%s", shell)
  21. Cmd(gitCmd)
  22. }
  23. func Copy(src, dest string) {
  24. gitCmd := fmt.Sprintf("cp %s %s", src, dest)
  25. Cmd(gitCmd)
  26. }
  27. func Mv(src, dest string) {
  28. gitCmd := fmt.Sprintf("mv %s %s", src, dest)
  29. Cmd(gitCmd)
  30. }
  31. // delete file
  32. func Delete(file string) {
  33. gitCmd := fmt.Sprintf("rm -rf %s", file)
  34. Cmd(gitCmd)
  35. }
  36. func Cmd(cmd string) {
  37. fmt.Println("/bin/bash " + "-c " + cmd)
  38. command := exec.Command("/bin/bash", "-c", cmd)
  39. command.Stdout = os.Stdout
  40. command.Stderr = os.Stdout
  41. err := command.Run()
  42. if err != nil {
  43. log.Fatal(fmt.Sprintf("run %s err", "/bin/bash "+"-c "+cmd))
  44. }
  45. }