opts.go 1.3 KB

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