1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/api/client/stack/opts.go
Vincent Demeester 10919e8909
Add documentation for stack commands
Also removes the `-f` flags of bundle to follow the single-letter flags
evaluation.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
2016-07-19 18:32:44 +02:00

45 lines
956 B
Go

// +build experimental
package stack
import (
"fmt"
"io"
"os"
"github.com/docker/docker/api/client/bundlefile"
"github.com/spf13/pflag"
)
func addBundlefileFlag(opt *string, flags *pflag.FlagSet) {
flags.StringVar(
opt,
"bundle", "",
"Path to a Distributed Application Bundle file (Default: STACK.dab)")
}
func loadBundlefile(stderr io.Writer, namespace string, path string) (*bundlefile.Bundlefile, error) {
defaultPath := fmt.Sprintf("%s.dab", namespace)
if path == "" {
path = defaultPath
}
if _, err := os.Stat(path); err != nil {
return nil, fmt.Errorf(
"Bundle %s not found. Specify the path with -f or --bundle",
path)
}
fmt.Fprintf(stderr, "Loading bundle from %s\n", path)
reader, err := os.Open(path)
if err != nil {
return nil, err
}
defer reader.Close()
bundle, err := bundlefile.LoadFile(reader)
if err != nil {
return nil, fmt.Errorf("Error reading %s: %v\n", path, err)
}
return bundle, err
}