github.com/taubyte/tau-cli@v0.1.13-0.20240326000942-487f0d57edfc/singletons/config/profiles.go (about) 1 package config 2 3 import ( 4 "github.com/taubyte/go-seer" 5 "github.com/taubyte/tau-cli/i18n" 6 singletonsI18n "github.com/taubyte/tau-cli/i18n/singletons" 7 ) 8 9 func Profiles() *profileHandler { 10 getOrCreateConfig() 11 12 return &profileHandler{} 13 } 14 15 func (p *profileHandler) Root() *seer.Query { 16 return _config.Document().Get(singletonsI18n.ProfilesKey).Fork() 17 } 18 19 func (p *profileHandler) Get(name string) (profile Profile, err error) { 20 err = p.Root().Get(name).Value(&profile) 21 if err != nil { 22 err = singletonsI18n.GettingProfileFailedWith(name, err) 23 return 24 } 25 26 profile.name = name 27 return profile, nil 28 } 29 30 func (p *profileHandler) Set(name string, profile Profile) error { 31 err := p.Root().Get(name).Set(profile).Commit() 32 if err != nil { 33 return singletonsI18n.SettingProfileFailedWith(name, err) 34 } 35 36 return _config.root.Sync() 37 } 38 39 func (p *profileHandler) List(loginCommand bool) (profiles map[string]Profile) { 40 // Ignoring error here as it will just return an empty map 41 err := p.Root().Value(&profiles) 42 if err != nil && !loginCommand { 43 i18n.Help().HaveYouLoggedIn() 44 } 45 46 return profiles 47 }