-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.go
51 lines (43 loc) · 1.41 KB
/
build.go
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
package cmd
import (
u "github.com/branogarbo/golcli/util"
"github.com/spf13/cobra"
)
var buildCmd = &cobra.Command{
Use: "build",
Short: "Creates a build file from a pattern file.",
Example: `golcli build -W 70 -c 400 pattern.txt builds/pattern`,
Args: cobra.RangeArgs(1, 2),
RunE: func(cmd *cobra.Command, args []string) error {
var buildFilePath string
patternFilePath := args[0]
if len(args) == 2 {
buildFilePath = args[1]
}
frameWidth, _ := cmd.Flags().GetInt("width")
frameHeight, _ := cmd.Flags().GetInt("height")
frameCount, _ := cmd.Flags().GetInt("count")
patternX, _ := cmd.Flags().GetInt("pattern-x")
patternY, _ := cmd.Flags().GetInt("pattern-y")
bc := u.BuildConfig{
BuildFilePath: buildFilePath,
Width: frameWidth,
Height: frameHeight,
FrameCount: frameCount,
InitPattern: u.Pattern{
FilePath: patternFilePath,
X: patternX,
Y: patternY,
},
}
return u.GenBuildFile(bc)
},
}
func init() {
rootCmd.AddCommand(buildCmd)
buildCmd.Flags().IntP("width", "W", 40, "The width of the frames")
buildCmd.Flags().IntP("height", "H", 30, "The height of the frames")
buildCmd.Flags().IntP("count", "c", 500, "The number of frames displayed before exiting")
buildCmd.Flags().IntP("pattern-x", "x", 12, "The x offset of the initial pattern")
buildCmd.Flags().IntP("pattern-y", "y", 8, "The y offset of the initial pattern")
}