Skip to content

Commit f590ee7

Browse files
Return error from Start function (#13)
Returning an error from `Start` function will allow us to report the error and exit with a proper exit code.
1 parent e6cebd4 commit f590ee7

File tree

2 files changed

+15
-20
lines changed

2 files changed

+15
-20
lines changed

cmd/git-pair/main.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
)
1212

1313
func main() {
14-
cli.VersionPrinter = func(cCtx *cli.Context) {
14+
cli.VersionPrinter = func(*cli.Context) {
1515
printVersion()
1616
}
1717

@@ -31,8 +31,7 @@ func main() {
3131
Aliases: []string{"s"},
3232
Usage: "Start pairing mode",
3333
Action: func(*cli.Context) error {
34-
Start()
35-
return nil
34+
return Start()
3635
},
3736
},
3837
{

cmd/git-pair/start.go

+13-17
Original file line numberDiff line numberDiff line change
@@ -9,47 +9,43 @@ import (
99
"github.com/inverse/git-pair/internal/util"
1010
)
1111

12-
func Start() {
12+
func Start() error {
1313
localContributors, err := contributors.GetLocalContributors()
1414
if err != nil {
15-
fmt.Printf("Failed to load local contributors: %s\n", err)
16-
return
15+
return fmt.Errorf("Failed to load local contributors: %w", err)
1716
}
1817

1918
repoContributors, err := git.GetRepoContributors()
2019
if err != nil {
21-
fmt.Printf("Failed to load repo contributors: %s\n", err)
22-
return
20+
return fmt.Errorf("Failed to load repo contributors: %w", err)
2321
}
2422

2523
allContributors := util.UniqueStrings(append(localContributors, repoContributors...))
2624
if len(allContributors) == 0 {
27-
fmt.Println("No contributors found")
28-
return
25+
fmt.Println("⚠️ No contributors found")
26+
return nil
2927
}
3028

31-
selectedContributors := []string{}
29+
var selectedContributors []string
30+
3231
prompt := &survey.MultiSelect{
3332
Message: "Who's pairing:",
3433
Options: allContributors,
3534
}
3635

37-
err = survey.AskOne(prompt, &selectedContributors)
38-
if err != nil {
39-
fmt.Println(err)
40-
return
36+
if err := survey.AskOne(prompt, &selectedContributors); err != nil {
37+
return err
4138
}
4239

4340
if len(selectedContributors) == 0 {
4441
fmt.Println("You must select at least one contributor")
45-
return
42+
return nil
4643
}
4744

48-
err = git.EnablePairingMode(selectedContributors)
49-
if err != nil {
50-
fmt.Println(err)
51-
return
45+
if err := git.EnablePairingMode(selectedContributors); err != nil {
46+
return err
5247
}
5348

5449
fmt.Println("🚀 Pairing mode started")
50+
return nil
5551
}

0 commit comments

Comments
 (0)