-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.go
More file actions
87 lines (74 loc) · 2.32 KB
/
common.go
File metadata and controls
87 lines (74 loc) · 2.32 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
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
package main
import (
"errors"
"github.com/spf13/pflag"
)
// flag is used as a common flag representation where flags can be specified that are re-used across commands.
// See pflag.StringP for details about these attributes
type flag struct {
Name string
Short string
Value any
Usage string
}
// Apply to pflag.FlagSet basic on type of flag.Value or panic if unknown type
func (f *flag) Apply(flagSet *pflag.FlagSet) {
switch f.Value.(type) {
case string:
flagSet.StringP(f.Name, f.Short, f.Value.(string), f.Usage)
case []string:
flagSet.StringSliceP(f.Name, f.Short, f.Value.([]string), f.Usage)
case bool:
flagSet.BoolP(f.Name, f.Short, f.Value.(bool), f.Usage)
case int:
flagSet.IntP(f.Name, f.Short, f.Value.(int), f.Usage)
default:
panic("unknown type")
}
}
var outputFlag = flag{
Name: "output",
Short: "o",
Value: "diagram.%s", // first %s is substituted by the default extension
Usage: "Optionally set the location of the output file",
}
var globsFlag = flag{
Name: "globs",
Short: "g",
Value: []string{},
Usage: "glob patterns to match (e.g. '**/*.json', '*.json', 'file.json')",
}
var baseURIFlag = flag{
Name: "base-uri",
Short: "",
Value: "",
Usage: "when provided the base-uri will be used to resolve json schemas using the $id property. If the schema does not start with 'http' or 'https' it's assumed to be a 'file://' reference",
}
var allowOverwriteFlag = flag{
Name: "overwrite",
Short: "",
Value: false,
Usage: "if provided allows existing files to be overwritten (i.e. regenerate)",
}
var toolFlag = flag{
Name: "tool",
Short: "",
Value: "",
Usage: "path to the tool to render the 'd2' file, if empty 'which d2' is used",
}
var containerBasePathFlag = flag{
Name: "container-base-path",
Short: "",
Value: "",
Usage: "can only be used in conjunction with a file based --base-uri, if set will put classes in containers representing directories",
}
var depthFlag = flag{
Name: "depth",
Short: "",
Value: -1,
Usage: "max depth of external $refs that can be followed from a glob reference schema",
}
// ErrNoGlobs is returned when no globs are provided (which is a no-op)
var ErrNoGlobs = errors.New("no globs provided")
// ErrNoOverwrite is returned when a file would be overwritten which is not allowed
var ErrNoOverwrite = errors.New("file exists but overwrite of file is not allowed")