1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
15 "git.curoverse.com/arvados.git/sdk/go/ctxlog"
16 "github.com/ghodss/yaml"
19 var DumpCommand dumpCommand
21 type dumpCommand struct{}
23 func (dumpCommand) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
27 fmt.Fprintf(stderr, "%s\n", err)
31 err = fmt.Errorf("usage: %s <config-src.yaml >config-min.yaml", prog)
34 log := ctxlog.New(stderr, "text", "info")
35 cfg, err := Load(stdin, log)
39 out, err := yaml.Marshal(cfg)
43 _, err = stdout.Write(out)
50 var CheckCommand checkCommand
52 type checkCommand struct{}
54 func (checkCommand) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
58 fmt.Fprintf(stderr, "%s\n", err)
62 err = fmt.Errorf("usage: %s <config-src.yaml && echo 'no changes needed'", prog)
65 log := &plainLogger{w: stderr}
66 buf, err := ioutil.ReadAll(stdin)
70 withoutDepr, err := load(bytes.NewBuffer(buf), log, false)
74 withDepr, err := load(bytes.NewBuffer(buf), nil, true)
78 cmd := exec.Command("diff", "-u", "--label", "without-deprecated-configs", "--label", "relying-on-deprecated-configs", "/dev/fd/3", "/dev/fd/4")
79 for _, obj := range []interface{}{withoutDepr, withDepr} {
80 y, _ := yaml.Marshal(obj)
81 pr, pw, err := os.Pipe()
87 io.Copy(pw, bytes.NewBuffer(y))
90 cmd.ExtraFiles = append(cmd.ExtraFiles, pr)
92 diff, err := cmd.CombinedOutput()
93 if bytes.HasPrefix(diff, []byte("--- ")) {
94 fmt.Fprintln(stdout, "Your configuration is relying on deprecated entries. Suggest making the following changes.")
97 } else if len(diff) > 0 {
98 fmt.Fprintf(stderr, "Unexpected diff output:\n%s", diff)
100 } else if err != nil {
109 type plainLogger struct {
114 func (pl *plainLogger) Warnf(format string, args ...interface{}) {
116 fmt.Fprintf(pl.w, format+"\n", args...)