change repl and status command to use callback
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
package survey
|
package survey
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/LazyBachelor/LazyPM/internal/commands/issues"
|
"github.com/LazyBachelor/LazyPM/internal/commands/issues"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
@@ -15,11 +17,25 @@ var StatusCmd = &cobra.Command{
|
|||||||
|
|
||||||
func runStatusCmd(cmd *cobra.Command, args []string) error {
|
func runStatusCmd(cmd *cobra.Command, args []string) error {
|
||||||
app := issues.AppFromContext(cmd.Context())
|
app := issues.AppFromContext(cmd.Context())
|
||||||
if app == nil || app.CurrentFeedback == nil {
|
if app == nil {
|
||||||
cmd.Println("No validation status available.")
|
cmd.Println("No validation status available.")
|
||||||
return nil
|
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 == "" {
|
if app.CurrentFeedback.Message == "" {
|
||||||
cmd.Println("No validation status available yet.")
|
cmd.Println("No validation status available yet.")
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ type Check struct {
|
|||||||
type ValidatedInterface interface {
|
type ValidatedInterface interface {
|
||||||
Interface
|
Interface
|
||||||
SetChannels(feedbackChan chan ValidationFeedback, quitChan chan bool)
|
SetChannels(feedbackChan chan ValidationFeedback, quitChan chan bool)
|
||||||
|
SetSubmitChan(submitChan chan<- struct{})
|
||||||
}
|
}
|
||||||
|
|
||||||
type TaskDetails struct {
|
type TaskDetails struct {
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ You can also run shell commands directly. Type 'exit' or 'quit' to leave.`
|
|||||||
type REPL struct {
|
type REPL struct {
|
||||||
feedbackChan chan ValidationFeedback
|
feedbackChan chan ValidationFeedback
|
||||||
quitChan chan bool
|
quitChan chan bool
|
||||||
|
submitChan chan<- struct{}
|
||||||
app *App
|
app *App
|
||||||
|
|
||||||
currentFeedback ValidationFeedback
|
currentFeedback ValidationFeedback
|
||||||
@@ -65,7 +66,11 @@ func (r *REPL) Run(ctx context.Context, config app.Config) error {
|
|||||||
// Store app reference for updating feedback
|
// Store app reference for updating feedback
|
||||||
r.app = app
|
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
|
// Start goroutine to watch for validation feedback and quit signals
|
||||||
if r.feedbackChan != nil && r.quitChan != nil {
|
if r.feedbackChan != nil && r.quitChan != nil {
|
||||||
@@ -151,6 +156,10 @@ func (r *REPL) SetChannels(feedbackChan chan task.ValidationFeedback, quitChan c
|
|||||||
r.quitChan = quitChan
|
r.quitChan = quitChan
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *REPL) SetSubmitChan(submitChan chan<- struct{}) {
|
||||||
|
r.submitChan = submitChan
|
||||||
|
}
|
||||||
|
|
||||||
func (r *REPL) logAction(action string) {
|
func (r *REPL) logAction(action string) {
|
||||||
if r.app != nil {
|
if r.app != nil {
|
||||||
r.app.LogAction(models.EncodeActionEvent(models.ActionEvent{
|
r.app.LogAction(models.EncodeActionEvent(models.ActionEvent{
|
||||||
|
|||||||
Reference in New Issue
Block a user