1
0
mirror of https://github.com/rancher/rke.git synced 2025-06-25 06:53:02 +00:00
rke/cmd/common.go

30 lines
673 B
Go
Raw Normal View History

package cmd
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"github.com/urfave/cli"
)
2017-12-16 03:38:15 +00:00
func resolveClusterFile(ctx *cli.Context) (string, string, error) {
clusterFile := ctx.String("config")
fp, err := filepath.Abs(clusterFile)
if err != nil {
2017-12-16 03:38:15 +00:00
return "", "", fmt.Errorf("failed to lookup current directory name: %v", err)
}
file, err := os.Open(fp)
if err != nil {
2017-12-16 03:38:15 +00:00
return "", "", fmt.Errorf("Can not find cluster configuration file: %v", err)
}
defer file.Close()
buf, err := ioutil.ReadAll(file)
if err != nil {
2017-12-16 03:38:15 +00:00
return "", "", fmt.Errorf("failed to read file: %v", err)
}
clusterFileBuff := string(buf)
2017-12-16 03:38:15 +00:00
return clusterFileBuff, clusterFile, nil
}