Skip to content

Commit

Permalink
[#200] Refactor display of VCS info to show meaningful info only
Browse files Browse the repository at this point in the history
  • Loading branch information
mengdaming committed Feb 1, 2023
1 parent 574ea9e commit 138ba9c
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 6 deletions.
19 changes: 14 additions & 5 deletions src/cli/terminal_ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,16 +242,25 @@ func (term *TerminalUI) ShowRunningMode(mode runmode.RunMode) {
// ShowSessionInfo shows main information related to the current TCR session
func (term *TerminalUI) ShowSessionInfo() {
info := term.tcr.GetSessionInfo()

term.ReportTitle(false, "Base Directory: ", info.BaseDir)
term.ReportInfo(false, "Work Directory: ", info.WorkDir)
term.ReportInfo(false, "Language=", info.LanguageName, ", Toolchain=", info.ToolchainName)
term.reportVCSInfo(info)
}

autoPush := "disabled"
if info.GitAutoPush {
autoPush = "enabled"
func (term *TerminalUI) reportVCSInfo(info engine.SessionInfo) {
switch info.VCSName {
case git.Name:
autoPush := "disabled"
if info.GitAutoPush {
autoPush = "enabled"
}
term.ReportInfo(false, "Running on ", info.VCSSessionSummary, " with auto-push ", autoPush)
case p4.Name:
term.ReportInfo(false, "Running with ", info.VCSSessionSummary)
default:
term.ReportWarning(false, "VCS \"", info.VCSName, "\" is unknown")
}
term.ReportInfo(false, "Running on ", info.VCSSessionSummary, " with auto-push ", autoPush)
}

// Confirm asks the user for confirmation
Expand Down
45 changes: 44 additions & 1 deletion src/cli/terminal_ui_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ func Test_show_session_info(t *testing.T) {
expected := asCyanTraceWithSeparatorLine("Base Directory: fake") +
asCyanTrace("Work Directory: fake") +
asCyanTrace("Language=fake, Toolchain=fake") +
asCyanTrace("Running on VCS session \"fake\" with auto-push disabled")
asYellowTrace("VCS \"fake\" is unknown")

assert.Equal(t, expected, capturer.CaptureStdout(func() {
term, _, _ := terminalSetup(*params.AParamSet())
Expand All @@ -488,6 +488,49 @@ func Test_show_session_info(t *testing.T) {
}))
}

func Test_report_vcs_info(t *testing.T) {
tests := []struct {
desc string
info engine.SessionInfo
expected string
}{
{
"VCS not set",
engine.SessionInfo{VCSName: "", VCSSessionSummary: "", GitAutoPush: false},
asYellowTrace("VCS \"\" is unknown"),
},
{
"VCS unknown",
engine.SessionInfo{VCSName: "dummy", VCSSessionSummary: "", GitAutoPush: false},
asYellowTrace("VCS \"dummy\" is unknown"),
},
{
"git with auto-push on",
engine.SessionInfo{VCSName: "git", VCSSessionSummary: "git branch \"my-branch\"", GitAutoPush: true},
asCyanTrace("Running on git branch \"my-branch\" with auto-push enabled"),
},
{
"git with auto-push off",
engine.SessionInfo{VCSName: "git", VCSSessionSummary: "git branch \"my-branch\"", GitAutoPush: false},
asCyanTrace("Running on git branch \"my-branch\" with auto-push disabled"),
},
{
"p4",
engine.SessionInfo{VCSName: "p4", VCSSessionSummary: "p4 client \"my-client\"", GitAutoPush: false},
asCyanTrace("Running with p4 client \"my-client\""),
},
}
for _, test := range tests {
t.Run(test.desc, func(t *testing.T) {
assert.Equal(t, test.expected, capturer.CaptureStdout(func() {
term, _, _ := terminalSetup(*params.AParamSet())
term.reportVCSInfo(test.info)
terminalTeardown(*term)
}))
})
}
}

func Test_main_menu(t *testing.T) {
slowTestTag(t)
testFlags := []struct {
Expand Down

0 comments on commit 138ba9c

Please sign in to comment.