github.com/kim0/docker@v0.6.2-0.20161130212042-4addda3f07e7/cli/command/stack/opts.go (about)

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