change repl and status command to use callback

This commit is contained in:
Robin Olsen
2026-03-04 22:44:01 +01:00
parent 3d183d7fcd
commit 4842d30aab
3 changed files with 28 additions and 2 deletions

View File

@@ -1,6 +1,8 @@
package survey
import (
"time"
"github.com/LazyBachelor/LazyPM/internal/commands/issues"
"github.com/spf13/cobra"
)
@@ -15,11 +17,25 @@ var StatusCmd = &cobra.Command{
func runStatusCmd(cmd *cobra.Command, args []string) error {
app := issues.AppFromContext(cmd.Context())
if app == nil || app.CurrentFeedback == nil {
if app == nil {
cmd.Println("No validation status available.")
return nil
}
if app.SubmitChan != nil {
select {
case app.SubmitChan <- struct{}{}:
default:
}
}
time.Sleep(100 * time.Millisecond)
if app.CurrentFeedback == nil {
cmd.Println("No validation status available yet.")
return nil
}
if app.CurrentFeedback.Message == "" {
cmd.Println("No validation status available yet.")
return nil

View File

@@ -28,6 +28,7 @@ type Check struct {
type ValidatedInterface interface {
Interface
SetChannels(feedbackChan chan ValidationFeedback, quitChan chan bool)
SetSubmitChan(submitChan chan<- struct{})
}
type TaskDetails struct {

View File

@@ -31,6 +31,7 @@ You can also run shell commands directly. Type 'exit' or 'quit' to leave.`
type REPL struct {
feedbackChan chan ValidationFeedback
quitChan chan bool
submitChan chan<- struct{}
app *App
currentFeedback ValidationFeedback
@@ -65,7 +66,11 @@ func (r *REPL) Run(ctx context.Context, config app.Config) error {
// Store app reference for updating feedback
r.app = app
fmt.Println(style.TitleStyle.Render(ReplTitle)) // Print REPL title.
if r.submitChan != nil {
r.app.SubmitChan = r.submitChan
}
fmt.Println(style.TitleStyle.Render(ReplTitle))
// Start goroutine to watch for validation feedback and quit signals
if r.feedbackChan != nil && r.quitChan != nil {
@@ -151,6 +156,10 @@ func (r *REPL) SetChannels(feedbackChan chan task.ValidationFeedback, quitChan c
r.quitChan = quitChan
}
func (r *REPL) SetSubmitChan(submitChan chan<- struct{}) {
r.submitChan = submitChan
}
func (r *REPL) logAction(action string) {
if r.app != nil {
r.app.LogAction(models.EncodeActionEvent(models.ActionEvent{