import ( "github.com/cloudfoundry/cli/cf/configuration" "fmt" ) configRepo := configuration.NewRepositoryFromFilepath() org, err := configRepo.Organization() if err != nil { fmt.Printf("Error reading target org: %s", err) } else { fmt.Printf("Target org: %s", org.Name) }
import ( "github.com/cloudfoundry/cli/cf/configuration" "fmt" ) configRepo := configuration.NewRepositoryFromFilepath() config, err := configRepo.Get() if err != nil { fmt.Printf("Error reading CLI config: %s", err) } else { config.APIEndpoint = "https://api.example.com" err = configRepo.Save() if err != nil { fmt.Printf("Error saving CLI config: %s", err) } else { fmt.Println("API endpoint saved") } }This code creates a configuration repository from the default CLI configuration file, reads the configuration from it, sets the API endpoint to a new value, and saves the updated configuration. If there was an error reading or saving the configuration, it prints an error message. Otherwise, it prints a message indicating that the API endpoint was saved.