Skip to content

Commit 1fd7957

Browse files
authored
cli: align built-in and plugin rule commit behavior (#85)
Aligning the behavior between built-in rules and rules run via plugins. Will run all plugins before committing and if warnings occur, commit will get blocked.
1 parent 3834a7a commit 1fd7957

File tree

1 file changed

+26
-31
lines changed

1 file changed

+26
-31
lines changed

cmd/protolock/main.go

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -84,56 +84,51 @@ func main() {
8484
}
8585

8686
case "commit":
87-
r, err := protolock.Commit(*cfg)
88-
if err != nil {
89-
fmt.Println(err)
90-
os.Exit(1)
91-
}
92-
9387
// if force option is false (default), then disallow commit if
9488
// there are any warnings encountered by runing a status check.
9589
if !*force {
96-
report, err := protolock.Status(*cfg)
97-
if err != nil {
98-
handleReport(report, err)
99-
}
100-
101-
if len(report.Warnings) > 0 {
102-
os.Exit(1)
103-
}
90+
status(cfg)
10491
}
10592

106-
err = saveToLockFile(*cfg, r)
93+
r, err := protolock.Commit(*cfg)
10794
if err != nil {
10895
fmt.Println(err)
10996
os.Exit(1)
11097
}
11198

112-
case "status":
113-
report, err := protolock.Status(*cfg)
114-
if err != protolock.ErrWarningsFound && err != nil {
115-
fmt.Println("[protolock]:", err)
99+
err = saveToLockFile(*cfg, r)
100+
if err != nil {
101+
fmt.Println(err)
116102
os.Exit(1)
117103
}
118104

119-
// if plugins are provided, attempt to execute each as a exeutable
120-
// located in the user's OS executable path as reported by stdlib's
121-
// exec.LookPath func
122-
if *plugins != "" {
123-
report, err = runPlugins(*plugins, report)
124-
if err != nil {
125-
fmt.Println(err)
126-
os.Exit(1)
127-
}
128-
}
129-
130-
handleReport(report, err)
105+
case "status":
106+
status(cfg)
131107

132108
default:
133109
os.Exit(0)
134110
}
135111
}
136112

113+
func status(cfg *protolock.Config) {
114+
report, err := protolock.Status(*cfg)
115+
if err != protolock.ErrWarningsFound && err != nil {
116+
fmt.Println("[protolock]:", err)
117+
os.Exit(1)
118+
}
119+
// if plugins are provided, attempt to execute each as a executable
120+
// located in the user's OS executable path as reported by stdlib's
121+
// exec.LookPath func
122+
if *plugins != "" {
123+
report, err = runPlugins(*plugins, report)
124+
if err != nil {
125+
fmt.Println(err)
126+
os.Exit(1)
127+
}
128+
}
129+
handleReport(report, err)
130+
}
131+
137132
func handleReport(report *protolock.Report, err error) {
138133
if len(report.Warnings) > 0 {
139134

0 commit comments

Comments
 (0)