opts.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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.StringVar(
  12. opt,
  13. "file", "",
  14. "Path to a Distributed Application Bundle file (Default: STACK.dab)")
  15. }
  16. func addRegistryAuthFlag(opt *bool, flags *pflag.FlagSet) {
  17. flags.BoolVar(opt, "with-registry-auth", false, "Send registry authentication details to Swarm agents")
  18. }
  19. func loadBundlefile(stderr io.Writer, namespace string, path string) (*bundlefile.Bundlefile, error) {
  20. defaultPath := fmt.Sprintf("%s.dab", namespace)
  21. if path == "" {
  22. path = defaultPath
  23. }
  24. if _, err := os.Stat(path); err != nil {
  25. return nil, fmt.Errorf(
  26. "Bundle %s not found. Specify the path with --file",
  27. path)
  28. }
  29. fmt.Fprintf(stderr, "Loading bundle from %s\n", path)
  30. reader, err := os.Open(path)
  31. if err != nil {
  32. return nil, err
  33. }
  34. defer reader.Close()
  35. bundle, err := bundlefile.LoadFile(reader)
  36. if err != nil {
  37. return nil, fmt.Errorf("Error reading %s: %v\n", path, err)
  38. }
  39. return bundle, err
  40. }