task

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 13, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CreateCmd = &cobra.Command{
	Use:   "create",
	Short: "Create a new task",
	Long:  `Create a new task with the specified configuration`,
	Run: func(cmd *cobra.Command, args []string) {
		source, _ := cmd.Flags().GetString("from-json")
		if source != "" {
			tasks, err := repository.ReadJSONSource[[]models.Task](source)
			if err != nil {
				styles.PrintError(fmt.Sprintf("Failed to read source: %v", err))
				os.Exit(1)
			}

			if err := repository.ImportTasks(tasks); err != nil {
				styles.PrintError(fmt.Sprintf("Import failed:\n%v", err))
				os.Exit(1)
			}

			styles.PrintSuccess(fmt.Sprintf("%d task(s) imported successfully!", len(tasks)))
			os.Exit(0)
		}

		p := tea.NewProgram(NewModel())
		if _, err := p.Run(); err != nil {
			os.Exit(1)
		}
	},
}

CreateCmd starts the TUI form to create a new task, or imports tasks from JSON when --from-json is set.

View Source
var DeleteCmd = &cobra.Command{
	Use:               "delete <name>",
	Short:             "Delete a task",
	Long:              `Delete a task with the specified name`,
	Args:              cobra.ExactArgs(1),
	ValidArgsFunction: completeTaskNames,
	Run: func(cmd *cobra.Command, args []string) {
		taskName := args[0]

		if _, err := repository.FindTaskByName(taskName); err != nil {
			styles.PrintError(fmt.Sprintf("Task '%s' not found", taskName))
			return
		}

		if err := DeleteTask(taskName); err != nil {
			styles.PrintError(fmt.Sprintf("Failed to delete task '%s': %v", taskName, err))
			return
		}

		styles.PrintSuccess(fmt.Sprintf("Task '%s' deleted successfully!", taskName))
	},
}

DeleteCmd deletes a task specified by name.

View Source
var EditCmd = &cobra.Command{
	Use:               "edit <name>",
	Short:             "Edit an existing task",
	Long:              `Edit an existing task with the specified name`,
	Args:              cobra.ExactArgs(1),
	ValidArgsFunction: completeTaskNames,
	Run: func(cmd *cobra.Command, args []string) {
		taskName := args[0]

		task, err := repository.FindTaskByName(taskName)
		if err != nil {
			styles.PrintError(fmt.Sprintf("Task '%s' not found: %v", taskName, err))
			return
		}

		p := tea.NewProgram(NewEditModel(task))
		if _, err := p.Run(); err != nil {
			os.Exit(1)
		}
	},
}

EditCmd starts the TUI form to edit an existing task.

View Source
var ListCmd = &cobra.Command{
	Use:   "list",
	Short: "List all tasks",
	Long:  `Display a list of all configured tasks`,
	Run: func(cmd *cobra.Command, args []string) {
		onlyNames, _ := cmd.Flags().GetBool("only-names")

		if onlyNames {
			err := listAllTaskNames()
			if err != nil {
				fmt.Println("Error listing task names:", err)
			}
			return
		}

		if err := listAllTasks(); err != nil {
			fmt.Println("Error listing tasks:", err)
		}
	},
}

ListCmd displays the list of configured tasks.

View Source
var RunCmd = &cobra.Command{
	Use:               "run <name>",
	Short:             "Run a task",
	Long:              `Run a task with the specified name`,
	Args:              cobra.ExactArgs(1),
	ValidArgsFunction: completeTaskNames,
	Run: func(cmd *cobra.Command, args []string) {
		taskName := args[0]

		runner, err := vscode.NewRunner()
		if err != nil {
			styles.PrintError(fmt.Sprintf("Failed to create secure runner: %v", err))
			return
		}

		styles.PrintProgress(fmt.Sprintf("Detected secure VSCode instance, proceeding to run task '%s'...", taskName))

		if err := runner.RunTask(taskName); err != nil {
			styles.PrintError(fmt.Sprintf("Error running task: %v", err))
			return
		}
	},
}

Functions

func DeleteTask

func DeleteTask(name string) error

DeleteTask removes a task from the local configuration file by name.

func FindByName

func FindByName(name string) (*models.Task, error)

FindByName retrieves a task by its name from the saved tasks

func NewEditModel

func NewEditModel(task *models.Task) tea.Model

NewEditModel initializes and returns the TUI model for editing an existing task.

func NewModel

func NewModel() tea.Model

NewModel initializes and returns the TUI model for the task creation form.

Types

type TaskModel

type TaskModel struct {
	// contains filtered or unexported fields
}

TaskModel manages the state and logic of the TUI form for creating/editing tasks.

func (*TaskModel) HandleFocus

func (t *TaskModel) HandleFocus() (tea.Model, tea.Cmd)

HandleFocus updates the visual focus and style of the form fields.

func (*TaskModel) HandleInput

func (t *TaskModel) HandleInput(msg tea.Msg) tea.Cmd

HandleInput processes text input and updates the suggestion managers.

func (*TaskModel) Init

func (t *TaskModel) Init() tea.Cmd

Init initializes the TUI model (cursor blinking).

func (*TaskModel) Update

func (t *TaskModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update handles messages received by the TUI model and updates the form state.

func (*TaskModel) View

func (t *TaskModel) View() string

View renders the TUI form view for creating/editing tasks.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL