-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.go
152 lines (145 loc) · 3.89 KB
/
main.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package main
import (
"fmt"
"os"
cli "github.com/urfave/cli/v2"
)
const (
defaultMargin = 1
defaultColumns = 16
)
const (
extraDataUsage = `Extra data to add to the font. Either as a yaml file or as a string.
This can be used to to store metadata in the non visible region of a character
or to define entire characters used for data storage.
For an example file, see https://github.com/fiam/max7456tool/example_data.yaml
Multiple files can be combined by repeating this flag.`
)
var (
verboseFlag = false
debugFlag = false
appVersion string
)
func main() {
app := cli.NewApp()
app.Version = appVersion
buildAndGenerateFlags := []cli.Flag{
&cli.BoolFlag{
Name: "no-blanks",
Aliases: []string{"nb"},
Usage: "Don't fill missing characters with blanks (used only for directory input)",
},
&cli.IntFlag{
Name: "margin",
Aliases: []string{"m"},
Value: defaultMargin,
Usage: "Margin between each character (used only for image input)",
},
&cli.IntFlag{
Name: "columns",
Aliases: []string{"c"},
Value: defaultColumns,
Usage: "Number of columns in the output image (used only for image input)",
},
}
var buildFlags []cli.Flag
buildFlags = append(buildFlags, buildAndGenerateFlags...)
buildFlags = append(buildFlags, &cli.StringSliceFlag{
Name: "extra",
Aliases: []string{"e"},
Usage: extraDataUsage,
})
var generateFlags []cli.Flag
generateFlags = append(generateFlags, buildAndGenerateFlags...)
generateFlags = append(generateFlags, &cli.BoolFlag{
Name: "remove-duplicates",
Usage: "Remove duplicate characters that are the same in the child and parent font",
})
app.Usage = "tool for managing .mcm character sets for MAX7456"
app.Flags = []cli.Flag{
&cli.BoolFlag{
Name: "force",
Aliases: []string{"f"},
Usage: "Overwrite output files without asking",
Destination: &forceFlag,
},
&cli.BoolFlag{
Name: "verbose",
Aliases: []string{"V"},
Usage: "Enable verbose output",
Destination: &verboseFlag,
},
&cli.BoolFlag{
Name: "debug",
Aliases: []string{"d"},
Usage: "Print debug messages",
Destination: &debugFlag,
},
}
app.Commands = []*cli.Command{
{
Name: "extract",
Usage: "Extract all characters to individual images",
ArgsUsage: "<input.mcm> <output-dir>",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "add-blanks",
Aliases: []string{"b"},
Usage: "Include blank characters in the extracted files",
},
},
Action: extractAction,
},
{
Name: "build",
Usage: "Build a .mcm from the files in the given directory or .png file",
ArgsUsage: "<input> <output.mcm>",
Flags: buildFlags,
Action: buildAction,
},
{
Name: "generate",
Usage: "Generate multiple fonts from a fonts.yaml file",
ArgsUsage: "<fonts.yaml> # See an example at https://github.com/fiam/max7456tool/example_fonts.yaml",
Flags: generateFlags,
Action: generateAction,
},
{
Name: "png",
Usage: "Generate a .png from an .mcm",
ArgsUsage: "<input.mcm> <output.png>",
Flags: []cli.Flag{
&cli.IntFlag{
Name: "margin",
Aliases: []string{"m"},
Value: defaultMargin,
Usage: "Margin between each character",
},
&cli.IntFlag{
Name: "columns",
Aliases: []string{"c"},
Value: defaultColumns,
Usage: "Number of columns in the output image",
},
},
Action: pngAction,
},
{
Name: "bin",
Usage: "Generate a raw .bin font file from a .mcm",
ArgsUsage: "<input.mcm> <output.bin>",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: flipHorizontalPixelsFlagName,
Aliases: []string{"fhp"},
Usage: "Flip order of horizontal pixels in each row",
},
},
Action: binAction,
},
}
if err := app.Run(os.Args); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}