opts.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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.StringVarP(opt, "compose-file", "c", "", "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. flags.SetAnnotation("bundle-file", "experimental", nil)
  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. }