Skip to content

Commit

Permalink
refactor: split functions from statusAction
Browse files Browse the repository at this point in the history
  • Loading branch information
suin committed Nov 4, 2018
1 parent dae3f99 commit 05efbd9
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions app/cli/commands/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,8 @@ func statusAction(c *cli.Context) error {
if err != nil {
return err
}
var color cliutil.StatusColor = &cliutil.StatusColorEnabled{}
if c.Bool("no-ansi") || !terminal.IsTerminal(int(os.Stdout.Fd())) {
color = &cliutil.StatusColorDisabled{}
}
printStatus := printLongStatus
if c.Bool("no-status") {
printStatus = printOnlyPaths
} else if c.Bool("short") {
printStatus = printShortStatus
}
color := getStatusColor(c)
printStatus := getPrintStatus(c)
for _, repoStatus := range repoStatuses {
if !c.Bool("all") && repoStatus.GetGitStatus() == domain.UpToDate {
continue
Expand All @@ -58,6 +50,22 @@ func statusAction(c *cli.Context) error {
return nil
}

func getPrintStatus(c *cli.Context) func(domain.RepoStatus, cliutil.StatusColor) {
if c.Bool("no-status") {
return printOnlyPaths
} else if c.Bool("short") {
return printShortStatus
}
return printLongStatus
}

func getStatusColor(c *cli.Context) cliutil.StatusColor {
if c.Bool("no-ansi") || !terminal.IsTerminal(int(os.Stdout.Fd())) {
return &cliutil.StatusColorDisabled{}
}
return &cliutil.StatusColorEnabled{}
}

func printLongStatus(repoStatus domain.RepoStatus, color cliutil.StatusColor) {
fmt.Printf("%s: %s\n", gitStatusToLongString(repoStatus.GetGitStatus(), color), repoStatus.GetPath())
}
Expand Down

0 comments on commit 05efbd9

Please sign in to comment.