task

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2023 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AddCmd = &cobra.Command{
	Use:   "add [task]",
	Short: "Add a new task",
	Args:  cobra.ExactArgs(1),
	Run: func(cmd *cobra.Command, args []string) {

		tasks := &handlers.Tasks{}
		err := tasks.Load(taskFile)
		checkNilErr(err)

		err = tasks.Add(args[0])
		checkNilErr(err)

		err = tasks.Save(taskFile)
		checkNilErr(err)

		fmt.Println("Task added successfully")
	},
}

addCmd represents the add command

View Source
var DeleteAllCmd = &cobra.Command{
	Use:   "deleteall",
	Short: "Delete all tasks",
	Run: func(cmd *cobra.Command, args []string) {

		tasks := &handlers.Tasks{}
		err := tasks.Load(taskFile)
		checkNilErr(err)

		err = tasks.DeleteAll()
		checkNilErr(err)

		err = tasks.Save(taskFile)
		checkNilErr(err)

		fmt.Println("All tasks deleted successfully")
	},
}

deleteAllCmd represents the deleteAll command

View Source
var DeleteCmd = &cobra.Command{
	Use:   "delete [task ID]",
	Short: "Delete a task by ID",
	Args:  cobra.ExactArgs(1),
	Run: func(cmd *cobra.Command, args []string) {

		tasks := &handlers.Tasks{}
		err := tasks.Load(taskFile)
		checkNilErr(err)

		deleteTaskID := args[0]
		convertedString, err := strconv.Atoi(deleteTaskID)
		if err != nil {
			fmt.Println("Please enter a valid task ID")
			return
		}

		err = tasks.Delete(convertedString)
		checkNilErr(err)

		err = tasks.Save(taskFile)
		checkNilErr(err)

		fmt.Println("Task deleted successfully")
	},
}

deleteCmd represents the delete command

View Source
var DoneCmd = &cobra.Command{
	Use:   "done [task ID]",
	Short: "Mark a task as done",
	Args:  cobra.ExactArgs(1),
	Run: func(cmd *cobra.Command, args []string) {

		tasks := &handlers.Tasks{}
		err := tasks.Load(taskFile)
		checkNilErr(err)

		doneTaskID := args[0]
		convertedString, err := strconv.Atoi(doneTaskID)
		if err != nil {
			fmt.Println("Please enter a valid task ID")
			return
		}

		err = tasks.Done(convertedString)
		checkNilErr(err)

		err = tasks.Save(taskFile)
		checkNilErr(err)

		fmt.Println("Task marked as done successfully")

	},
}

doneCmd represents the done command

View Source
var ListCmd = &cobra.Command{
	Use:   "list",
	Short: "List all tasks",
	Run: func(cmd *cobra.Command, args []string) {
		tasks := &handlers.Tasks{}
		err := tasks.Load(taskFile)
		checkNilErr(err)

		err = tasks.List()
		checkNilErr(err)
	},
}

listCmd represents the list command

View Source
var UpdateCmd = &cobra.Command{
	Use:   "update [task ID] [message]",
	Short: "Update a task by ID",
	Args:  cobra.ExactArgs(2),
	Run: func(cmd *cobra.Command, args []string) {

		tasks := &handlers.Tasks{}
		err := tasks.Load(taskFile)
		checkNilErr(err)

		updateTaskId := args[0]
		convertedString, err := strconv.Atoi(updateTaskId)
		if err != nil {
			fmt.Println("Please enter a valid task ID")
			return
		}

		message := args[1]

		err = tasks.Update(convertedString, message)
		checkNilErr(err)

		err = tasks.Save(taskFile)
		checkNilErr(err)

		fmt.Println("Task updated successfully")

	},
}

updateCmd represents the update command

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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