- Add colorized output for success/error messages - Change custom message flag from -m to -M - Implement branch prefixing (feature/ or fix/) - Add config for workon.model and workon.ide - Update README.md index on task completion - Integrate IDE opening if configured - Refine error handling and logging
61 lines
1.7 KiB
Go
61 lines
1.7 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/fatih/color"
|
|
"github.com/spf13/cobra"
|
|
|
|
"gmgauthier.com/grokkit/internal/logger"
|
|
"gmgauthier.com/grokkit/internal/workon"
|
|
)
|
|
|
|
var workonCmd = &cobra.Command{
|
|
Use: "workon <todo_item_title>",
|
|
Short: "Start or complete work on a todo item or fix",
|
|
Long: `workon automates starting or completing a todo/fix:
|
|
- Moves queued todo to doing/ or creates new fix .md
|
|
- Creates matching git branch
|
|
- Generates + appends "Work Plan" via Grok
|
|
- Commits to the branch
|
|
- Optional: cnadd log + open in configured IDE
|
|
|
|
Purely transactional. See todo/doing/workon.md for full spec.`,
|
|
Args: cobra.ExactArgs(1),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
title := strings.ReplaceAll(args[0], " ", "-")
|
|
customMsg, _ := cmd.Flags().GetString("message")
|
|
isFix, _ := cmd.Flags().GetBool("fix")
|
|
isComplete, _ := cmd.Flags().GetBool("complete")
|
|
|
|
if isComplete && customMsg != "" {
|
|
return fmt.Errorf("-c cannot be combined with -m")
|
|
}
|
|
|
|
logger.Info("workon starting", "title", title, "fix", isFix, "complete", isComplete)
|
|
|
|
if err := workon.Run(title, customMsg, isFix, isComplete); err != nil {
|
|
color.Red("workon failed: %v", err)
|
|
return err
|
|
}
|
|
|
|
mode := "todo"
|
|
if isFix {
|
|
mode = "fix"
|
|
}
|
|
action := "started"
|
|
if isComplete {
|
|
action = "completed"
|
|
}
|
|
color.Green("workon %s: %s (%s)", action, title, mode)
|
|
return nil
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
workonCmd.Flags().StringP("message", "M", "", "Custom commit message (default: \"Start working on <todo_item_title>\")")
|
|
workonCmd.Flags().BoolP("fix", "f", false, "Treat as fix instead of todo (create new .md in doing/)")
|
|
workonCmd.Flags().BoolP("complete", "c", false, "Complete the item (move to completed/; exclusive)")
|
|
}
|