-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
staging.go
91 lines (85 loc) · 2.38 KB
/
staging.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package gotcmd
import (
"github.com/gotvc/got/pkg/gotrepo"
"github.com/gotvc/got/pkg/metrics"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
func newAddCmd(open func() (*gotrepo.Repo, error)) *cobra.Command {
var repo *gotrepo.Repo
return &cobra.Command{
Use: "add",
Short: "adds paths to the staging area",
PreRunE: loadRepo(&repo, open),
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return errors.Errorf("path argument required")
}
r := metrics.NewTTYRenderer(collector, cmd.OutOrStdout())
defer r.Close()
return repo.Add(ctx, args...)
},
}
}
func newRmCmd(open func() (*gotrepo.Repo, error)) *cobra.Command {
var repo *gotrepo.Repo
return &cobra.Command{
Use: "rm",
Short: "stages paths for deletion",
PreRunE: loadRepo(&repo, open),
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return errors.Errorf("path argument required")
}
r := metrics.NewTTYRenderer(collector, cmd.OutOrStdout())
defer r.Close()
return repo.Rm(ctx, args...)
},
}
}
func newPutCmd(open func() (*gotrepo.Repo, error)) *cobra.Command {
var repo *gotrepo.Repo
return &cobra.Command{
Use: "put",
Short: "stages paths for replacement",
PreRunE: loadRepo(&repo, open),
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return errors.Errorf("path argument required")
}
r := metrics.NewTTYRenderer(collector, cmd.OutOrStdout())
defer r.Close()
return repo.Put(ctx, args...)
},
}
}
func newDiscardCmd(open func() (*gotrepo.Repo, error)) *cobra.Command {
var repo *gotrepo.Repo
return &cobra.Command{
Use: "discard",
Short: "discards any changes staged for a path",
PreRunE: loadRepo(&repo, open),
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return errors.Errorf("path argument required")
}
return repo.Discard(ctx, args...)
},
}
}
func newClearCmd(open func() (*gotrepo.Repo, error)) *cobra.Command {
var repo *gotrepo.Repo
return &cobra.Command{
Use: "clear",
Short: "clears the staging area",
PreRunE: loadRepo(&repo, open),
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
return repo.Clear(ctx)
},
}
}