From 798af1a486b864ea3b8c5cb6d1e7226a09300bd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=9E=E3=83=AA=E3=82=A6=E3=82=B9?= Date: Sat, 17 Oct 2020 01:33:47 +0100 Subject: [PATCH] Implemented project command --- z/project.go | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 z/project.go diff --git a/z/project.go b/z/project.go new file mode 100644 index 0000000..af27452 --- /dev/null +++ b/z/project.go @@ -0,0 +1,60 @@ +package z + +import ( + "os" + "fmt" + "github.com/spf13/cobra" + // "github.com/gookit/color" +) + +var projectColor string + +type Project struct { + Name string `json:"name,omitempty"` + Color string `json:"color,omitempty"` +} + +var projectCmd = &cobra.Command{ + Use: "project ([flags]) [project]", + Short: "Project settings", + Long: "Configure project settings.", + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + user := GetCurrentUser() + projectName := args[0] + + + project, err := database.GetProject(user, projectName) + if err != nil { + fmt.Printf("%s %+v\n", CharError, err) + os.Exit(1) + } + + project.Name = projectName + + if projectColor != "" { + project.Color = projectColor + } + + err = database.UpdateProject(user, projectName, project) + if err != nil { + fmt.Printf("%s %+v\n", CharError, err) + os.Exit(1) + } + + fmt.Printf("%s project updated\n", CharInfo) + return + }, +} + +func init() { + rootCmd.AddCommand(projectCmd) + projectCmd.Flags().StringVarP(&projectColor, "color", "c", "", "Set the color of the project (hex code, e.g. #121212)") + + var err error + database, err = InitDatabase() + if err != nil { + fmt.Printf("%s %+v\n", CharError, err) + os.Exit(1) + } +}