Add switch and switchback Cmd

Add switch and switchback Cmd
This commit is contained in:
Martin (Schretzi) Fuchsluger
2025-02-17 19:26:03 +01:00
parent 99607391c8
commit e7780432d7
3 changed files with 65 additions and 0 deletions
+1
View File
@@ -12,6 +12,7 @@ var database *Database
var begin string var begin string
var finish string var finish string
var switchString string
var project string var project string
var task string var task string
var notes string var notes string
+26
View File
@@ -0,0 +1,26 @@
package z
import (
"github.com/spf13/cobra"
)
var switchBackCmd = &cobra.Command{
Use: "switchback",
Short: "switchback to the task before the last one",
Long: "End running activity and resume the task which was before, which can either be kept running until 'finish' is being called or parameterized to be a finished activity.",
Run: func(cmd *cobra.Command, args []string) {
finish = switchString
finishTask(FinishOnlyTime)
finish = ""
begin = switchString
resumeTask(2)
},
}
func init() {
rootCmd.AddCommand(switchBackCmd)
switchBackCmd.Flags().StringVarP(&switchString, "begin", "b", "", "Time the new activity should begin at and the old one ends\n\nEither in the formats 16:00 / 4:00PM \nor relative to the current time, \ne.g. -0:15 (now minus 15 minutes), +1.50 (now plus 1:30h).")
}
+38
View File
@@ -0,0 +1,38 @@
package z
import (
"github.com/spf13/cobra"
)
var switchCmd = &cobra.Command{
Use: "switch",
Short: "switch to another task",
Long: "End running activity and track new activity, which can either be kept running until 'finish' is being called or parameterized to be a finished activity.",
Run: func(cmd *cobra.Command, args []string) {
finish = switchString
finishTask(FinishOnlyTime)
finish = ""
begin = switchString
trackTask()
},
}
func init() {
rootCmd.AddCommand(switchCmd)
switchCmd.Flags().StringVarP(&switchString, "begin", "b", "", "Time the new activity should begin at and the old one ends\n\nEither in the formats 16:00 / 4:00PM \nor relative to the current time, \ne.g. -0:15 (now minus 15 minutes), +1.50 (now plus 1:30h).")
switchCmd.Flags().StringVarP(&project, "project", "p", "", "Project to be assigned")
switchCmd.Flags().StringVarP(&task, "task", "t", "", "Task to be assigned")
switchCmd.Flags().StringVarP(&notes, "notes", "n", "", "Activity notes")
flagName := "task"
switchCmd.RegisterFlagCompletionFunc(flagName, func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
user := GetCurrentUser()
entries, _ := database.ListEntries(user)
_, tasks := listProjectsAndTasks(entries)
return tasks, cobra.ShellCompDirectiveDefault
})
}