/
push.go
54 lines (44 loc) · 1.24 KB
/
push.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package cmd
import (
"os"
"os/exec"
"github.com/spf13/cobra"
)
// pushCmd represents the push command.
var pushCmd = &cobra.Command{
Use: "push",
Short: "Consolidate git add, commit, and push",
Long: `This subcommand reduces contribution friction by staging, commiting, and pushing all of your changes with a single, simple command.
It executes the following commands in sequence:
> git pull
> git add .
> git commit -m "Update"
> git push`,
RunE: func(cmd *cobra.Command, args []string) error {
base := "git"
argsPull := []string{"pull", "origin", "master"}
argsAdd := []string{"add", "."}
argsCommit := []string{"commit", "-m", "Update"}
argsPush := []string{"push", "origin", "master"}
var argsSlice [][]string
argsSlice = append(argsSlice, argsPull)
argsSlice = append(argsSlice, argsAdd)
argsSlice = append(argsSlice, argsCommit)
argsSlice = append(argsSlice, argsPush)
for _, arguments := range argsSlice {
command := exec.Command(base, arguments...)
configureCommand(command)
if err := command.Run(); err != nil {
return err
}
}
return nil
},
}
func init() {
rootCmd.AddCommand(pushCmd)
}
func configureCommand(command *exec.Cmd) {
command.Stdout = os.Stdout
command.Stderr = os.Stderr
}