| user | 5a7d60d | 2025-07-27 21:22:04 +0400 | [diff] [blame] | 1 | package commands |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "fmt" |
| 6 | "time" |
| 7 | |
| 8 | "github.com/iomodo/staff/tm" |
| 9 | "github.com/spf13/cobra" |
| 10 | ) |
| 11 | |
| 12 | var createTaskCmd = &cobra.Command{ |
| 13 | Use: "create-task [title]", |
| 14 | Short: "Create a new task", |
| 15 | Long: `Create a new task with specified title, description, and priority. |
| 16 | |
| 17 | Examples: |
| 18 | staff create-task "Add user authentication" |
| 19 | staff create-task "Fix login bug" --description "Users cannot log in with Google OAuth" --priority high --assignee backend-engineer`, |
| 20 | Args: cobra.ExactArgs(1), |
| 21 | RunE: runCreateTask, |
| 22 | } |
| 23 | |
| 24 | var ( |
| 25 | taskDescription string |
| 26 | taskPriority string |
| 27 | taskAssignee string |
| 28 | taskDueDate string |
| 29 | ) |
| 30 | |
| 31 | func init() { |
| 32 | createTaskCmd.Flags().StringVarP(&taskDescription, "description", "d", "", "Task description") |
| 33 | createTaskCmd.Flags().StringVarP(&taskPriority, "priority", "p", "medium", "Task priority (low, medium, high)") |
| 34 | createTaskCmd.Flags().StringVarP(&taskAssignee, "assignee", "a", "", "Agent to assign the task to") |
| 35 | createTaskCmd.Flags().StringVar(&taskDueDate, "due", "", "Due date (RFC3339 format, e.g., 2024-01-15T10:00:00Z)") |
| 36 | } |
| 37 | |
| 38 | func runCreateTask(cmd *cobra.Command, args []string) error { |
| 39 | title := args[0] |
| iomodo | 50598c6 | 2025-07-27 22:06:32 +0400 | [diff] [blame] | 40 | |
| user | 5a7d60d | 2025-07-27 21:22:04 +0400 | [diff] [blame] | 41 | // Validate priority |
| 42 | priority := tm.TaskPriority(taskPriority) |
| 43 | if priority != tm.PriorityLow && priority != tm.PriorityMedium && priority != tm.PriorityHigh { |
| 44 | return fmt.Errorf("invalid priority: %s (must be low, medium, or high)", taskPriority) |
| 45 | } |
| 46 | |
| 47 | // Parse due date if provided |
| 48 | var dueDate *time.Time |
| 49 | if taskDueDate != "" { |
| 50 | parsed, err := time.Parse(time.RFC3339, taskDueDate) |
| 51 | if err != nil { |
| 52 | return fmt.Errorf("invalid due date format: %s (expected RFC3339)", taskDueDate) |
| 53 | } |
| 54 | dueDate = &parsed |
| 55 | } |
| 56 | |
| 57 | // Create task request |
| 58 | req := &tm.TaskCreateRequest{ |
| 59 | Title: title, |
| 60 | Description: taskDescription, |
| 61 | OwnerID: "user", // MVP: single user |
| 62 | Priority: priority, |
| 63 | DueDate: dueDate, |
| 64 | } |
| 65 | |
| 66 | // Create the task |
| 67 | task, err := taskManager.CreateTask(context.Background(), req) |
| 68 | if err != nil { |
| 69 | return fmt.Errorf("failed to create task: %w", err) |
| 70 | } |
| 71 | |
| 72 | fmt.Printf("Task created successfully!\n") |
| 73 | fmt.Printf("ID: %s\n", task.ID) |
| 74 | fmt.Printf("Title: %s\n", task.Title) |
| 75 | fmt.Printf("Priority: %s\n", task.Priority) |
| 76 | fmt.Printf("Status: %s\n", task.Status) |
| iomodo | 50598c6 | 2025-07-27 22:06:32 +0400 | [diff] [blame] | 77 | |
| user | 5a7d60d | 2025-07-27 21:22:04 +0400 | [diff] [blame] | 78 | // Auto-assign if assignee is specified |
| 79 | if taskAssignee != "" { |
| 80 | task.Assignee = taskAssignee |
| 81 | if err := taskManager.UpdateTask(task); err != nil { |
| 82 | fmt.Printf("Warning: Failed to assign task to %s: %v\n", taskAssignee, err) |
| 83 | } else { |
| 84 | fmt.Printf("Assigned to: %s\n", taskAssignee) |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | return nil |
| iomodo | 50598c6 | 2025-07-27 22:06:32 +0400 | [diff] [blame] | 89 | } |