github.com/kunnos/engine@v1.13.1/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 addComposefileFlag(opt *string, flags *pflag.FlagSet) {
    13  	flags.StringVarP(opt, "compose-file", "c", "", "Path to a Compose file")
    14  }
    15  
    16  func addBundlefileFlag(opt *string, flags *pflag.FlagSet) {
    17  	flags.StringVar(opt, "bundle-file", "", "Path to a Distributed Application Bundle file")
    18  	flags.SetAnnotation("bundle-file", "experimental", nil)
    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  }