zeit/z/projectCmd.go

56 lines
1.1 KiB
Go
Raw Permalink Normal View History

2020-10-17 00:33:47 +00:00
package z
import (
"os"
"fmt"
2020-10-17 12:17:01 +00:00
// "time"
2020-10-17 00:33:47 +00:00
"github.com/spf13/cobra"
// "github.com/gookit/color"
)
var projectColor string
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)
}
}