Skip to content

Commit 71f8abc

Browse files
committed
cleanup more activities operations
1 parent 50d9e98 commit 71f8abc

4 files changed

Lines changed: 56 additions & 107 deletions

File tree

cmd/activities.go

Lines changed: 54 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -15,50 +15,49 @@ var newCmd = &cobra.Command{
1515
Run: func(cmd *cobra.Command, args []string) {
1616
projectId, _ := cmd.Flags().GetInt("project")
1717
taskId, _ := cmd.Flags().GetInt("task")
18-
// description, err := cmd.Flags().GetString("description")
19-
projects, err := data.GetProjects()
18+
description, err := cmd.Flags().GetString("description")
19+
20+
projects, err := data.GetProjects()
21+
if err != nil {
22+
fmt.Println("Could not retrieve projects", err)
23+
}
24+
2025
if projectId == 0 {
21-
if err != nil {
22-
fmt.Println("Could not get projects")
23-
}
2426

2527
options := make([]huh.Option[int], len(projects))
2628
for i, p := range projects {
2729
options[i] = huh.NewOption[int](p.Name, p.Id)
2830
}
2931

3032
pform := huh.NewSelect[int]().Options(options...).Value(&projectId)
31-
pform.Run()
32-
if (projectId == 0) {
33-
return
34-
}
33+
pform.Run()
34+
if projectId == 0 {
35+
return
36+
}
37+
}
38+
39+
var project data.Project
40+
for _, p := range projects {
41+
if p.Id == projectId {
42+
project = p
43+
}
44+
}
45+
46+
if taskId == 0 {
47+
options := make([]huh.Option[int], len(project.Tasks))
48+
for i, t := range project.Tasks {
49+
options[i] = huh.NewOption[int](t.Name, t.Id)
50+
}
51+
tform := huh.NewSelect[int]().Options(options...).Value(&taskId)
52+
tform.Run()
53+
if taskId == 0 {
54+
return
55+
}
3556
}
3657

37-
var project data.Project
38-
for _, p := range projects {
39-
if p.Id == projectId {
40-
project = p
41-
}
42-
}
43-
44-
if taskId == 0 {
45-
if err != nil {
46-
fmt.Println("Could not get tasks")
47-
}
48-
options := make([]huh.Option[int], len(project.Tasks))
49-
for i, t := range project.Tasks {
50-
options[i] = huh.NewOption[int](t.Name, t.Id)
51-
}
52-
tform := huh.NewSelect[int]().Options(options...).Value(&taskId)
53-
tform.Run()
54-
if taskId == 0 {
55-
return
56-
}
57-
}
58-
59-
if description == "" {
60-
huh.NewInput().Title("Description:").Prompt(">").Value(&description).Run()
61-
}
58+
if description == "" {
59+
huh.NewInput().Title("Description:").Prompt(">").Value(&description).Run()
60+
}
6261

6362
err = data.CreateActivity(projectId, taskId, description)
6463
if err != nil {
@@ -94,23 +93,23 @@ var editCmd = &cobra.Command{
9493
}
9594

9695
var deleteCmd = &cobra.Command{
97-
Use: "delete <activity>",
98-
Short: "Delete an activity",
99-
Run: func(cmd *cobra.Command, args []string) {
100-
if len(args) == 0 {
101-
cmd.Help()
102-
return
103-
}
104-
activityId, err := strconv.Atoi(args[0])
105-
if err != nil {
106-
fmt.Println("Invalid activity id")
107-
return
108-
}
109-
err = data.DeleteActivity(activityId)
110-
if err != nil {
111-
fmt.Println("Could not delete activity:", err)
112-
}
113-
},
96+
Use: "delete <activity>",
97+
Short: "Delete an activity",
98+
Run: func(cmd *cobra.Command, args []string) {
99+
if len(args) == 0 {
100+
cmd.Help()
101+
return
102+
}
103+
activityId, err := strconv.Atoi(args[0])
104+
if err != nil {
105+
fmt.Println("Invalid activity id")
106+
return
107+
}
108+
err = data.DeleteActivity(activityId)
109+
if err != nil {
110+
fmt.Println("Could not delete activity:", err)
111+
}
112+
},
114113
}
115114

116115
var activitiesCmd = &cobra.Command{
@@ -119,17 +118,15 @@ var activitiesCmd = &cobra.Command{
119118
}
120119

121120
func init() {
122-
activitiesCmd.Flags().BoolP("new", "n", false, "Create a new activity")
123-
124-
activitiesCmd.Flags().IntP("delete", "x", 0, "Delete activity by ID")
125-
126121
editCmd.Flags().IntP("time", "t", 0, "Set the time for the activity (in seconds)")
127122
editCmd.Flags().StringP("description", "d", "", "Set the description for the activity")
128123

129124
activitiesCmd.AddCommand(editCmd)
130-
activitiesCmd.AddCommand(newCmd)
131125

132-
activitiesCmd.AddCommand(deleteCmd)
126+
newCmd.Flags().Bool("no-start", false, "Don't start the activity when created")
127+
activitiesCmd.AddCommand(newCmd)
128+
129+
activitiesCmd.AddCommand(deleteCmd)
133130

134131
rootCmd.AddCommand(activitiesCmd)
135132
}

cmd/ls.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ var activityCmd = &cobra.Command{
5858
today, _ := cmd.Flags().GetBool("today")
5959
for _, activity := range activities {
6060
if !today || activity.Date == time.Now().Format("2006-01-02") {
61-
fmt.Printf("%d %s\n", activity.Id, activity.Description)
61+
fmt.Printf("%d\t%s\n", activity.Id, activity.Description)
6262
}
6363
}
6464
},

cmd/start.go

Lines changed: 0 additions & 43 deletions
This file was deleted.

cmd/stop.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@ import (
1010
// rootCmd represents the base command when called without any subcommands
1111
var stopCmd = &cobra.Command{
1212
Use: "stop [id]",
13-
Short: "Stop time tracking for a given project",
13+
Short: "Stop time tracking for all projects",
1414
Run: func(cmd *cobra.Command, args []string) {
15-
if activityId != 0 {
16-
data.StopActivity(activityId)
17-
}
1815
activities, err := data.GetActivities()
1916
if err != nil {
2017
fmt.Println(err)
@@ -29,7 +26,5 @@ var stopCmd = &cobra.Command{
2926
}
3027

3128
func init() {
32-
stopCmd.Flags().IntVarP(&activityId, "activity", "a", 0, "Activity ID (if not provided, a new activity will be created)")
33-
stopCmd.MarkFlagRequired("activity")
3429
rootCmd.AddCommand(stopCmd)
3530
}

0 commit comments

Comments
 (0)