// LoadProfile loads a user configuration
// from ~/.mesos-cli.json creating a
// JSON file with defaults if it does
// not exist.
LoadProfile loads a user configuration
from ~/.mesos-cli.json creating a
JSON file with defaults if it does
not exist.
// LoadProfile loads a user configuration // from ~ / . mesos - cli . json creating a // JSON file with defaults if it does // not exist .
func LoadProfile(path, name string) (profile *Profile, err error) {
	config := &Config{Profiles: map[string]*Profile{}}
	if _, err = os.Stat(path); os.IsNotExist(err) {
		config.Profiles["default"] = defaults()
		raw, err := json.MarshalIndent(config, "", "  ")
		if err != nil {
			return nil, err
		}
		err = ioutil.WriteFile(path, raw, os.FileMode(0755))
		if err != nil {
			return nil, err
		}
		profile = config.Profiles["default"]
	} else {
		raw, err := ioutil.ReadFile(path)
		if err != nil {
			return nil, err
		}
		if err = json.Unmarshal(raw, &config); err != nil {
			return nil, err
		}
		if _, ok := config.Profiles[name]; !ok {
			return nil, fmt.Errorf("Cannot load profile: %s", name)
		}
		profile = config.Profiles[name]
	}
	return profile, nil
}
func LoadProfile ( path , name string ) ( profile * Profile , err error ) { config := & Config { Profiles : map [ string ] * Profile { } } if _ , err = os . Stat ( path ) ; os . IsNotExist ( err ) { config . Profiles [ " " ] = defaults ( ) raw , err := json . MarshalIndent ( config , " " , " " ) if err != nil { return nil , err } err = ioutil . WriteFile ( path , raw , os . FileMode ( 0755 ) ) if err != nil { return nil , err } profile = config . Profiles [ " " ] } else { raw , err := ioutil . ReadFile ( path ) if err != nil { return nil , err } if err = json . Unmarshal ( raw , & config ) ; err != nil { return nil , err } if _ , ok := config . Profiles [ name ] ; ! ok { return nil , fmt . Errorf ( " " , name ) } profile = config . Profiles [ name ] } return profile , nil }
LoadProfile loads a user configuration
from ~/.mesos-cli.json creating a
JSON file with defaults if it does
not exist.
LoadProfile loads a user configuration from ~ / . mesos - cli . json creating a JSON file with defaults if it does not exist .