-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.go
More file actions
79 lines (72 loc) · 2.35 KB
/
main.go
File metadata and controls
79 lines (72 loc) · 2.35 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
package main
import (
"errors"
"flag"
"fmt"
"io"
"log"
"os"
"github.com/CustomResourceDefinition/catalog/internal/command"
)
const commandCompare = "compare"
const commandUpdate = "update"
const commandVerify = "verify"
func main() {
err := run(os.Args, nil)
if err != nil {
log.Fatal(err)
}
}
func run(args []string, logger io.Writer) error {
cmd, err := parse(args, logger)
if err != nil {
return err
}
return cmd.Run()
}
func parse(args []string, logger io.Writer) (command.Command, error) {
if len(args) < 2 {
return nil, command.ErrNoArguments
}
arg := args[1]
switch arg {
case commandCompare:
cmd := flag.NewFlagSet(commandCompare, flag.ContinueOnError)
datreeio := cmd.String("datreeio", "", "Path of checked out remote datreeio directory")
current := cmd.String("current", "", "Path of local schema directory")
ignore := cmd.String("ignore", "", "Path of ignore configuration")
output := cmd.String("out", "", "Path of output markdown file")
cmd.SetOutput(logger)
err := cmd.Parse(args[2:])
if err != nil {
return nil, err
}
return command.NewComparer(*datreeio, *current, *output, *ignore, cmd), nil
case commandUpdate:
cmd := flag.NewFlagSet(commandUpdate, flag.ContinueOnError)
configuration := cmd.String("configuration", "", "Path to configuration file for CRD sources")
schema := cmd.String("output", "", "Path of directory for openapi schema output files")
definitions := cmd.String("definitions", "", "Path of directory for definition output files")
registry := cmd.String("registry", "", "Path to registry file for tracking source versions")
performance := cmd.String("performance-log", "", "Path to performance log file")
cmd.SetOutput(logger)
err := cmd.Parse(args[2:])
if err != nil {
return nil, err
}
updater := command.NewUpdater(*configuration, *schema, *definitions, *registry, *performance, logger, cmd)
return updater, nil
case commandVerify:
cmd := flag.NewFlagSet(commandVerify, flag.ContinueOnError)
schema := cmd.String("schema", "", "Path of jsonschema file to use")
file := cmd.String("file", "", "Path of file to check")
cmd.SetOutput(logger)
err := cmd.Parse(args[2:])
if err != nil {
return nil, err
}
return command.NewVerifier(*schema, *file, cmd), nil
default:
return nil, errors.Join(command.ErrUnknownCommand, fmt.Errorf("unknown arguments: %s", arg))
}
}