github.com/kobeld/docker@v1.12.0-rc1/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 bundle (Default: STACK.dsb)")
    19  }
    20  
    21  func loadBundlefile(stderr io.Writer, namespace string, path string) (*bundlefile.Bundlefile, error) {
    22  	defaultPath := fmt.Sprintf("%s.dsb", 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  	bundle, err := bundlefile.LoadFile(path)
    35  	if err != nil {
    36  		return nil, fmt.Errorf("Error reading %s: %v\n", path, err)
    37  	}
    38  	return bundle, err
    39  }