diff --git a/pkg/koyeb/koyeb.go b/pkg/koyeb/koyeb.go index 519f6c70..498644bd 100644 --- a/pkg/koyeb/koyeb.go +++ b/pkg/koyeb/koyeb.go @@ -30,7 +30,6 @@ var ( forceASCII bool debugFull bool debug bool - organization string loginCmd = &cobra.Command{ Use: "login", @@ -76,6 +75,7 @@ func GetRootCommand() *cobra.Command { return err } DetectUpdates() + organization := viper.GetString("organization") return SetupCLIContext(cmd, organization) }, } @@ -90,13 +90,11 @@ func GetRootCommand() *cobra.Command { rootCmd.PersistentFlags().BoolP("full", "", false, "do not truncate output") rootCmd.PersistentFlags().String("url", "https://app.koyeb.com", "url of the api") rootCmd.PersistentFlags().String("token", "", "API token") - rootCmd.PersistentFlags().StringVar(&organization, "organization", "", "organization ID") // viper.BindPFlag returns an error only if the second argument is nil, which is never the case here, so we ignore the error - viper.BindPFlag("url", rootCmd.PersistentFlags().Lookup("url")) //nolint:errcheck - viper.BindPFlag("token", rootCmd.PersistentFlags().Lookup("token")) //nolint:errcheck - viper.BindPFlag("debug", rootCmd.PersistentFlags().Lookup("debug")) //nolint:errcheck - viper.BindPFlag("organization", rootCmd.PersistentFlags().Lookup("organization")) //nolint:errcheck + viper.BindPFlag("url", rootCmd.PersistentFlags().Lookup("url")) //nolint:errcheck + viper.BindPFlag("token", rootCmd.PersistentFlags().Lookup("token")) //nolint:errcheck + viper.BindPFlag("debug", rootCmd.PersistentFlags().Lookup("debug")) //nolint:errcheck rootCmd.AddCommand(loginCmd) rootCmd.AddCommand(versionCmd) @@ -254,6 +252,5 @@ func initConfig(rootCmd *cobra.Command) error { apiurl = viper.GetString("url") token = viper.GetString("token") debug = viper.GetBool("debug") - organization = viper.GetString("organization") return nil } diff --git a/pkg/koyeb/organizations_list.go b/pkg/koyeb/organizations_list.go index e4eb3a24..9014f6ae 100644 --- a/pkg/koyeb/organizations_list.go +++ b/pkg/koyeb/organizations_list.go @@ -47,19 +47,8 @@ func (h *OrganizationHandler) List(ctx *CLIContext, cmd *cobra.Command, args []s } } - // ctx.Organization is empty when the field "organization" is not set in the - // configuration file, and is not provided with the --organization flag. - currentOrganization := ctx.Organization - if currentOrganization == "" { - res, resp, err := ctx.Client.ProfileApi.GetCurrentOrganization(ctx.Context).Execute() - if err != nil { - return errors.NewCLIErrorFromAPIError("Unable to fetch the current organization", err, resp) - } - currentOrganization = *res.Organization.Id - } - full := GetBoolFlags(cmd, "full") - reply := NewListOragnizationsReply(ctx.Mapper, &koyeb.ListOrganizationMembersReply{Members: list}, full, currentOrganization) + reply := NewListOragnizationsReply(ctx.Mapper, &koyeb.ListOrganizationMembersReply{Members: list}, full, ctx.Organization) ctx.Renderer.Render(reply) return nil } diff --git a/pkg/koyeb/organizations_switch.go b/pkg/koyeb/organizations_switch.go index 02ec486f..8a559c5c 100644 --- a/pkg/koyeb/organizations_switch.go +++ b/pkg/koyeb/organizations_switch.go @@ -12,7 +12,9 @@ func (h *OrganizationHandler) Switch(ctx *CLIContext, cmd *cobra.Command, args [ return err } viper.Set("organization", organization) - if err := viper.WriteConfig(); err != nil { + + err = viper.WriteConfig() + if err != nil { return &errors.CLIError{ What: "Unable to switch the current organization", Why: "we were unable to write the configuration file",