Skip to content

Commit 88c26c4

Browse files
author
echoVic
committed
fix: keep Web UI running after wrapped command exits
- Web UI now stays running after the command finishes - User can view results and press Ctrl+C to exit - Bump version to 0.0.11
1 parent 7e1eb69 commit 88c26c4

6 files changed

Lines changed: 17 additions & 4 deletions

File tree

cmd/bar/update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const (
1616
repoOwner = "echoVic"
1717
repoName = "blade-agent-runtime"
1818
installURL = "https://echovic.github.io/blade-agent-runtime/install.sh"
19-
currentVersion = "0.0.10"
19+
currentVersion = "0.0.11"
2020
)
2121

2222
func updateCmd() *cobra.Command {

cmd/bar/wrap.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
func wrapCmd() *cobra.Command {
2222
var noUI bool
2323
var uiPort int
24+
var uiServer *web.Server
2425

2526
cmd := &cobra.Command{
2627
Use: "wrap -- <command> [args...]",
@@ -45,13 +46,12 @@ When the command exits, BAR records a step with the diff of all changes.`,
4546
// Start UI by default (unless --no-ui is set)
4647
if !noUI {
4748
addr := fmt.Sprintf(":%d", uiPort)
48-
server := web.NewServer(addr, app.TaskManager, app.BarDir)
49+
uiServer = web.NewServer(addr, app.TaskManager, app.BarDir)
4950
go func() {
50-
if err := server.Start(); err != nil {
51+
if err := uiServer.Start(); err != nil {
5152
app.Logger.Error("Web UI failed: %v", err)
5253
}
5354
}()
54-
defer server.Stop()
5555

5656
// Wait a bit for server to start
5757
time.Sleep(500 * time.Millisecond)
@@ -165,6 +165,19 @@ When the command exits, BAR records a step with the diff of all changes.`,
165165
app.Logger.Info("Step %s recorded", stepID)
166166
app.Logger.Info("Files changed: %d (+%d, -%d)", diffResult.Files, diffResult.Additions, diffResult.Deletions)
167167

168+
// If UI is running, wait for user to close it
169+
if uiServer != nil {
170+
app.Logger.Info("")
171+
app.Logger.Info("Web UI still running. Press Ctrl+C to exit.")
172+
173+
waitChan := make(chan os.Signal, 1)
174+
signal.Notify(waitChan, syscall.SIGINT, syscall.SIGTERM)
175+
<-waitChan
176+
177+
uiServer.Stop()
178+
app.Logger.Info("Web UI stopped.")
179+
}
180+
168181
return nil
169182
},
170183
}

dist/bar_darwin_amd64.tar.gz

-171 Bytes
Binary file not shown.

dist/bar_darwin_arm64.tar.gz

-93 Bytes
Binary file not shown.

dist/bar_linux_amd64.tar.gz

338 Bytes
Binary file not shown.

dist/bar_linux_arm64.tar.gz

-243 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)