Skip to content

Commit 05efbd9

Browse files
committed
refactor: split functions from statusAction
1 parent dae3f99 commit 05efbd9

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

app/cli/commands/status.go

+18-10
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,8 @@ func statusAction(c *cli.Context) error {
3939
if err != nil {
4040
return err
4141
}
42-
var color cliutil.StatusColor = &cliutil.StatusColorEnabled{}
43-
if c.Bool("no-ansi") || !terminal.IsTerminal(int(os.Stdout.Fd())) {
44-
color = &cliutil.StatusColorDisabled{}
45-
}
46-
printStatus := printLongStatus
47-
if c.Bool("no-status") {
48-
printStatus = printOnlyPaths
49-
} else if c.Bool("short") {
50-
printStatus = printShortStatus
51-
}
42+
color := getStatusColor(c)
43+
printStatus := getPrintStatus(c)
5244
for _, repoStatus := range repoStatuses {
5345
if !c.Bool("all") && repoStatus.GetGitStatus() == domain.UpToDate {
5446
continue
@@ -58,6 +50,22 @@ func statusAction(c *cli.Context) error {
5850
return nil
5951
}
6052

53+
func getPrintStatus(c *cli.Context) func(domain.RepoStatus, cliutil.StatusColor) {
54+
if c.Bool("no-status") {
55+
return printOnlyPaths
56+
} else if c.Bool("short") {
57+
return printShortStatus
58+
}
59+
return printLongStatus
60+
}
61+
62+
func getStatusColor(c *cli.Context) cliutil.StatusColor {
63+
if c.Bool("no-ansi") || !terminal.IsTerminal(int(os.Stdout.Fd())) {
64+
return &cliutil.StatusColorDisabled{}
65+
}
66+
return &cliutil.StatusColorEnabled{}
67+
}
68+
6169
func printLongStatus(repoStatus domain.RepoStatus, color cliutil.StatusColor) {
6270
fmt.Printf("%s: %s\n", gitStatusToLongString(repoStatus.GetGitStatus(), color), repoStatus.GetPath())
6371
}

0 commit comments

Comments
 (0)