diff --git a/cmd/milestones/finish.go b/cmd/milestones/finish.go index cd8338d..2ade0ed 100644 --- a/cmd/milestones/finish.go +++ b/cmd/milestones/finish.go @@ -10,11 +10,15 @@ import ( "github.com/spf13/cobra" ) +var ( + finishMilestoneProjectFlag string +) + func FinishCmd() *cobra.Command { cmd := &cobra.Command{ Use: "finish", Short: "Finish the active milestone", - 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.`, + 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.`, Run: func(cmd *cobra.Command, args []string) { ui.NewlineAbove() @@ -25,7 +29,7 @@ func FinishCmd() *cobra.Command { } defer db.Close() - projectName, err := project.DetectConfiguredProject() + projectName, err := project.DetectConfiguredProjectWithOverride(finishMilestoneProjectFlag) if err != nil { ui.PrintError(ui.EmojiError, fmt.Sprintf("detecting project: %v", err)) os.Exit(1) @@ -39,7 +43,7 @@ func FinishCmd() *cobra.Command { } if activeMilestone == nil { - ui.PrintError(ui.EmojiError, "No active milestone found") + ui.PrintError(ui.EmojiError, fmt.Sprintf("No active milestone found for %s", projectName)) ui.PrintMuted(0, "Use 'tmpo milestone start' to start a new milestone.") ui.NewlineBelow() os.Exit(1) @@ -73,5 +77,7 @@ func FinishCmd() *cobra.Command { }, } + cmd.Flags().StringVarP(&finishMilestoneProjectFlag, "project", "p", "", "Finish a milestone for a specific global project") + return cmd } diff --git a/cmd/milestones/start.go b/cmd/milestones/start.go index 6af6e16..92fea4a 100644 --- a/cmd/milestones/start.go +++ b/cmd/milestones/start.go @@ -10,11 +10,15 @@ import ( "github.com/spf13/cobra" ) +var ( + startMilestoneProjectFlag string +) + func StartCmd() *cobra.Command { cmd := &cobra.Command{ Use: "start [name]", Short: "Start a new milestone", - Long: `Start a new milestone for the current project. Time entries created after starting a milestone will be automatically tagged with it.`, + 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.`, Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { ui.NewlineAbove() @@ -26,7 +30,7 @@ func StartCmd() *cobra.Command { } defer db.Close() - projectName, err := project.DetectConfiguredProject() + projectName, err := project.DetectConfiguredProjectWithOverride(startMilestoneProjectFlag) if err != nil { ui.PrintError(ui.EmojiError, fmt.Sprintf("detecting project: %v", err)) os.Exit(1) @@ -79,5 +83,7 @@ func StartCmd() *cobra.Command { }, } + cmd.Flags().StringVarP(&startMilestoneProjectFlag, "project", "p", "", "Start a milestone for a specific global project") + return cmd } diff --git a/cmd/milestones/status.go b/cmd/milestones/status.go index c8ffdcb..ce075e6 100644 --- a/cmd/milestones/status.go +++ b/cmd/milestones/status.go @@ -12,11 +12,15 @@ import ( "github.com/spf13/cobra" ) +var ( + statusMilestoneProjectFlag string +) + func StatusCmd() *cobra.Command { cmd := &cobra.Command{ Use: "status", Short: "Show active milestone status", - Long: `Display information about the currently active milestone for the current project.`, + Long: `Display information about the currently active milestone for the current project, or the one specified.`, Run: func(cmd *cobra.Command, args []string) { ui.NewlineAbove() @@ -27,7 +31,7 @@ func StatusCmd() *cobra.Command { } defer db.Close() - projectName, err := project.DetectConfiguredProject() + projectName, err := project.DetectConfiguredProjectWithOverride(statusMilestoneProjectFlag) if err != nil { ui.PrintError(ui.EmojiError, fmt.Sprintf("detecting project: %v", err)) os.Exit(1) @@ -41,7 +45,7 @@ func StatusCmd() *cobra.Command { } if activeMilestone == nil { - ui.PrintWarning(ui.EmojiWarning, "No active milestone") + ui.PrintError(ui.EmojiError, fmt.Sprintf("No active milestone found for %s", projectName)) ui.PrintMuted(0, "Use 'tmpo milestone start' to start a new milestone.") ui.NewlineBelow() return @@ -72,5 +76,7 @@ func StatusCmd() *cobra.Command { }, } + cmd.Flags().StringVarP(&statusMilestoneProjectFlag, "project", "p", "", "Get the milestone status for a specific global project") + return cmd }