Skip to content

Commit e3d7cb1

Browse files
committed
[#694] Add toolchain command abort shortcut in CLI
- Shortcut: 'A' (abort)
1 parent 0799138 commit e3d7cb1

File tree

6 files changed

+54
-2
lines changed

6 files changed

+54
-2
lines changed

src/cli/terminal_ui.go

+25
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ const (
6262
enterNavigatorRoleMenuHelper = "Navigator role"
6363
openBrowserMenuHelper = "Open in browser"
6464
gitAutoPushMenuHelper = "Turn on/off git auto-push"
65+
abortCommandMenuHelper = "Abort current command"
6566
quitMenuHelper = "Quit"
6667
optionsMenuHelper = "List available options"
6768
timerStatusMenuHelper = "Timer status"
@@ -290,6 +291,10 @@ func (term *TerminalUI) vcsPush() {
290291
term.tcr.VCSPush()
291292
}
292293

294+
func (term *TerminalUI) abortCommand() {
295+
term.tcr.AbortCommand()
296+
}
297+
293298
func (term *TerminalUI) whatShallWeDo() {
294299
if term.params.Mode.IsMultiRole() {
295300
term.listMenuOptions(term.mobMenu, "What shall we do?")
@@ -444,6 +449,9 @@ func (term *TerminalUI) initSoloMenu() *menu {
444449
newMenuOption('Y', syncMenuHelper,
445450
term.p4MenuEnabler(),
446451
term.vcsPullMenuAction(), false),
452+
newMenuOption('A', abortCommandMenuHelper,
453+
term.abortCommandEnabler(),
454+
term.abortCommandMenuAction(), false),
447455
newMenuOption('Q', quitTCRMenuHelper,
448456
term.quitRoleMenuEnabler(role.Driver{}),
449457
term.quitRoleMenuAction(), true),
@@ -480,6 +488,9 @@ func (term *TerminalUI) initMobMenu() *menu {
480488
newMenuOption('Y', syncMenuHelper,
481489
term.p4MenuEnabler(),
482490
term.vcsPullMenuAction(), false),
491+
newMenuOption('A', abortCommandMenuHelper,
492+
term.abortCommandEnabler(),
493+
term.abortCommandMenuAction(), false),
483494
newMenuOption('Q', quitMenuHelper,
484495
term.quitRoleMenuEnabler(nil),
485496
term.quitMenuAction(), true),
@@ -554,6 +565,12 @@ func (term *TerminalUI) vcsPushMenuAction() menuAction {
554565
}
555566
}
556567

568+
func (term *TerminalUI) abortCommandMenuAction() menuAction {
569+
return func() {
570+
term.abortCommand()
571+
}
572+
}
573+
557574
func (term *TerminalUI) optionsMenuAction(m *menu) menuAction {
558575
return func() {
559576
term.listMenuOptions(m, "Available Options:")
@@ -579,6 +596,14 @@ func (term *TerminalUI) timerStatusMenuAction() menuAction {
579596
}
580597
}
581598

599+
func (term *TerminalUI) abortCommandEnabler() menuEnabler {
600+
return func() bool {
601+
// For now we only enable this shortcut when in driver role.
602+
// We may need to enable it more widely when we extend abort to VCS commands as well
603+
return term.tcr.GetCurrentRole() == role.Driver{}
604+
}
605+
}
606+
582607
func (term *TerminalUI) quitRoleMenuEnabler(r role.Role) menuEnabler {
583608
return func() bool {
584609
return term.tcr.GetCurrentRole() == r

src/cli/terminal_ui_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ func Test_list_role_menu_options(t *testing.T) {
219219
asCyanTrace("\tP "+menuArrow+" "+gitAutoPushMenuHelper) +
220220
asCyanTrace("\tL "+menuArrow+" "+pullMenuHelper) +
221221
asCyanTrace("\tS "+menuArrow+" "+pushMenuHelper) +
222+
asCyanTrace("\tA "+menuArrow+" "+abortCommandMenuHelper) +
222223
asCyanTrace("\tQ "+menuArrow+" "+quitTCRMenuHelper) +
223224
asCyanTrace("\t? "+menuArrow+" "+optionsMenuHelper),
224225
},
@@ -231,6 +232,7 @@ func Test_list_role_menu_options(t *testing.T) {
231232
asCyanTrace("\tP "+menuArrow+" "+gitAutoPushMenuHelper) +
232233
asCyanTrace("\tL "+menuArrow+" "+pullMenuHelper) +
233234
asCyanTrace("\tS "+menuArrow+" "+pushMenuHelper) +
235+
asCyanTrace("\tA "+menuArrow+" "+abortCommandMenuHelper) +
234236
asCyanTrace("\tQ "+menuArrow+" "+quitDriverRoleMenuHelper) +
235237
asCyanTrace("\t? "+menuArrow+" "+optionsMenuHelper),
236238
},

src/engine/tcr.go

+7
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ type (
6262
RunAsNavigator()
6363
Stop()
6464
RunTCRCycle()
65+
AbortCommand()
6566
GetSessionInfo() SessionInfo
6667
GetMobTimerStatus() timer.CurrentState
6768
SetRunMode(m runmode.RunMode)
@@ -521,6 +522,12 @@ func (tcr *TCREngine) RunTCRCycle() {
521522
}
522523
}
523524

525+
// AbortCommand triggers interruption of an ongoing TCR cycle operation
526+
func (tcr *TCREngine) AbortCommand() {
527+
//report.PostWarning("Aborting current command")
528+
tcr.toolchain.AbortExecution()
529+
}
530+
524531
func (tcr *TCREngine) createTCREvent(testResult toolchain.TestCommandResult) (event events.TCREvent) {
525532
diffs, err := tcr.vcs.Diff()
526533
if err != nil {

src/toolchain/command.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2021 Murex
2+
Copyright (c) 2024 Murex
33
44
Permission is hereby granted, free of charge, to any person obtaining a copy
55
of this software and associated documentation files (the "Software"), to deal

src/toolchain/command_runner.go

+12
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,15 @@ func (*CommandRunner) reportCommandTrace(readCloser io.ReadCloser) {
121121
}
122122
}()
123123
}
124+
125+
// AbortRunningCommand triggers aborting of any command that is currently running
126+
func (r *CommandRunner) AbortRunningCommand() {
127+
if r.command == nil || r.command.Process == nil {
128+
report.PostWarning("There is no command running at this time")
129+
return
130+
}
131+
report.PostWarning("Aborting command: \"", r.command.String(), "\"")
132+
_ = r.command.Process.Kill()
133+
// Calling Kill() may be a bit too brutal (may leave children process alive)
134+
//_ = r.command.Process.Signal(os.Kill)
135+
}

src/toolchain/toolchain.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2023 Murex
2+
Copyright (c) 2024 Murex
33
44
Permission is hereby granted, free of charge, to any person obtaining a copy
55
of this software and associated documentation files (the "Software"), to deal
@@ -70,6 +70,7 @@ type (
7070
checkTestCommand() error
7171
runsOnPlatform(osName OsName, archName ArchName) bool
7272
CheckCommandAccess(cmdPath string) (string, error)
73+
AbortExecution()
7374
}
7475
)
7576

@@ -162,6 +163,11 @@ func (tchn Toolchain) RunTests() TestCommandResult {
162163
return TestCommandResult{result, testStats}
163164
}
164165

166+
// AbortExecution asks the toolchain to abort any command currently executing
167+
func (Toolchain) AbortExecution() {
168+
commandRunner.AbortRunningCommand()
169+
}
170+
165171
// BuildCommandPath returns the build command path for this toolchain
166172
func (tchn Toolchain) BuildCommandPath() string {
167173
return findCompatibleCommand(tchn.buildCommands).Path

0 commit comments

Comments
 (0)