func (m *ConfigurationManager) Save() error {
	c := m.Config.Clone()  
	for _, v := range c.Contexts {
		v.FormatHost()
		if err := EncryptPassword(v); err != nil {
			return err
		}
	}
	out, err := api.ConfigMarshalYAML(c)
	if err != nil {  
		return fmt.Errorf("unable to marshal the configuration, error: [%v]", err)
	}
	if m.Filepath == "" {
		m.Filepath = DefaultConfigFilepath
	}
	directoryMode := os.FileMode(0750)
	os.MkdirAll(filepath.Dir(m.Filepath), directoryMode)
	fileMode := os.FileMode(0600)
	if err = ioutil.WriteFile(m.Filepath, out, fileMode); err != nil {
		return fmt.Errorf("unable to create the configuration file for your system, error: [%v]", err)
	}
	return nil
}
Save saves the configuration
package config
import (
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"
	"strings"
	"github.com/joho/godotenv"
	"github.com/lensesio/lenses-go/pkg/api"
	"github.com/lensesio/lenses-go/pkg/utils"
	"github.com/spf13/pflag"
)
var DefaultConfigFilepath = filepath.Join(api.DefaultConfigurationHomeDir, "lenses-cli.yml")
var Manager *ConfigurationManager
type ConfigurationManager struct {
	Config *api.Config
	CurrentContext, host, timeout, token, user, pass, kerberosConf, kerberosRealm, kerberosKeytab, kerberosCCache string
	insecure, debug                                                                                               bool
	Filepath string
}
func NewConfigurationManager(set *pflag.FlagSet) *ConfigurationManager {
	m := &ConfigurationManager{
		Config: &api.Config{
			Contexts: make(map[string]*api.ClientConfig),
		},
	}
	set.StringVar(&m.CurrentContext, "context", "", "Load specific environment, embedded configuration based on the configuration's 'Contexts'")
	set.StringVar(&m.host, "host", "", "Lenses host")
	set.StringVar(&m.user, "user", "", "User")
	set.StringVar(&m.pass, "pass", "", "Password")
	set.StringVar(&m.kerberosConf, "kerberos-conf", "", "krb5.conf")
	set.StringVar(&m.kerberosRealm, "kerberos-realm", "", "Kerberos realm")
	set.StringVar(&m.kerberosKeytab, "kerberos-keytab", "", "KeyTab file")
	set.StringVar(&m.kerberosCCache, "kerberos-ccache", "", "Kerberos keytab file")
	set.StringVar(&m.timeout, "timeout", "", "Timeout for the connection establishment")
	set.BoolVar(&m.insecure, "insecure", false, "All insecure http requests")
	set.StringVar(&m.token, "token", "", "Lenses auth token")
	set.BoolVar(&m.debug, "debug", false, "Print some information that are necessary for debugging")
	set.StringVar(&m.Filepath, "config", "", "Load or save the host, user, pass and debug fields from or to a configuration file (yaml or json)")
	return m
}
func NewEmptyConfigManager() *ConfigurationManager {
	return &ConfigurationManager{
		Config: &api.Config{
			Contexts: make(map[string]*api.ClientConfig),
		},
	}
}
const currentContextEnvKey = "LENSES_CLI_CONTEXT"
func (m *ConfigurationManager) Load() (bool, error) {
	c := m.Config
	var found bool
	if m.Filepath != "" {
		if err := api.TryReadConfigFromFile(m.Filepath, c); err != nil {
			return false, err
		}
		found = true
	} else if found = api.TryReadConfigFromCurrentWorkingDir(c); found {
	} else if found = api.TryReadConfigFromExecutable(c); found {
	} else if found = api.TryReadConfigFromHome(c); found {
	}
	currentContext := c.CurrentContext
	currentContextChanged := false
	if flag := m.CurrentContext; flag != "" && flag != currentContext {
		currentContext = flag
		currentContextChanged = true
	} else if currentContext == "" {
		currentContext = api.DefaultContextKey
	}
	c.SetCurrent(currentContext)
	authFromFlags, authLoadedFromFlags := makeAuthFromFlags(m.user, m.pass, m.kerberosConf, m.kerberosRealm, m.kerberosKeytab, m.kerberosCCache)
	if authLoadedFromFlags {
		c.GetCurrent().Authentication = authFromFlags
	}
	c.GetCurrent().Fill(api.ClientConfig{
		Host:     m.host,
		Token:    m.token,
		Timeout:  m.timeout,
		Insecure: m.insecure,
		Debug:    m.debug,
	})
	if found {
		if currentContextChanged {
			for _, v := range c.Contexts {
				DecryptPassword(v)
			}
			if err := m.Save(); err != nil {
				return false, err
			}
		} else {
			if !authLoadedFromFlags {
				godotenv.Load()
				if envContext := strings.TrimSpace(os.Getenv(currentContextEnvKey)); envContext != "" {
					c.CurrentContext = envContext
				}
				for _, v := range c.Contexts {
					DecryptPassword(v)
				}
			}
		}
	}
	if c.CurrentContext != "" && !c.CurrentContextExists() {
		return false, fmt.Errorf("unknown context [%s] given, please use the `configure --context="+c.CurrentContext+" --reset`", c.CurrentContext)
	}
	return c.IsValid(), nil
}