Implemented project command
This commit is contained in:
parent
b7d64baeef
commit
798af1a486
1 changed files with 60 additions and 0 deletions
60
z/project.go
Normal file
60
z/project.go
Normal file
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue