-
Notifications
You must be signed in to change notification settings - Fork 530
/
Copy pathexport.go
64 lines (52 loc) · 1.58 KB
/
export.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
package d2cli
import (
"fmt"
"path/filepath"
"strings"
)
type exportExtension string
const GIF exportExtension = ".gif"
const PNG exportExtension = ".png"
const PPTX exportExtension = ".pptx"
const PDF exportExtension = ".pdf"
const SVG exportExtension = ".svg"
const ASCII exportExtension = ".txt"
var SUPPORTED_EXTENSIONS = []exportExtension{ASCII, SVG, PNG, PDF, PPTX, GIF}
var STDOUT_FORMAT_MAP = map[string]exportExtension{
"png": PNG,
"svg": SVG,
"ascii": ASCII,
}
var SUPPORTED_STDOUT_FORMATS = []string{"png", "svg", "ascii"}
func getOutputFormat(stdoutFormatFlag *string, outputPath string) (exportExtension, error) {
if stdoutFormatFlag != nil && *stdoutFormatFlag != "" {
format := strings.ToLower(*stdoutFormatFlag)
if ext, ok := STDOUT_FORMAT_MAP[format]; ok {
return ext, nil
}
return "", fmt.Errorf("%s is not a supported format. Supported formats are: %s", *stdoutFormatFlag, SUPPORTED_STDOUT_FORMATS)
}
return getExportExtension(outputPath), nil
}
func getExportExtension(outputPath string) exportExtension {
ext := filepath.Ext(outputPath)
for _, kext := range SUPPORTED_EXTENSIONS {
if kext == exportExtension(ext) {
return exportExtension(ext)
}
}
// default is svg
return exportExtension(SVG)
}
func (ex exportExtension) supportsAnimation() bool {
return ex == SVG || ex == GIF
}
func (ex exportExtension) requiresAnimationInterval() bool {
return ex == GIF
}
func (ex exportExtension) requiresPNGRenderer() bool {
return ex == PNG || ex == PDF || ex == PPTX || ex == GIF
}
func (ex exportExtension) supportsDarkTheme() bool {
return ex == SVG
}