@@ -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
9695var 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
116115var activitiesCmd = & cobra.Command {
@@ -119,17 +118,15 @@ var activitiesCmd = &cobra.Command{
119118}
120119
121120func 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}
0 commit comments