Merge branch '8784-dir-listings'
[arvados.git] / sdk / go / config / dump.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: Apache-2.0
4
5 package config
6
7 import (
8         "errors"
9         "os"
10
11         "github.com/ghodss/yaml"
12 )
13
14 // DumpAndExit writes the given config to stdout as YAML. If an error
15 // occurs, that error is returned. Otherwise, the program exits 0.
16 //
17 // Example:
18 //
19 //      log.Fatal(DumpAndExit(cfg))
20 func DumpAndExit(cfg interface{}) error {
21         y, err := yaml.Marshal(cfg)
22         if err != nil {
23                 return err
24         }
25         _, err = os.Stdout.Write(y)
26         if err != nil {
27                 return err
28         }
29         os.Exit(0)
30         return errors.New("exit failed!?")
31 }