opts.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package stack
  2. import (
  3. "fmt"
  4. "io"
  5. "os"
  6. "github.com/docker/docker/cli/command/bundlefile"
  7. "github.com/spf13/pflag"
  8. )
  9. func addComposefileFlag(opt *string, flags *pflag.FlagSet) {
  10. flags.StringVar(opt, "compose-file", "", "Path to a Compose file")
  11. }
  12. func addBundlefileFlag(opt *string, flags *pflag.FlagSet) {
  13. flags.StringVar(opt, "bundle-file", "", "Path to a Distributed Application Bundle file")
  14. }
  15. func addRegistryAuthFlag(opt *bool, flags *pflag.FlagSet) {
  16. flags.BoolVar(opt, "with-registry-auth", false, "Send registry authentication details to Swarm agents")
  17. }
  18. func loadBundlefile(stderr io.Writer, namespace string, path string) (*bundlefile.Bundlefile, error) {
  19. defaultPath := fmt.Sprintf("%s.dab", namespace)
  20. if path == "" {
  21. path = defaultPath
  22. }
  23. if _, err := os.Stat(path); err != nil {
  24. return nil, fmt.Errorf(
  25. "Bundle %s not found. Specify the path with --file",
  26. path)
  27. }
  28. fmt.Fprintf(stderr, "Loading bundle from %s\n", path)
  29. reader, err := os.Open(path)
  30. if err != nil {
  31. return nil, err
  32. }
  33. defer reader.Close()
  34. bundle, err := bundlefile.LoadFile(reader)
  35. if err != nil {
  36. return nil, fmt.Errorf("Error reading %s: %v\n", path, err)
  37. }
  38. return bundle, err
  39. }