opts.go 911 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // +build experimental
  2. package stack
  3. import (
  4. "fmt"
  5. "io"
  6. "os"
  7. "github.com/docker/docker/api/client/bundlefile"
  8. "github.com/spf13/pflag"
  9. )
  10. func addBundlefileFlag(opt *string, flags *pflag.FlagSet) {
  11. flags.StringVarP(
  12. opt,
  13. "bundle", "f", "",
  14. "Path to a bundle (Default: STACK.dsb)")
  15. }
  16. func loadBundlefile(stderr io.Writer, namespace string, path string) (*bundlefile.Bundlefile, error) {
  17. defaultPath := fmt.Sprintf("%s.dsb", namespace)
  18. if path == "" {
  19. path = defaultPath
  20. }
  21. if _, err := os.Stat(path); err != nil {
  22. return nil, fmt.Errorf(
  23. "Bundle %s not found. Specify the path with -f or --bundle",
  24. path)
  25. }
  26. fmt.Fprintf(stderr, "Loading bundle from %s\n", path)
  27. reader, err := os.Open(path)
  28. if err != nil {
  29. return nil, err
  30. }
  31. bundle, err := bundlefile.LoadFile(reader)
  32. if err != nil {
  33. return nil, fmt.Errorf("Error reading %s: %v\n", path, err)
  34. }
  35. return bundle, err
  36. }