-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathextract.go
More file actions
60 lines (48 loc) · 1.48 KB
/
Copy pathextract.go
File metadata and controls
60 lines (48 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
Copyright © 2024 Achnologia <EMAIL ADDRESS>
*/
package cmd
import (
"fmt"
"image/color"
"github.com/Achno/gowall/config"
"github.com/Achno/gowall/internal/backends/colorthief"
"github.com/Achno/gowall/internal/image"
"github.com/Achno/gowall/utils"
"github.com/spf13/cobra"
)
var colorsNum int
var previewFlag bool
// extractCmd represents the extract command
var extractCmd = &cobra.Command{
Use: "extract [FILE]",
Short: "Returns the color palette of the image you specified (like pywal)",
Long: `Using the colorthief backend ( like pywal ) it returns the color palette of the image (path) you specified`,
Run: func(cmd *cobra.Command, args []string) {
switch {
case len(args) > 0:
expandFile := utils.ExpandHomeDirectory(args)
clr, err := colorthief.GetPaletteFromFile(expandFile[0], colorsNum)
utils.HandleError(err)
for _, c := range clr {
rgba, ok := c.(color.RGBA)
if !ok {
utils.HandleError(fmt.Errorf("error in RGB casting"))
}
fmt.Println(image.RGBtoHex(rgba))
}
// open up hex code preview site
if previewFlag {
utils.OpenURL(config.HexCodeVisualUrl)
}
default:
fmt.Println("Error: requires at least 1 arg(s), only received 0")
_ = cmd.Usage()
}
},
}
func init() {
rootCmd.AddCommand(extractCmd)
extractCmd.Flags().IntVarP(&colorsNum, "colors", "c", 6, "-c <number of colors to return>")
extractCmd.Flags().BoolVarP(&previewFlag, "preview", "p", false, "gowall extract -p (opens hex code preview site)")
}