Skip to content

Commit bbf29f9

Browse files
feat: Add --project flag to tmpo milestone [start | finish | status] (#108)
2 parents 9794fee + 56000a4 commit bbf29f9

3 files changed

Lines changed: 26 additions & 8 deletions

File tree

cmd/milestones/finish.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@ import (
1010
"github.com/spf13/cobra"
1111
)
1212

13+
var (
14+
finishMilestoneProjectFlag string
15+
)
16+
1317
func FinishCmd() *cobra.Command {
1418
cmd := &cobra.Command{
1519
Use: "finish",
1620
Short: "Finish the active milestone",
17-
Long: `Finish the currently active milestone for the current project. This marks the milestone as completed and stops auto-tagging new time entries with it.`,
21+
Long: `Finish the currently active milestone for the current project, or the one specified. This marks the milestone as completed and stops auto-tagging new time entries with it.`,
1822
Run: func(cmd *cobra.Command, args []string) {
1923
ui.NewlineAbove()
2024

@@ -25,7 +29,7 @@ func FinishCmd() *cobra.Command {
2529
}
2630
defer db.Close()
2731

28-
projectName, err := project.DetectConfiguredProject()
32+
projectName, err := project.DetectConfiguredProjectWithOverride(finishMilestoneProjectFlag)
2933
if err != nil {
3034
ui.PrintError(ui.EmojiError, fmt.Sprintf("detecting project: %v", err))
3135
os.Exit(1)
@@ -39,7 +43,7 @@ func FinishCmd() *cobra.Command {
3943
}
4044

4145
if activeMilestone == nil {
42-
ui.PrintError(ui.EmojiError, "No active milestone found")
46+
ui.PrintError(ui.EmojiError, fmt.Sprintf("No active milestone found for %s", projectName))
4347
ui.PrintMuted(0, "Use 'tmpo milestone start' to start a new milestone.")
4448
ui.NewlineBelow()
4549
os.Exit(1)
@@ -73,5 +77,7 @@ func FinishCmd() *cobra.Command {
7377
},
7478
}
7579

80+
cmd.Flags().StringVarP(&finishMilestoneProjectFlag, "project", "p", "", "Finish a milestone for a specific global project")
81+
7682
return cmd
7783
}

cmd/milestones/start.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@ import (
1010
"github.com/spf13/cobra"
1111
)
1212

13+
var (
14+
startMilestoneProjectFlag string
15+
)
16+
1317
func StartCmd() *cobra.Command {
1418
cmd := &cobra.Command{
1519
Use: "start [name]",
1620
Short: "Start a new milestone",
17-
Long: `Start a new milestone for the current project. Time entries created after starting a milestone will be automatically tagged with it.`,
21+
Long: `Start a new milestone for the current project, or the one specified. Time entries created after starting a milestone will be automatically tagged with it.`,
1822
Args: cobra.ExactArgs(1),
1923
Run: func(cmd *cobra.Command, args []string) {
2024
ui.NewlineAbove()
@@ -26,7 +30,7 @@ func StartCmd() *cobra.Command {
2630
}
2731
defer db.Close()
2832

29-
projectName, err := project.DetectConfiguredProject()
33+
projectName, err := project.DetectConfiguredProjectWithOverride(startMilestoneProjectFlag)
3034
if err != nil {
3135
ui.PrintError(ui.EmojiError, fmt.Sprintf("detecting project: %v", err))
3236
os.Exit(1)
@@ -79,5 +83,7 @@ func StartCmd() *cobra.Command {
7983
},
8084
}
8185

86+
cmd.Flags().StringVarP(&startMilestoneProjectFlag, "project", "p", "", "Start a milestone for a specific global project")
87+
8288
return cmd
8389
}

cmd/milestones/status.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@ import (
1212
"github.com/spf13/cobra"
1313
)
1414

15+
var (
16+
statusMilestoneProjectFlag string
17+
)
18+
1519
func StatusCmd() *cobra.Command {
1620
cmd := &cobra.Command{
1721
Use: "status",
1822
Short: "Show active milestone status",
19-
Long: `Display information about the currently active milestone for the current project.`,
23+
Long: `Display information about the currently active milestone for the current project, or the one specified.`,
2024
Run: func(cmd *cobra.Command, args []string) {
2125
ui.NewlineAbove()
2226

@@ -27,7 +31,7 @@ func StatusCmd() *cobra.Command {
2731
}
2832
defer db.Close()
2933

30-
projectName, err := project.DetectConfiguredProject()
34+
projectName, err := project.DetectConfiguredProjectWithOverride(statusMilestoneProjectFlag)
3135
if err != nil {
3236
ui.PrintError(ui.EmojiError, fmt.Sprintf("detecting project: %v", err))
3337
os.Exit(1)
@@ -41,7 +45,7 @@ func StatusCmd() *cobra.Command {
4145
}
4246

4347
if activeMilestone == nil {
44-
ui.PrintWarning(ui.EmojiWarning, "No active milestone")
48+
ui.PrintError(ui.EmojiError, fmt.Sprintf("No active milestone found for %s", projectName))
4549
ui.PrintMuted(0, "Use 'tmpo milestone start' to start a new milestone.")
4650
ui.NewlineBelow()
4751
return
@@ -72,5 +76,7 @@ func StatusCmd() *cobra.Command {
7276
},
7377
}
7478

79+
cmd.Flags().StringVarP(&statusMilestoneProjectFlag, "project", "p", "", "Get the milestone status for a specific global project")
80+
7581
return cmd
7682
}

0 commit comments

Comments
 (0)