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"
17 "github.com/sirupsen/logrus"
20 var DumpCommand dumpCommand
22 type dumpCommand struct{}
24 func (dumpCommand) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
28 fmt.Fprintf(stderr, "%s\n", err)
34 Logger: ctxlog.New(stderr, "text", "info"),
37 flags := flag.NewFlagSet("", flag.ContinueOnError)
38 flags.SetOutput(stderr)
39 loader.SetupFlags(flags)
41 err = flags.Parse(args)
42 if err == flag.ErrHelp {
45 } else if err != nil {
49 if len(flags.Args()) != 0 {
54 cfg, err := loader.Load()
58 out, err := yaml.Marshal(cfg)
62 _, err = stdout.Write(out)
69 var CheckCommand checkCommand
71 type checkCommand struct{}
73 func (checkCommand) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
75 var logbuf = &bytes.Buffer{}
77 io.Copy(stderr, logbuf)
79 fmt.Fprintf(stderr, "%s\n", err)
83 logger := logrus.New()
90 flags := flag.NewFlagSet("", flag.ContinueOnError)
91 flags.SetOutput(stderr)
92 loader.SetupFlags(flags)
94 err = flags.Parse(args)
95 if err == flag.ErrHelp {
98 } else if err != nil {
102 if len(flags.Args()) != 0 {
107 loader.SkipDeprecated = true
108 withoutDepr, err := loader.Load()
112 loader.SkipDeprecated = false
113 withDepr, err := loader.Load()
117 cmd := exec.Command("diff", "-u", "--label", "without-deprecated-configs", "--label", "relying-on-deprecated-configs", "/dev/fd/3", "/dev/fd/4")
118 for _, obj := range []interface{}{withoutDepr, withDepr} {
119 y, _ := yaml.Marshal(obj)
120 pr, pw, err := os.Pipe()
126 io.Copy(pw, bytes.NewBuffer(y))
129 cmd.ExtraFiles = append(cmd.ExtraFiles, pr)
131 diff, err := cmd.CombinedOutput()
132 if bytes.HasPrefix(diff, []byte("--- ")) {
133 fmt.Fprintln(stdout, "Your configuration is relying on deprecated entries. Suggest making the following changes.")
137 } else if len(diff) > 0 {
138 fmt.Fprintf(stderr, "Unexpected diff output:\n%s", diff)
140 } else if err != nil {
143 if logbuf.Len() > 0 {
149 var DumpDefaultsCommand defaultsCommand
151 type defaultsCommand struct{}
153 func (defaultsCommand) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
154 _, err := stdout.Write(DefaultYAML)
156 fmt.Fprintln(stderr, err)