Skip to content

Commit

Permalink
fix(cmd): Fix db and table name completions
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Feb 17, 2024
1 parent df4e5e0 commit 0f06f97
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 2 additions & 0 deletions internal/config/flags/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func BindAnalyze(cmd *cobra.Command) {
func listTables(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
conf := config.Exec{DisableHeaders: true}

viper.Set(consts.NoJobKey, true)
err := util.DefaultSetup(cmd, &conf.Global, util.SetupOptions{})
if err != nil {
return nil, cobra.ShellCompDirectiveError
Expand All @@ -133,6 +134,7 @@ func listTables(cmd *cobra.Command, args []string, toComplete string) ([]string,
func listDatabases(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
conf := config.Exec{DisableHeaders: true}

viper.Set(consts.NoJobKey, true)
err := util.DefaultSetup(cmd, &conf.Global, util.SetupOptions{})
if err != nil {
return nil, cobra.ShellCompDirectiveError
Expand Down
14 changes: 9 additions & 5 deletions internal/util/cmd_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ func DefaultSetup(cmd *cobra.Command, conf *config.Global, opts SetupOptions) (e

if len(pods) == 1 {
conf.DbPod = pods[0]
conf.JobPod = pods[0]
} else {
names := make([]string, 0, len(pods))
for _, pod := range pods {
Expand Down Expand Up @@ -213,14 +212,19 @@ func DefaultSetup(cmd *cobra.Command, conf *config.Global, opts SetupOptions) (e
return nil
})

group.Go(func() error {
if viper.GetBool(consts.NoJobKey) {
conf.Host = "127.0.0.1"
conf.JobPod = conf.DbPod
}
return nil
})

return group.Wait()
}

func CreateJob(cmd *cobra.Command, conf *config.Global, opts SetupOptions) error {
if viper.GetBool(consts.NoJobKey) {
conf.Host = "127.0.0.1"
conf.JobPod = conf.DbPod
} else {
if !viper.GetBool(consts.NoJobKey) {
if err := createJob(cmd, conf, opts.Name); err != nil {
return err
}
Expand Down

0 comments on commit 0f06f97

Please sign in to comment.