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