add status command for getting task status
add feedback to repl
This commit is contained in:
46
pkg/cli/commands/status.go
Normal file
46
pkg/cli/commands/status.go
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
package commands
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/LazyBachelor/LazyPM/pkg/task"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
// replInstance holds a reference to the REPL for accessing validation feedback
|
||||||
|
var replInstance interface {
|
||||||
|
GetCurrentFeedback() task.ValidationFeedback
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetRepl sets the REPL instance for use by commands
|
||||||
|
func SetRepl(repl interface {
|
||||||
|
GetCurrentFeedback() task.ValidationFeedback
|
||||||
|
}) {
|
||||||
|
replInstance = repl
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusCmd displays the current task validation status
|
||||||
|
var StatusCmd = &cobra.Command{
|
||||||
|
Use: "status",
|
||||||
|
Short: "Check task validation status",
|
||||||
|
Long: "Displays the current task validation status and feedback.",
|
||||||
|
RunE: runStatusCmd,
|
||||||
|
}
|
||||||
|
|
||||||
|
func runStatusCmd(cmd *cobra.Command, args []string) error {
|
||||||
|
if replInstance == nil {
|
||||||
|
cmd.Println("No task validation available")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
feedback := replInstance.GetCurrentFeedback()
|
||||||
|
if feedback.Message == "" {
|
||||||
|
cmd.Println("No validation status available yet.")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.Print(feedback.Message)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(StatusCmd)
|
||||||
|
}
|
||||||
@@ -11,18 +11,26 @@ import (
|
|||||||
"github.com/LazyBachelor/LazyPM/pkg/cli"
|
"github.com/LazyBachelor/LazyPM/pkg/cli"
|
||||||
"github.com/LazyBachelor/LazyPM/pkg/cli/commands"
|
"github.com/LazyBachelor/LazyPM/pkg/cli/commands"
|
||||||
"github.com/LazyBachelor/LazyPM/pkg/cli/styles"
|
"github.com/LazyBachelor/LazyPM/pkg/cli/styles"
|
||||||
|
"github.com/LazyBachelor/LazyPM/pkg/task"
|
||||||
"github.com/c-bata/go-prompt"
|
"github.com/c-bata/go-prompt"
|
||||||
"golang.org/x/term"
|
"golang.org/x/term"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ReplHelp = `Type 'pm help' for available PM commands.
|
ReplHelp = `Type 'pm help' for available PM commands.
|
||||||
|
Type 'pm status' to check task progress.
|
||||||
You can also run shell commands directly. Type 'exit' or 'quit' to leave.`
|
You can also run shell commands directly. Type 'exit' or 'quit' to leave.`
|
||||||
|
|
||||||
ReplTitle = "Welcome to Project Management CLI! " + ReplHelp
|
ReplTitle = "Welcome to Project Management CLI! " + ReplHelp
|
||||||
)
|
)
|
||||||
|
|
||||||
type REPL struct{}
|
type REPL struct {
|
||||||
|
feedbackChan chan task.ValidationFeedback
|
||||||
|
quitChan chan bool
|
||||||
|
|
||||||
|
currentFeedback task.ValidationFeedback
|
||||||
|
exitRequested bool
|
||||||
|
}
|
||||||
|
|
||||||
func NewRepl() *REPL {
|
func NewRepl() *REPL {
|
||||||
return &REPL{}
|
return &REPL{}
|
||||||
@@ -49,14 +57,27 @@ func (r *REPL) Run(ctx context.Context, config cli.CLIConfig) error {
|
|||||||
// Make sure to set services, to ensure they are available.
|
// Make sure to set services, to ensure they are available.
|
||||||
commands.SetServices(svc)
|
commands.SetServices(svc)
|
||||||
|
|
||||||
|
// Set the REPL instance so status command can access it
|
||||||
|
commands.SetRepl(r)
|
||||||
|
|
||||||
fmt.Println(styles.TitleStyle.Render(ReplTitle)) // Print REPL title.
|
fmt.Println(styles.TitleStyle.Render(ReplTitle)) // Print REPL title.
|
||||||
|
|
||||||
|
// Start goroutine to watch for validation feedback and quit signals
|
||||||
|
if r.feedbackChan != nil && r.quitChan != nil {
|
||||||
|
go r.watchValidation()
|
||||||
|
}
|
||||||
|
|
||||||
// history keeps track of command history.
|
// history keeps track of command history.
|
||||||
// This enables navigating through previous commands.
|
// This enables navigating through previous commands.
|
||||||
var history []string
|
var history []string
|
||||||
|
|
||||||
// Start the REPL loop, which continues until the user types "exit" or "quit".
|
// Start the REPL loop, which continues until the user types "exit" or "quit" or task completes.
|
||||||
for {
|
for !r.exitRequested {
|
||||||
|
// Check if we should exit before prompting (non-blocking check)
|
||||||
|
if r.exitRequested {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
// Prompt the user for input, and provide suggestions.
|
// Prompt the user for input, and provide suggestions.
|
||||||
input := prompt.Input(
|
input := prompt.Input(
|
||||||
PromptPrefix,
|
PromptPrefix,
|
||||||
@@ -64,6 +85,11 @@ func (r *REPL) Run(ctx context.Context, config cli.CLIConfig) error {
|
|||||||
promptOptions(history)...,
|
promptOptions(history)...,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Check again after prompt returns (in case validation completed while waiting)
|
||||||
|
if r.exitRequested {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
// Trim whitespace from the input to ensure consistent command processing.
|
// Trim whitespace from the input to ensure consistent command processing.
|
||||||
input = strings.TrimSpace(input)
|
input = strings.TrimSpace(input)
|
||||||
|
|
||||||
@@ -82,3 +108,32 @@ func (r *REPL) Run(ctx context.Context, config cli.CLIConfig) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *REPL) watchValidation() {
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case feedback := <-r.feedbackChan:
|
||||||
|
r.currentFeedback = feedback
|
||||||
|
if feedback.Success {
|
||||||
|
fmt.Printf("\n%s\n", styles.TitleStyle.Render("Task completed successfully!"))
|
||||||
|
fmt.Println("Press Enter to exit...")
|
||||||
|
r.exitRequested = true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
case <-r.quitChan:
|
||||||
|
r.exitRequested = true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetCurrentFeedback returns the current validation feedback for the status command
|
||||||
|
func (r *REPL) GetCurrentFeedback() task.ValidationFeedback {
|
||||||
|
return r.currentFeedback
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetChannels sets the channels for receiving validation feedback and quit signals from the task interface
|
||||||
|
func (r *REPL) SetChannels(feedbackChan chan task.ValidationFeedback, quitChan chan bool) {
|
||||||
|
r.feedbackChan = feedbackChan
|
||||||
|
r.quitChan = quitChan
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user