Skip to content

Commit

Permalink
Revert "Add --organization and fix list when the flag is not set"
Browse files Browse the repository at this point in the history
This reverts commit e117dc0.
  • Loading branch information
brmzkw committed Aug 18, 2023
1 parent 86cfe30 commit 628d9c8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 20 deletions.
11 changes: 4 additions & 7 deletions pkg/koyeb/koyeb.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ var (
forceASCII bool
debugFull bool
debug bool
organization string

loginCmd = &cobra.Command{
Use: "login",
Expand Down Expand Up @@ -76,6 +75,7 @@ func GetRootCommand() *cobra.Command {
return err
}
DetectUpdates()
organization := viper.GetString("organization")
return SetupCLIContext(cmd, organization)
},
}
Expand All @@ -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)
Expand Down Expand Up @@ -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
}
13 changes: 1 addition & 12 deletions pkg/koyeb/organizations_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/koyeb/organizations_switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 628d9c8

Please sign in to comment.