-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create add and remove effort for Jira
- Loading branch information
Showing
11 changed files
with
316 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,64 @@ | ||
package cmd | ||
|
||
import ( | ||
"eager/internal" | ||
"eager/pkg" | ||
"eager/pkg/cli" | ||
"eager/pkg/jira" | ||
"fmt" | ||
"github.com/spf13/cobra" | ||
"time" | ||
) | ||
|
||
func init() { | ||
// TODO mro Reactivate that command after implementing it | ||
//rootCmd.AddCommand(addCmd) | ||
rootCmd.AddCommand(addCmd) | ||
addCmd.AddCommand(addJiraCmd) | ||
|
||
addCmd.PersistentFlags().IntVar(&conf.Year, internal.FlagYear, time.Now().Year(), "specify the year") | ||
addCmd.PersistentFlags().IntVar(&conf.Month, internal.FlagMonth, int(time.Now().Month()), "specify the month") | ||
addCmd.PersistentFlags().IntVar(&conf.Day, internal.FlagDay, time.Now().Day(), "specify the day") | ||
addCmd.PersistentFlags().StringVar(&conf.Task, internal.FlagTask, "", "specify the task") | ||
addCmd.PersistentFlags().BoolVar(&conf.Duration.Merge, internal.FlagMerge, false, "merge effort on same day and task") | ||
addCmd.MarkFlagRequired(internal.FlagTask) | ||
} | ||
|
||
var addCmd = &cobra.Command{ | ||
Use: "add", | ||
Short: "Add worklog item", | ||
Long: "Add a worklog item to your local store.", | ||
Long: "Add a worklog item to the given store.", | ||
Args: cobra.NoArgs, | ||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error { | ||
// Call to root persistent pre run necessary. See https://github.com/spf13/cobra/issues/216 | ||
err := cmd.Root().PersistentPreRunE(cmd, args) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
}, | ||
} | ||
|
||
var addJiraCmd = &cobra.Command{ | ||
Use: "jira", | ||
Short: "Add worklog item to Jira", | ||
Long: "Add a worklog item to Atlassian Jira.", | ||
Args: cobra.NoArgs, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
duration, err := time.ParseDuration(args[0]) | ||
if err != nil { | ||
return fmt.Errorf("not a valid duration '%s'", args[0]) | ||
} | ||
jira.AddWorklogItem( | ||
pkg.NewHttpClient(), | ||
conf.Server(), | ||
conf.Userinfo(), | ||
conf.Year, | ||
time.Month(conf.Month), | ||
conf.Day, | ||
pkg.Task(conf.Task), | ||
duration, | ||
conf.Duration.Merge, | ||
cli.Confirmation, | ||
) | ||
return nil | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package cli | ||
|
||
import ( | ||
"eager/pkg/jira/model" | ||
"fmt" | ||
) | ||
|
||
func Confirmation(worklog model.Worklog) bool { | ||
var answer string | ||
|
||
fmt.Printf("Remove %s (y/N): ", worklog.String()) | ||
_, err := fmt.Scanln(&answer) | ||
if err != nil { | ||
return false | ||
} | ||
if answer == "y" { | ||
return true | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.