github.com/omnigres/cli@v0.1.4/cmd/psql.go (about)

     1  package cmd
     2  
     3  import (
     4  	"context"
     5  	"github.com/charmbracelet/log"
     6  	"github.com/omnigres/cli/orb"
     7  	"github.com/spf13/cobra"
     8  )
     9  
    10  var database string = "omnigres"
    11  
    12  var psqlCmd = &cobra.Command{
    13  	Use:   "psql",
    14  	Short: "Connect to the cluster using psql",
    15  	Run: func(cmd *cobra.Command, args []string) {
    16  		var cluster orb.OrbCluster
    17  		var err error
    18  		cluster, err = getOrbCluster()
    19  		if err != nil {
    20  			log.Fatal(err)
    21  		}
    22  		ctx := context.Background()
    23  		err = cluster.ConnectPsql(ctx, database)
    24  		if err != nil {
    25  			log.Fatal(err)
    26  		}
    27  	},
    28  }
    29  
    30  func init() {
    31  	rootCmd.AddCommand(psqlCmd)
    32  	psqlCmd.Flags().StringVarP(&database, "database", "d", "omnigres", "Database to connect to")
    33  }