// Save saves the given profiles to the context file.
Save saves the given profiles to the context file.
// Save saves the given profiles to the context file .
func (c *File) Save(cfg *Context) error {
	file, err := c.Location()
	if err != nil {
		return err
	}
	data, err := json.MarshalIndent(cfg, "", "  ")
	if err != nil {
		return fmt.Errorf("%v: %w", "unable to marshal context", err)
	}
	rhoasCfgDir, err := DefaultDir()
	if err != nil {
		return err
	}
	if _, err = os.Stat(rhoasCfgDir); os.IsNotExist(err) {
		err = os.Mkdir(rhoasCfgDir, 0o700)
		if err != nil {
			return err
		}
	}
	err = ioutil.WriteFile(file, data, 0o600)
	if err != nil {
		return fmt.Errorf(errorFormat, "unable to save context", err)
	}
	return nil
}
func ( c * File ) Save ( cfg * Context ) error { file , err := c . Location ( ) if err != nil { return err } data , err := json . MarshalIndent ( cfg , " " , " " ) if err != nil { return fmt . Errorf ( " " , " " , err ) } rhoasCfgDir , err := DefaultDir ( ) if err != nil { return err } if _ , err = os . Stat ( rhoasCfgDir ) ; os . IsNotExist ( err ) { err = os . Mkdir ( rhoasCfgDir , 0o700 ) if err != nil { return err } } err = ioutil . WriteFile ( file , data , 0o600 ) if err != nil { return fmt . Errorf ( errorFormat , " " , err ) } return nil }
Save saves the given profiles to the context file.
Save saves the given profiles to the context file .