github.com/vieux/docker@v0.6.3-0.20161004191708-e097c2a938c7/cli/command/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/cli/command/bundlefile"
    11  	"github.com/spf13/pflag"
    12  )
    13  
    14  func addBundlefileFlag(opt *string, flags *pflag.FlagSet) {
    15  	flags.StringVar(
    16  		opt,
    17  		"file", "",
    18  		"Path to a Distributed Application Bundle file (Default: STACK.dab)")
    19  }
    20  
    21  func addRegistryAuthFlag(opt *bool, flags *pflag.FlagSet) {
    22  	flags.BoolVar(opt, "with-registry-auth", false, "Send registry authentication details to Swarm agents")
    23  }
    24  
    25  func loadBundlefile(stderr io.Writer, namespace string, path string) (*bundlefile.Bundlefile, error) {
    26  	defaultPath := fmt.Sprintf("%s.dab", namespace)
    27  
    28  	if path == "" {
    29  		path = defaultPath
    30  	}
    31  	if _, err := os.Stat(path); err != nil {
    32  		return nil, fmt.Errorf(
    33  			"Bundle %s not found. Specify the path with --file",
    34  			path)
    35  	}
    36  
    37  	fmt.Fprintf(stderr, "Loading bundle from %s\n", path)
    38  	reader, err := os.Open(path)
    39  	if err != nil {
    40  		return nil, err
    41  	}
    42  	defer reader.Close()
    43  
    44  	bundle, err := bundlefile.LoadFile(reader)
    45  	if err != nil {
    46  		return nil, fmt.Errorf("Error reading %s: %v\n", path, err)
    47  	}
    48  	return bundle, err
    49  }