From 196517a9d068c2a6857309c60f738ce4aabced16 Mon Sep 17 00:00:00 2001 From: ytimocin Date: Sat, 18 Jan 2025 14:27:56 -0800 Subject: [PATCH] Renaming packages Signed-off-by: ytimocin --- .../app/{connection => conn}/cloud/cloud.go | 4 +- .../app/{connection => conn}/cloud/create.go | 16 ++-- .../app/{connection => conn}/cloud/delete.go | 6 +- .../app/{connection => conn}/cloud/list.go | 4 +- .../app/{connection => conn}/cloud/open.go | 14 +-- .../app/{connection => conn}/cloud/types.go | 4 +- .../app/{connection => conn}/connection.go | 12 +-- cmd/pops/app/{connection => conn}/create.go | 8 +- .../app/{connection => conn}/db/create.go | 2 +- cmd/pops/app/{connection => conn}/db/db.go | 0 .../app/{connection => conn}/db/delete.go | 6 +- cmd/pops/app/{connection => conn}/db/list.go | 4 +- cmd/pops/app/{connection => conn}/db/open.go | 2 +- cmd/pops/app/{connection => conn}/db/types.go | 4 +- cmd/pops/app/{connection => conn}/delete.go | 2 +- .../{connection => conn}/factory/create.go | 8 +- .../app/{connection => conn}/factory/doc.go | 0 .../app/{connection => conn}/factory/open.go | 12 +-- .../kubernetes => conn/k8s}/create.go | 4 +- .../kubernetes => conn/k8s}/delete.go | 8 +- .../kubernetes => conn/k8s}/kubernetes.go | 2 +- .../kubernetes => conn/k8s}/list.go | 6 +- .../kubernetes => conn/k8s}/open.go | 4 +- .../kubernetes => conn/k8s}/types.go | 6 +- cmd/pops/app/{connection => conn}/list.go | 2 +- cmd/pops/app/conn/open.go | 53 +++++++++++ cmd/pops/app/{connection => conn}/types.go | 6 +- cmd/pops/app/root.go | 6 +- pkg/config/config.go | 26 +++--- pkg/{connection => conn}/cloud.go | 2 +- pkg/{connection => conn}/cloud_test.go | 2 +- pkg/{connection => conn}/db.go | 20 ++++- pkg/{connection => conn}/db_test.go | 2 +- pkg/{connection => conn}/factory.go | 2 +- pkg/{connection => conn}/kubernetes.go | 2 +- pkg/{connection => conn}/kubernetes_test.go | 2 +- pkg/{connection => conn}/query.go | 2 +- pkg/{connection => conn}/types.go | 2 +- pkg/ui/common/doc.go | 3 - pkg/ui/{ => conn}/cloud/create.go | 61 ++++++++----- pkg/ui/{ => conn}/cloud/create_test.go | 0 pkg/ui/{ => conn}/cloud/doc.go | 0 pkg/ui/{ => conn}/cloud/open.go | 14 +-- pkg/ui/{ => conn}/cloud/types.go | 0 pkg/ui/{ => conn}/db/create.go | 20 ++--- pkg/ui/{ => conn}/db/doc.go | 0 pkg/ui/{ => conn}/db/open.go | 14 +-- pkg/ui/{ => conn}/db/types.go | 0 pkg/ui/{kubernetes => conn/k8s}/create.go | 22 ++--- pkg/ui/{kubernetes => conn/k8s}/doc.go | 2 +- pkg/ui/{kubernetes => conn/k8s}/open.go | 16 ++-- pkg/ui/{kubernetes => conn/k8s}/types.go | 2 +- .../app/connection => pkg/ui/conn}/open.go | 87 +++---------------- pkg/ui/shell.go | 19 ++-- pkg/ui/types.go | 14 ++- 55 files changed, 290 insertions(+), 251 deletions(-) rename cmd/pops/app/{connection => conn}/cloud/cloud.go (92%) rename cmd/pops/app/{connection => conn}/cloud/create.go (87%) rename cmd/pops/app/{connection => conn}/cloud/delete.go (95%) rename cmd/pops/app/{connection => conn}/cloud/list.go (93%) rename cmd/pops/app/{connection => conn}/cloud/open.go (86%) rename cmd/pops/app/{connection => conn}/cloud/types.go (93%) rename cmd/pops/app/{connection => conn}/connection.go (86%) rename cmd/pops/app/{connection => conn}/create.go (94%) rename cmd/pops/app/{connection => conn}/db/create.go (96%) rename cmd/pops/app/{connection => conn}/db/db.go (100%) rename cmd/pops/app/{connection => conn}/db/delete.go (94%) rename cmd/pops/app/{connection => conn}/db/list.go (93%) rename cmd/pops/app/{connection => conn}/db/open.go (95%) rename cmd/pops/app/{connection => conn}/db/types.go (93%) rename cmd/pops/app/{connection => conn}/delete.go (99%) rename cmd/pops/app/{connection => conn}/factory/create.go (69%) rename cmd/pops/app/{connection => conn}/factory/doc.go (100%) rename cmd/pops/app/{connection => conn}/factory/open.go (56%) rename cmd/pops/app/{connection/kubernetes => conn/k8s}/create.go (93%) rename cmd/pops/app/{connection/kubernetes => conn/k8s}/delete.go (93%) rename cmd/pops/app/{connection/kubernetes => conn/k8s}/kubernetes.go (98%) rename cmd/pops/app/{connection/kubernetes => conn/k8s}/list.go (91%) rename cmd/pops/app/{connection/kubernetes => conn/k8s}/open.go (93%) rename cmd/pops/app/{connection/kubernetes => conn/k8s}/types.go (92%) rename cmd/pops/app/{connection => conn}/list.go (98%) create mode 100644 cmd/pops/app/conn/open.go rename cmd/pops/app/{connection => conn}/types.go (92%) rename pkg/{connection => conn}/cloud.go (99%) rename pkg/{connection => conn}/cloud_test.go (99%) rename pkg/{connection => conn}/db.go (95%) rename pkg/{connection => conn}/db_test.go (99%) rename pkg/{connection => conn}/factory.go (97%) rename pkg/{connection => conn}/kubernetes.go (99%) rename pkg/{connection => conn}/kubernetes_test.go (99%) rename pkg/{connection => conn}/query.go (96%) rename pkg/{connection => conn}/types.go (99%) delete mode 100644 pkg/ui/common/doc.go rename pkg/ui/{ => conn}/cloud/create.go (78%) rename pkg/ui/{ => conn}/cloud/create_test.go (100%) rename pkg/ui/{ => conn}/cloud/doc.go (100%) rename pkg/ui/{ => conn}/cloud/open.go (91%) rename pkg/ui/{ => conn}/cloud/types.go (100%) rename pkg/ui/{ => conn}/db/create.go (91%) rename pkg/ui/{ => conn}/db/doc.go (100%) rename pkg/ui/{ => conn}/db/open.go (91%) rename pkg/ui/{ => conn}/db/types.go (100%) rename pkg/ui/{kubernetes => conn/k8s}/create.go (91%) rename pkg/ui/{kubernetes => conn/k8s}/doc.go (77%) rename pkg/ui/{kubernetes => conn/k8s}/open.go (90%) rename pkg/ui/{kubernetes => conn/k8s}/types.go (95%) rename {cmd/pops/app/connection => pkg/ui/conn}/open.go (51%) diff --git a/cmd/pops/app/connection/cloud/cloud.go b/cmd/pops/app/conn/cloud/cloud.go similarity index 92% rename from cmd/pops/app/connection/cloud/cloud.go rename to cmd/pops/app/conn/cloud/cloud.go index e4d30f6..ab48e21 100644 --- a/cmd/pops/app/connection/cloud/cloud.go +++ b/cmd/pops/app/conn/cloud/cloud.go @@ -11,14 +11,14 @@ func NewRootCommand() *cobra.Command { Long: ` Cloud Connection: -- Available Cloud connection types: Azure and AWS. +- Available Cloud connection types: Azure. - Commands: create, delete, open, list, types. - Examples: * 'pops connection cloud create' creates a connection to a cloud provider. * 'pops connection cloud open' opens an existing cloud connection. * 'pops connection cloud list' lists all cloud connections. * 'pops connection cloud delete' deletes a cloud connection. - * 'pops connection cloud types' lists all available cloud connection types (for now; Azure and AWS). + * 'pops connection cloud types' lists all available cloud connection types (for now; Azure). More connection types and features are coming soon!`, } diff --git a/cmd/pops/app/connection/cloud/create.go b/cmd/pops/app/conn/cloud/create.go similarity index 87% rename from cmd/pops/app/connection/cloud/create.go rename to cmd/pops/app/conn/cloud/create.go index a937c71..e8cc7c4 100644 --- a/cmd/pops/app/connection/cloud/create.go +++ b/cmd/pops/app/conn/cloud/create.go @@ -5,9 +5,9 @@ import ( "strings" "github.com/prompt-ops/pops/pkg/config" - "github.com/prompt-ops/pops/pkg/connection" + "github.com/prompt-ops/pops/pkg/conn" "github.com/prompt-ops/pops/pkg/ui" - "github.com/prompt-ops/pops/pkg/ui/cloud" + "github.com/prompt-ops/pops/pkg/ui/conn/cloud" tea "github.com/charmbracelet/bubbletea" "github.com/spf13/cobra" @@ -57,7 +57,7 @@ func newCreateCmd() *cobra.Command { Long: ` Cloud Connection: -- Available Cloud connection types: Azure, AWS, and GCP. +- Available Cloud connection types: Azure. - Commands: create, delete, open, list, types. - Examples: * 'pops connection cloud create' creates a connection interactively. @@ -73,8 +73,8 @@ Cloud Connection: } transitionMsg := ui.TransitionToShellMsg{ - Connection: connection.NewCloudConnection(name, - connection.AvailableCloudConnectionType{ + Connection: conn.NewCloudConnection(name, + conn.AvailableCloudConnectionType{ Subtype: strings.Title(provider), }, ), @@ -114,8 +114,8 @@ func createCloudConnection(name, provider string) error { return fmt.Errorf("connection name cannot be empty") } - var selectedProvider connection.AvailableCloudConnectionType - for _, p := range connection.AvailableCloudConnectionTypes { + var selectedProvider conn.AvailableCloudConnectionType + for _, p := range conn.AvailableCloudConnectionTypes { if strings.ToLower(p.Subtype) == provider { selectedProvider = p break @@ -129,7 +129,7 @@ func createCloudConnection(name, provider string) error { return fmt.Errorf("connection name '%s' already exists", name) } - connection := connection.NewCloudConnection(name, selectedProvider) + connection := conn.NewCloudConnection(name, selectedProvider) if err := config.SaveConnection(connection); err != nil { return fmt.Errorf("failed to save connection: %w", err) } diff --git a/cmd/pops/app/connection/cloud/delete.go b/cmd/pops/app/conn/cloud/delete.go similarity index 95% rename from cmd/pops/app/connection/cloud/delete.go rename to cmd/pops/app/conn/cloud/delete.go index 36ecfa4..b42498f 100644 --- a/cmd/pops/app/connection/cloud/delete.go +++ b/cmd/pops/app/conn/cloud/delete.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/prompt-ops/pops/pkg/config" - "github.com/prompt-ops/pops/pkg/connection" + "github.com/prompt-ops/pops/pkg/conn" "github.com/prompt-ops/pops/pkg/ui" "github.com/charmbracelet/bubbles/table" @@ -98,7 +98,7 @@ Examples: // deleteAllCloudConnections deletes all cloud connections func deleteAllCloudConnections() error { - if err := config.DeleteAllConnectionsByType(connection.ConnectionTypeCloud); err != nil { + if err := config.DeleteAllConnectionsByType(conn.ConnectionTypeCloud); err != nil { return fmt.Errorf("error deleting all cloud connections: %w", err) } color.Green("All cloud connections have been successfully deleted.") @@ -123,7 +123,7 @@ func deleteCloudConnection(name string) error { // runInteractiveDelete runs the Bubble Tea program for interactive deletion func runInteractiveDelete() (string, error) { - connections, err := config.GetConnectionsByType(connection.ConnectionTypeCloud) + connections, err := config.GetConnectionsByType(conn.ConnectionTypeCloud) if err != nil { return "", fmt.Errorf("getting connections: %w", err) } diff --git a/cmd/pops/app/connection/cloud/list.go b/cmd/pops/app/conn/cloud/list.go similarity index 93% rename from cmd/pops/app/connection/cloud/list.go rename to cmd/pops/app/conn/cloud/list.go index 880ee98..dfa95ff 100644 --- a/cmd/pops/app/connection/cloud/list.go +++ b/cmd/pops/app/conn/cloud/list.go @@ -5,7 +5,7 @@ import ( "os" "github.com/prompt-ops/pops/pkg/config" - "github.com/prompt-ops/pops/pkg/connection" + "github.com/prompt-ops/pops/pkg/conn" "github.com/prompt-ops/pops/pkg/ui" "github.com/charmbracelet/bubbles/table" @@ -33,7 +33,7 @@ func newListCmd() *cobra.Command { // runListConnections lists all connections func runListConnections() error { - connections, err := config.GetConnectionsByType(connection.ConnectionTypeCloud) + connections, err := config.GetConnectionsByType(conn.ConnectionTypeCloud) if err != nil { return fmt.Errorf("getting cloud connections: %w", err) } diff --git a/cmd/pops/app/connection/cloud/open.go b/cmd/pops/app/conn/cloud/open.go similarity index 86% rename from cmd/pops/app/connection/cloud/open.go rename to cmd/pops/app/conn/cloud/open.go index 831f1e5..083b601 100644 --- a/cmd/pops/app/connection/cloud/open.go +++ b/cmd/pops/app/conn/cloud/open.go @@ -4,9 +4,9 @@ import ( "fmt" "github.com/prompt-ops/pops/pkg/config" - "github.com/prompt-ops/pops/pkg/connection" + "github.com/prompt-ops/pops/pkg/conn" "github.com/prompt-ops/pops/pkg/ui" - "github.com/prompt-ops/pops/pkg/ui/cloud" + "github.com/prompt-ops/pops/pkg/ui/conn/cloud" tea "github.com/charmbracelet/bubbletea" "github.com/spf13/cobra" @@ -51,7 +51,7 @@ func newOpenCmd() *cobra.Command { cmd := &cobra.Command{ Use: "open [connection-name]", - Short: "Open an existing cloud connection.", + Short: "Open an existing cloud conn.", Long: `Open a cloud connection to access its shell. You can specify the connection name either as a positional argument or using the --name flag. @@ -116,10 +116,10 @@ Examples: // getConnectionByName retrieves a cloud connection by its name. // Returns an error if the connection does not exist. -func getConnectionByName(name string) (connection.Connection, error) { - cloudConnections, err := config.GetConnectionsByType(connection.ConnectionTypeCloud) +func getConnectionByName(name string) (conn.Connection, error) { + cloudConnections, err := config.GetConnectionsByType(conn.ConnectionTypeCloud) if err != nil { - return connection.Connection{}, fmt.Errorf("failed to retrieve connections: %w", err) + return conn.Connection{}, fmt.Errorf("failed to retrieve connections: %w", err) } for _, conn := range cloudConnections { @@ -128,5 +128,5 @@ func getConnectionByName(name string) (connection.Connection, error) { } } - return connection.Connection{}, fmt.Errorf("connection '%s' does not exist", name) + return conn.Connection{}, fmt.Errorf("connection '%s' does not exist", name) } diff --git a/cmd/pops/app/connection/cloud/types.go b/cmd/pops/app/conn/cloud/types.go similarity index 93% rename from cmd/pops/app/connection/cloud/types.go rename to cmd/pops/app/conn/cloud/types.go index 09b9efd..d15a19b 100644 --- a/cmd/pops/app/connection/cloud/types.go +++ b/cmd/pops/app/conn/cloud/types.go @@ -3,7 +3,7 @@ package cloud import ( "os" - "github.com/prompt-ops/pops/pkg/connection" + "github.com/prompt-ops/pops/pkg/conn" "github.com/prompt-ops/pops/pkg/ui" "github.com/charmbracelet/bubbles/table" @@ -31,7 +31,7 @@ func newTypesCmd() *cobra.Command { // runListAvaibleCloudTypes lists all available cloud connection types func runListAvaibleCloudTypes() error { - cloudConnectionTypes := connection.AvailableCloudConnectionTypes + cloudConnectionTypes := conn.AvailableCloudConnectionTypes items := make([]table.Row, len(cloudConnectionTypes)) for i, cloudConnectionType := range cloudConnectionTypes { diff --git a/cmd/pops/app/connection/connection.go b/cmd/pops/app/conn/connection.go similarity index 86% rename from cmd/pops/app/connection/connection.go rename to cmd/pops/app/conn/connection.go index 54a51c2..e4852af 100644 --- a/cmd/pops/app/connection/connection.go +++ b/cmd/pops/app/conn/connection.go @@ -1,9 +1,9 @@ -package connection +package conn import ( - "github.com/prompt-ops/pops/cmd/pops/app/connection/cloud" - "github.com/prompt-ops/pops/cmd/pops/app/connection/db" - "github.com/prompt-ops/pops/cmd/pops/app/connection/kubernetes" + "github.com/prompt-ops/pops/cmd/pops/app/conn/cloud" + "github.com/prompt-ops/pops/cmd/pops/app/conn/db" + "github.com/prompt-ops/pops/cmd/pops/app/conn/k8s" "github.com/spf13/cobra" ) @@ -18,7 +18,7 @@ func NewConnectionCommand() *cobra.Command { Prompt-Ops manages your infrastructure using natural language. **Cloud Connection:** -- **Types**: Azure, AWS +- **Types**: Azure, AWS, and GCP (coming soon) - **Commands**: create, delete, open, list, types - **Example**: 'pops connection cloud create' creates a connection to a cloud provider. @@ -44,7 +44,7 @@ More connection types and features are coming soon!`, // Add subcommands cmd.AddCommand(cloud.NewRootCommand()) - cmd.AddCommand(kubernetes.NewRootCommand()) + cmd.AddCommand(k8s.NewRootCommand()) cmd.AddCommand(db.NewRootCommand()) // Add additional commands diff --git a/cmd/pops/app/connection/create.go b/cmd/pops/app/conn/create.go similarity index 94% rename from cmd/pops/app/connection/create.go rename to cmd/pops/app/conn/create.go index d5e0110..ece5568 100644 --- a/cmd/pops/app/connection/create.go +++ b/cmd/pops/app/conn/create.go @@ -1,8 +1,8 @@ -package connection +package conn import ( - "github.com/prompt-ops/pops/cmd/pops/app/connection/factory" - "github.com/prompt-ops/pops/pkg/connection" + "github.com/prompt-ops/pops/cmd/pops/app/conn/factory" + "github.com/prompt-ops/pops/pkg/conn" "github.com/prompt-ops/pops/pkg/ui" "github.com/charmbracelet/bubbles/table" @@ -49,7 +49,7 @@ type createModel struct { } func initialCreateModel() *createModel { - connectionTypes := connection.AvailableConnectionTypes() + connectionTypes := conn.AvailableConnectionTypes() items := make([]table.Row, len(connectionTypes)) for i, connectionType := range connectionTypes { diff --git a/cmd/pops/app/connection/db/create.go b/cmd/pops/app/conn/db/create.go similarity index 96% rename from cmd/pops/app/connection/db/create.go rename to cmd/pops/app/conn/db/create.go index a17a84c..ea16073 100644 --- a/cmd/pops/app/connection/db/create.go +++ b/cmd/pops/app/conn/db/create.go @@ -2,7 +2,7 @@ package db import ( "github.com/prompt-ops/pops/pkg/ui" - "github.com/prompt-ops/pops/pkg/ui/db" + "github.com/prompt-ops/pops/pkg/ui/conn/db" tea "github.com/charmbracelet/bubbletea" "github.com/spf13/cobra" diff --git a/cmd/pops/app/connection/db/db.go b/cmd/pops/app/conn/db/db.go similarity index 100% rename from cmd/pops/app/connection/db/db.go rename to cmd/pops/app/conn/db/db.go diff --git a/cmd/pops/app/connection/db/delete.go b/cmd/pops/app/conn/db/delete.go similarity index 94% rename from cmd/pops/app/connection/db/delete.go rename to cmd/pops/app/conn/db/delete.go index 68d73a7..4efeb29 100644 --- a/cmd/pops/app/connection/db/delete.go +++ b/cmd/pops/app/conn/db/delete.go @@ -4,7 +4,7 @@ import ( "fmt" config "github.com/prompt-ops/pops/pkg/config" - "github.com/prompt-ops/pops/pkg/connection" + "github.com/prompt-ops/pops/pkg/conn" "github.com/prompt-ops/pops/pkg/ui" "github.com/charmbracelet/bubbles/table" @@ -70,7 +70,7 @@ func newDeleteCmd() *cobra.Command { // deleteAllDatabaseConnections deletes all database connections func deleteAllDatabaseConnections() error { - if err := config.DeleteAllConnectionsByType(connection.ConnectionTypeDatabase); err != nil { + if err := config.DeleteAllConnectionsByType(conn.ConnectionTypeDatabase); err != nil { return fmt.Errorf("error deleting all database connections: %w", err) } return nil @@ -86,7 +86,7 @@ func deleteDatabaseConnection(name string) error { // runInteractiveDelete runs the Bubble Tea program for interactive deletion func runInteractiveDelete() (string, error) { - connections, err := config.GetConnectionsByType(connection.ConnectionTypeDatabase) + connections, err := config.GetConnectionsByType(conn.ConnectionTypeDatabase) if err != nil { return "", fmt.Errorf("getting connections: %w", err) } diff --git a/cmd/pops/app/connection/db/list.go b/cmd/pops/app/conn/db/list.go similarity index 93% rename from cmd/pops/app/connection/db/list.go rename to cmd/pops/app/conn/db/list.go index 54e7f64..b37a3ae 100644 --- a/cmd/pops/app/connection/db/list.go +++ b/cmd/pops/app/conn/db/list.go @@ -5,7 +5,7 @@ import ( "os" config "github.com/prompt-ops/pops/pkg/config" - "github.com/prompt-ops/pops/pkg/connection" + "github.com/prompt-ops/pops/pkg/conn" "github.com/prompt-ops/pops/pkg/ui" "github.com/charmbracelet/bubbles/table" @@ -33,7 +33,7 @@ func newListCmd() *cobra.Command { // runListConnections lists all connections func runListConnections() error { - connections, err := config.GetConnectionsByType(connection.ConnectionTypeDatabase) + connections, err := config.GetConnectionsByType(conn.ConnectionTypeDatabase) if err != nil { return fmt.Errorf("getting database connections: %w", err) } diff --git a/cmd/pops/app/connection/db/open.go b/cmd/pops/app/conn/db/open.go similarity index 95% rename from cmd/pops/app/connection/db/open.go rename to cmd/pops/app/conn/db/open.go index 0c7be0f..d28a1ea 100644 --- a/cmd/pops/app/connection/db/open.go +++ b/cmd/pops/app/conn/db/open.go @@ -2,7 +2,7 @@ package db import ( ui "github.com/prompt-ops/pops/pkg/ui" - dbui "github.com/prompt-ops/pops/pkg/ui/db" + dbui "github.com/prompt-ops/pops/pkg/ui/conn/db" tea "github.com/charmbracelet/bubbletea" "github.com/spf13/cobra" diff --git a/cmd/pops/app/connection/db/types.go b/cmd/pops/app/conn/db/types.go similarity index 93% rename from cmd/pops/app/connection/db/types.go rename to cmd/pops/app/conn/db/types.go index 8d4572c..4374a08 100644 --- a/cmd/pops/app/connection/db/types.go +++ b/cmd/pops/app/conn/db/types.go @@ -3,7 +3,7 @@ package db import ( "os" - "github.com/prompt-ops/pops/pkg/connection" + "github.com/prompt-ops/pops/pkg/conn" "github.com/prompt-ops/pops/pkg/ui" "github.com/charmbracelet/bubbles/table" @@ -31,7 +31,7 @@ func newTypesCmd() *cobra.Command { // runListAvaibledatabaseTypes lists all available database connection types func runListAvaibleDatabaseTypes() error { - databaseConnections := connection.AvailableDatabaseConnectionTypes + databaseConnections := conn.AvailableDatabaseConnectionTypes items := make([]table.Row, len(databaseConnections)) for i, connectionType := range databaseConnections { diff --git a/cmd/pops/app/connection/delete.go b/cmd/pops/app/conn/delete.go similarity index 99% rename from cmd/pops/app/connection/delete.go rename to cmd/pops/app/conn/delete.go index 5a238b0..688d59d 100644 --- a/cmd/pops/app/connection/delete.go +++ b/cmd/pops/app/conn/delete.go @@ -1,4 +1,4 @@ -package connection +package conn import ( "fmt" diff --git a/cmd/pops/app/connection/factory/create.go b/cmd/pops/app/conn/factory/create.go similarity index 69% rename from cmd/pops/app/connection/factory/create.go rename to cmd/pops/app/conn/factory/create.go index a0ee774..90be161 100644 --- a/cmd/pops/app/connection/factory/create.go +++ b/cmd/pops/app/conn/factory/create.go @@ -4,9 +4,9 @@ import ( "fmt" "strings" - "github.com/prompt-ops/pops/cmd/pops/app/connection/cloud" - "github.com/prompt-ops/pops/cmd/pops/app/connection/db" - "github.com/prompt-ops/pops/cmd/pops/app/connection/kubernetes" + "github.com/prompt-ops/pops/cmd/pops/app/conn/cloud" + "github.com/prompt-ops/pops/cmd/pops/app/conn/db" + "github.com/prompt-ops/pops/cmd/pops/app/conn/k8s" tea "github.com/charmbracelet/bubbletea" ) @@ -17,7 +17,7 @@ func GetCreateModel(connectionType string) (tea.Model, error) { case "cloud": return cloud.NewCreateModel(), nil case "kubernetes": - return kubernetes.NewCreateModel(), nil + return k8s.NewCreateModel(), nil case "database": return db.NewCreateModel(), nil default: diff --git a/cmd/pops/app/connection/factory/doc.go b/cmd/pops/app/conn/factory/doc.go similarity index 100% rename from cmd/pops/app/connection/factory/doc.go rename to cmd/pops/app/conn/factory/doc.go diff --git a/cmd/pops/app/connection/factory/open.go b/cmd/pops/app/conn/factory/open.go similarity index 56% rename from cmd/pops/app/connection/factory/open.go rename to cmd/pops/app/conn/factory/open.go index 0166f8f..bcfce2d 100644 --- a/cmd/pops/app/connection/factory/open.go +++ b/cmd/pops/app/conn/factory/open.go @@ -4,21 +4,21 @@ import ( "fmt" "strings" - "github.com/prompt-ops/pops/cmd/pops/app/connection/cloud" - "github.com/prompt-ops/pops/cmd/pops/app/connection/db" - "github.com/prompt-ops/pops/cmd/pops/app/connection/kubernetes" - "github.com/prompt-ops/pops/pkg/connection" + "github.com/prompt-ops/pops/cmd/pops/app/conn/cloud" + "github.com/prompt-ops/pops/cmd/pops/app/conn/db" + "github.com/prompt-ops/pops/cmd/pops/app/conn/k8s" + "github.com/prompt-ops/pops/pkg/conn" tea "github.com/charmbracelet/bubbletea" ) // GetOpenModel returns a new openModel based on the connection type -func GetOpenModel(connection connection.Connection) (tea.Model, error) { +func GetOpenModel(connection conn.Connection) (tea.Model, error) { switch strings.ToLower(connection.Type.GetMainType()) { case "cloud": return cloud.NewOpenModel(), nil case "kubernetes": - return kubernetes.NewOpenModel(), nil + return k8s.NewOpenModel(), nil case "database": return db.NewOpenModel(), nil default: diff --git a/cmd/pops/app/connection/kubernetes/create.go b/cmd/pops/app/conn/k8s/create.go similarity index 93% rename from cmd/pops/app/connection/kubernetes/create.go rename to cmd/pops/app/conn/k8s/create.go index e6d7dc0..bc926b8 100644 --- a/cmd/pops/app/connection/kubernetes/create.go +++ b/cmd/pops/app/conn/k8s/create.go @@ -1,8 +1,8 @@ -package kubernetes +package k8s import ( "github.com/prompt-ops/pops/pkg/ui" - k8sui "github.com/prompt-ops/pops/pkg/ui/kubernetes" + k8sui "github.com/prompt-ops/pops/pkg/ui/conn/k8s" tea "github.com/charmbracelet/bubbletea" "github.com/spf13/cobra" diff --git a/cmd/pops/app/connection/kubernetes/delete.go b/cmd/pops/app/conn/k8s/delete.go similarity index 93% rename from cmd/pops/app/connection/kubernetes/delete.go rename to cmd/pops/app/conn/k8s/delete.go index cfecdbd..50ae6de 100644 --- a/cmd/pops/app/connection/kubernetes/delete.go +++ b/cmd/pops/app/conn/k8s/delete.go @@ -1,10 +1,10 @@ -package kubernetes +package k8s import ( "fmt" config "github.com/prompt-ops/pops/pkg/config" - "github.com/prompt-ops/pops/pkg/connection" + "github.com/prompt-ops/pops/pkg/conn" "github.com/prompt-ops/pops/pkg/ui" "github.com/charmbracelet/bubbles/table" @@ -70,7 +70,7 @@ func newDeleteCmd() *cobra.Command { // deleteAllKubernetesConnections deletes all kubernetes connections func deleteAllKubernetesConnections() error { - if err := config.DeleteAllConnectionsByType(connection.ConnectionTypeCloud); err != nil { + if err := config.DeleteAllConnectionsByType(conn.ConnectionTypeCloud); err != nil { return fmt.Errorf("error deleting all kubernetes connections: %w", err) } return nil @@ -86,7 +86,7 @@ func deleteKubernetesConnection(name string) error { // runInteractiveDelete runs the Bubble Tea program for interactive deletion func runInteractiveDelete() (string, error) { - connections, err := config.GetConnectionsByType(connection.ConnectionTypeCloud) + connections, err := config.GetConnectionsByType(conn.ConnectionTypeCloud) if err != nil { return "", fmt.Errorf("getting connections: %w", err) } diff --git a/cmd/pops/app/connection/kubernetes/kubernetes.go b/cmd/pops/app/conn/k8s/kubernetes.go similarity index 98% rename from cmd/pops/app/connection/kubernetes/kubernetes.go rename to cmd/pops/app/conn/k8s/kubernetes.go index bc2d7b3..edcb80b 100644 --- a/cmd/pops/app/connection/kubernetes/kubernetes.go +++ b/cmd/pops/app/conn/k8s/kubernetes.go @@ -1,4 +1,4 @@ -package kubernetes +package k8s import ( "github.com/spf13/cobra" diff --git a/cmd/pops/app/connection/kubernetes/list.go b/cmd/pops/app/conn/k8s/list.go similarity index 91% rename from cmd/pops/app/connection/kubernetes/list.go rename to cmd/pops/app/conn/k8s/list.go index 6c00ddc..2e87b4e 100644 --- a/cmd/pops/app/connection/kubernetes/list.go +++ b/cmd/pops/app/conn/k8s/list.go @@ -1,11 +1,11 @@ -package kubernetes +package k8s import ( "fmt" "os" config "github.com/prompt-ops/pops/pkg/config" - "github.com/prompt-ops/pops/pkg/connection" + "github.com/prompt-ops/pops/pkg/conn" "github.com/prompt-ops/pops/pkg/ui" "github.com/charmbracelet/bubbles/table" @@ -33,7 +33,7 @@ func newListCmd() *cobra.Command { // runListConnections lists all connections func runListConnections() error { - connections, err := config.GetConnectionsByType(connection.ConnectionTypeKubernetes) + connections, err := config.GetConnectionsByType(conn.ConnectionTypeKubernetes) if err != nil { return fmt.Errorf("getting kubernetes connections: %w", err) } diff --git a/cmd/pops/app/connection/kubernetes/open.go b/cmd/pops/app/conn/k8s/open.go similarity index 93% rename from cmd/pops/app/connection/kubernetes/open.go rename to cmd/pops/app/conn/k8s/open.go index eba22ea..61a6be2 100644 --- a/cmd/pops/app/connection/kubernetes/open.go +++ b/cmd/pops/app/conn/k8s/open.go @@ -1,8 +1,8 @@ -package kubernetes +package k8s import ( "github.com/prompt-ops/pops/pkg/ui" - k8sui "github.com/prompt-ops/pops/pkg/ui/kubernetes" + k8sui "github.com/prompt-ops/pops/pkg/ui/conn/k8s" tea "github.com/charmbracelet/bubbletea" "github.com/spf13/cobra" diff --git a/cmd/pops/app/connection/kubernetes/types.go b/cmd/pops/app/conn/k8s/types.go similarity index 92% rename from cmd/pops/app/connection/kubernetes/types.go rename to cmd/pops/app/conn/k8s/types.go index 4b55dfc..3d8ad35 100644 --- a/cmd/pops/app/connection/kubernetes/types.go +++ b/cmd/pops/app/conn/k8s/types.go @@ -1,9 +1,9 @@ -package kubernetes +package k8s import ( "os" - "github.com/prompt-ops/pops/pkg/connection" + "github.com/prompt-ops/pops/pkg/conn" "github.com/prompt-ops/pops/pkg/ui" "github.com/charmbracelet/bubbles/table" @@ -31,7 +31,7 @@ func newTypesCmd() *cobra.Command { // runListAvaibleKubernetesTypes lists all available kubernetes connection types func runListAvaibleKubernetesTypes() error { - connectionTypes := connection.AvailableKubernetesConnectionTypes + connectionTypes := conn.AvailableKubernetesConnectionTypes items := make([]table.Row, len(connectionTypes)) for i, connectionType := range connectionTypes { diff --git a/cmd/pops/app/connection/list.go b/cmd/pops/app/conn/list.go similarity index 98% rename from cmd/pops/app/connection/list.go rename to cmd/pops/app/conn/list.go index af43641..fa7faed 100644 --- a/cmd/pops/app/connection/list.go +++ b/cmd/pops/app/conn/list.go @@ -1,4 +1,4 @@ -package connection +package conn import ( "fmt" diff --git a/cmd/pops/app/conn/open.go b/cmd/pops/app/conn/open.go new file mode 100644 index 0000000..d230964 --- /dev/null +++ b/cmd/pops/app/conn/open.go @@ -0,0 +1,53 @@ +package conn + +import ( + "github.com/prompt-ops/pops/pkg/config" + "github.com/prompt-ops/pops/pkg/ui" + "github.com/prompt-ops/pops/pkg/ui/conn" + + tea "github.com/charmbracelet/bubbletea" + "github.com/fatih/color" + "github.com/spf13/cobra" +) + +// newOpenCmd creates the open command for the connection. +func newOpenCmd() *cobra.Command { + openCmd := &cobra.Command{ + Use: "open", + Short: "Open a connection", + Long: "Open a connection", + Run: func(cmd *cobra.Command, args []string) { + if len(args) == 1 { + openSingleConnection(args[0]) + } else { + openConnectionPicker() + } + }, + } + + return openCmd +} + +// openSingleConnection opens a single connection by name. +func openSingleConnection(name string) { + conn, err := config.GetConnectionByName(name) + if err != nil { + color.Red("Error getting connection: %v", err) + return + } + + shell := ui.NewShellModel(conn) + p := tea.NewProgram(shell) + if _, err := p.Run(); err != nil { + color.Red("Error opening shell UI: %v", err) + } +} + +// openConnectionPicker opens the connection picker UI. +func openConnectionPicker() { + root := conn.NewOpenRootModel() + p := tea.NewProgram(root) + if _, err := p.Run(); err != nil { + color.Red("Error: %v", err) + } +} diff --git a/cmd/pops/app/connection/types.go b/cmd/pops/app/conn/types.go similarity index 92% rename from cmd/pops/app/connection/types.go rename to cmd/pops/app/conn/types.go index 193f8c0..c7c9f6f 100644 --- a/cmd/pops/app/connection/types.go +++ b/cmd/pops/app/conn/types.go @@ -1,9 +1,9 @@ -package connection +package conn import ( "os" - "github.com/prompt-ops/pops/pkg/connection" + "github.com/prompt-ops/pops/pkg/conn" "github.com/prompt-ops/pops/pkg/ui" "github.com/charmbracelet/bubbles/table" @@ -31,7 +31,7 @@ func newTypesCmd() *cobra.Command { // runListAvaibleTypes lists all available connection types func runListAvaibleTypes() error { - connectionTypes := connection.AvailableConnectionTypes() + connectionTypes := conn.AvailableConnectionTypes() items := make([]table.Row, len(connectionTypes)) for i, connectionType := range connectionTypes { diff --git a/cmd/pops/app/root.go b/cmd/pops/app/root.go index 81e3bab..ad0f376 100644 --- a/cmd/pops/app/root.go +++ b/cmd/pops/app/root.go @@ -4,7 +4,7 @@ import ( "fmt" "os" - "github.com/prompt-ops/pops/cmd/pops/app/connection" + "github.com/prompt-ops/pops/cmd/pops/app/conn" "github.com/spf13/cobra" ) @@ -17,8 +17,8 @@ func NewRootCommand() *cobra.Command { // `pops version` command cmd.AddCommand(NewVersionCmd) - // `pops connection` commands - cmd.AddCommand(connection.NewConnectionCommand()) + // `pops connection (conn as alias)` commands + cmd.AddCommand(conn.NewConnectionCommand()) return cmd } diff --git a/pkg/config/config.go b/pkg/config/config.go index a682a3a..3036d03 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -8,11 +8,11 @@ import ( "path/filepath" "strings" - "github.com/prompt-ops/pops/pkg/connection" + "github.com/prompt-ops/pops/pkg/conn" ) // connections stores all the connection configurations in memory. -var connections []connection.Connection +var connections []conn.Connection // connectionsConfigFilePath defines the path to the connections configuration file. var connectionsConfigFilePath = getConfigFilePath("connections.json") @@ -47,7 +47,7 @@ func loadConnections() error { } defer file.Close() - var loadedConnections []connection.Connection + var loadedConnections []conn.Connection if err := json.NewDecoder(file).Decode(&loadedConnections); err != nil { return err } @@ -57,7 +57,7 @@ func loadConnections() error { } // SaveConnection saves a new connection or updates an existing one based on the connection name. -func SaveConnection(conn connection.Connection) error { +func SaveConnection(conn conn.Connection) error { if connections == nil { if err := loadConnections(); err != nil && !errors.Is(err, os.ErrNotExist) { return err @@ -102,10 +102,10 @@ func writeConnections() error { } // GetConnectionByName retrieves a connection by its name. -func GetConnectionByName(connectionName string) (connection.Connection, error) { +func GetConnectionByName(connectionName string) (conn.Connection, error) { if connections == nil { if err := loadConnections(); err != nil { - return connection.Connection{}, err + return conn.Connection{}, err } } @@ -115,11 +115,11 @@ func GetConnectionByName(connectionName string) (connection.Connection, error) { } } - return connection.Connection{}, fmt.Errorf("connection with name '%s' does not exist", connectionName) + return conn.Connection{}, fmt.Errorf("connection with name '%s' does not exist", connectionName) } // GetAllConnections retrieves all stored connections. -func GetAllConnections() ([]connection.Connection, error) { +func GetAllConnections() ([]conn.Connection, error) { if connections == nil { if err := loadConnections(); err != nil { return nil, err @@ -130,13 +130,13 @@ func GetAllConnections() ([]connection.Connection, error) { } // GetConnectionsByType retrieves connections filtered by their type. -func GetConnectionsByType(connectionType string) ([]connection.Connection, error) { +func GetConnectionsByType(connectionType string) ([]conn.Connection, error) { allConnections, err := GetAllConnections() if err != nil { return nil, err } - var filteredConnections []connection.Connection + var filteredConnections []conn.Connection for _, conn := range allConnections { if strings.EqualFold(conn.Type.GetMainType(), connectionType) { filteredConnections = append(filteredConnections, conn) @@ -154,7 +154,7 @@ func DeleteConnectionByName(connectionName string) error { } } - var updatedConnections []connection.Connection + var updatedConnections []conn.Connection found := false for _, conn := range connections { if strings.EqualFold(conn.Name, connectionName) { @@ -179,7 +179,7 @@ func DeleteConnectionByName(connectionName string) error { // DeleteAllConnections removes all stored connections. func DeleteAllConnections() error { - connections = []connection.Connection{} + connections = []conn.Connection{} if err := writeConnections(); err != nil { return err @@ -195,7 +195,7 @@ func DeleteAllConnectionsByType(connectionType string) error { } } - var updatedConnections []connection.Connection + var updatedConnections []conn.Connection for _, conn := range connections { if !strings.EqualFold(conn.Type.GetMainType(), connectionType) { updatedConnections = append(updatedConnections, conn) diff --git a/pkg/connection/cloud.go b/pkg/conn/cloud.go similarity index 99% rename from pkg/connection/cloud.go rename to pkg/conn/cloud.go index 26fb8e9..c44107c 100644 --- a/pkg/connection/cloud.go +++ b/pkg/conn/cloud.go @@ -1,4 +1,4 @@ -package connection +package conn import ( "bytes" diff --git a/pkg/connection/cloud_test.go b/pkg/conn/cloud_test.go similarity index 99% rename from pkg/connection/cloud_test.go rename to pkg/conn/cloud_test.go index 5167ba7..569c8b9 100644 --- a/pkg/connection/cloud_test.go +++ b/pkg/conn/cloud_test.go @@ -1,4 +1,4 @@ -package connection +package conn import ( "reflect" diff --git a/pkg/connection/db.go b/pkg/conn/db.go similarity index 95% rename from pkg/connection/db.go rename to pkg/conn/db.go index 15e60d3..4e6c0ae 100644 --- a/pkg/connection/db.go +++ b/pkg/conn/db.go @@ -1,10 +1,11 @@ -package connection +package conn import ( "bytes" "database/sql" "encoding/json" "fmt" + "regexp" _ "github.com/lib/pq" "github.com/olekukonko/tablewriter" @@ -143,7 +144,7 @@ func (b *BaseRDBMSConnection) CheckAuthentication() error { defer db.Close() if err := db.Ping(); err != nil { - return fmt.Errorf("Error pinging the database: %v", err) + return fmt.Errorf("error pinging the database: %v", err) } return nil @@ -180,9 +181,14 @@ func (b *BaseRDBMSConnection) SetContext() error { return fmt.Errorf("error scanning row: %v", err) } + schema = AddQuotesIfNeeded(schema) + table = AddQuotesIfNeeded(table) + column = AddQuotesIfNeeded(column) + dataType = AddQuotesIfNeeded(dataType) + fullTableName := fmt.Sprintf(`%s."%s"`, schema, table) b.TablesAndColumns[fullTableName] = append(b.TablesAndColumns[fullTableName], ColumnDetail{ - Name: fmt.Sprintf(`"%s"`, column), + Name: column, DataType: dataType, }) } @@ -193,6 +199,14 @@ func (b *BaseRDBMSConnection) SetContext() error { return nil } +// AddQuotesIfNeeded adds quotes around the name if it contains capital letters. +func AddQuotesIfNeeded(name string) string { + if regexp.MustCompile(`[A-Z]`).MatchString(name) { + return fmt.Sprintf(`"%s"`, name) + } + return name +} + // GetContext returns the tables and columns set by SetContext. func (b *BaseRDBMSConnection) GetContext() string { if b.TablesAndColumns == nil { diff --git a/pkg/connection/db_test.go b/pkg/conn/db_test.go similarity index 99% rename from pkg/connection/db_test.go rename to pkg/conn/db_test.go index 25d3a48..c7b88d2 100644 --- a/pkg/connection/db_test.go +++ b/pkg/conn/db_test.go @@ -1,4 +1,4 @@ -package connection +package conn import ( "reflect" diff --git a/pkg/connection/factory.go b/pkg/conn/factory.go similarity index 97% rename from pkg/connection/factory.go rename to pkg/conn/factory.go index 5a02549..8c1cedd 100644 --- a/pkg/connection/factory.go +++ b/pkg/conn/factory.go @@ -1,4 +1,4 @@ -package connection +package conn import ( "fmt" diff --git a/pkg/connection/kubernetes.go b/pkg/conn/kubernetes.go similarity index 99% rename from pkg/connection/kubernetes.go rename to pkg/conn/kubernetes.go index 887cde9..e988b4a 100644 --- a/pkg/connection/kubernetes.go +++ b/pkg/conn/kubernetes.go @@ -1,4 +1,4 @@ -package connection +package conn import ( "bytes" diff --git a/pkg/connection/kubernetes_test.go b/pkg/conn/kubernetes_test.go similarity index 99% rename from pkg/connection/kubernetes_test.go rename to pkg/conn/kubernetes_test.go index f6b2e3c..56a5581 100644 --- a/pkg/connection/kubernetes_test.go +++ b/pkg/conn/kubernetes_test.go @@ -1,4 +1,4 @@ -package connection +package conn import ( "reflect" diff --git a/pkg/connection/query.go b/pkg/conn/query.go similarity index 96% rename from pkg/connection/query.go rename to pkg/conn/query.go index d0dbcd2..a238a29 100644 --- a/pkg/connection/query.go +++ b/pkg/conn/query.go @@ -1,4 +1,4 @@ -package connection +package conn var TablesAndColumnsQueryMap = map[string]string{ "postgres": ` diff --git a/pkg/connection/types.go b/pkg/conn/types.go similarity index 99% rename from pkg/connection/types.go rename to pkg/conn/types.go index 88ea859..c3aafec 100644 --- a/pkg/connection/types.go +++ b/pkg/conn/types.go @@ -1,4 +1,4 @@ -package connection +package conn import ( "encoding/json" diff --git a/pkg/ui/common/doc.go b/pkg/ui/common/doc.go deleted file mode 100644 index d8cd082..0000000 --- a/pkg/ui/common/doc.go +++ /dev/null @@ -1,3 +0,0 @@ -package common - -// This package provides common UI components and utilities. diff --git a/pkg/ui/cloud/create.go b/pkg/ui/conn/cloud/create.go similarity index 78% rename from pkg/ui/cloud/create.go rename to pkg/ui/conn/cloud/create.go index 8a27f31..bad4bac 100644 --- a/pkg/ui/cloud/create.go +++ b/pkg/ui/conn/cloud/create.go @@ -10,7 +10,7 @@ import ( tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" config "github.com/prompt-ops/pops/pkg/config" - "github.com/prompt-ops/pops/pkg/connection" + "github.com/prompt-ops/pops/pkg/conn" "github.com/prompt-ops/pops/pkg/ui" ) @@ -27,11 +27,11 @@ const ( stepCreateDone ) -var providers = connection.AvailableCloudConnectionTypes +var providers = conn.AvailableCloudConnectionTypes type ( doneWaitingMsg struct { - Connection connection.Connection + Connection conn.Connection } errMsg struct { @@ -46,13 +46,13 @@ type createModel struct { err error spinner spinner.Model - connection connection.Connection - selectedCloudProvider connection.AvailableCloudConnectionType + connection conn.Connection + selectedCloudProvider conn.AvailableCloudConnectionType } func NewCreateModel() *createModel { ti := textinput.New() - ti.Placeholder = "Enter connection name..." + ti.Placeholder = ui.EnterConnectionNameMessage ti.CharLimit = 256 ti.Width = 30 @@ -121,7 +121,7 @@ func (m *createModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, nil } - connection := connection.NewCloudConnection(name, m.selectedCloudProvider) + connection := conn.NewCloudConnection(name, m.selectedCloudProvider) if err := config.SaveConnection(connection); err != nil { m.err = err return m, nil @@ -157,7 +157,7 @@ func (m *createModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case errMsg: m.err = msg.err m.currentStep = stepCreateDone - m.connection = connection.Connection{} + m.connection = conn.Connection{} return m, nil case tea.KeyMsg: switch msg.String() { @@ -191,7 +191,7 @@ func (m *createModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, cmd } -func waitTwoSecondsCmd(conn connection.Connection) tea.Cmd { +func waitTwoSecondsCmd(conn conn.Connection) tea.Cmd { return tea.Tick(2*time.Second, func(t time.Time) tea.Msg { return doneWaitingMsg{ Connection: conn, @@ -205,28 +205,47 @@ func (m *createModel) View() string { switch m.currentStep { case stepSelectProvider: - s := titleStyle.Render("Select a cloud provider (↑/↓, Enter to confirm):") - s += "\n\n" + title := "Select a cloud provider (↑/↓, Enter to confirm):" + footer := ui.QuitMessage + + var subtypeSelection string for i, p := range providers { cursor := " " if i == m.cursor { cursor = "→ " } - s += fmt.Sprintf("%s%s\n", cursor, promptStyle.Render(p.Subtype)) + subtypeSelection += fmt.Sprintf("%s%s\n", cursor, promptStyle.Render(p.Subtype)) } - s += "\nPress 'q' or 'esc' or Ctrl+C to quit." - return clearScreen + s + + return fmt.Sprintf( + "%s\n\n%s\n%s", + titleStyle.Render(title), + subtypeSelection, + lipgloss.NewStyle().Foreground(lipgloss.Color("8")).Render(footer), + ) case stepEnterConnectionName: - s := titleStyle.Render("Enter a name for the Cloud connection:") - s += "\n\n" + title := "Enter a name for the Cloud connection:" + footer := ui.QuitMessage + if m.err != nil { - s += errorStyle.Render(fmt.Sprintf("Error: %v", m.err)) - s += "\n" + errorMessage := fmt.Sprintf("Error: %v", m.err) + + return fmt.Sprintf( + "%s\n\n%s\n\n%s\n\n%s", + titleStyle.Render(title), + errorStyle.Render(errorMessage), + promptStyle.Render(m.input.View()), + lipgloss.NewStyle().Foreground(lipgloss.Color("8")).Render(footer), + ) } - s += m.input.View() - s += "\n" + helpStyle.Render("Press 'q' or 'esc' or Ctrl+C to quit.") - return clearScreen + s + + return fmt.Sprintf( + "%s\n\n%s\n\n%s", + titleStyle.Render(title), + promptStyle.Render(m.input.View()), + lipgloss.NewStyle().Foreground(lipgloss.Color("8")).Render(footer), + ) case stepCreateSpinner: return clearScreen + outputStyle.Render("Saving connection... ") + m.spinner.View() diff --git a/pkg/ui/cloud/create_test.go b/pkg/ui/conn/cloud/create_test.go similarity index 100% rename from pkg/ui/cloud/create_test.go rename to pkg/ui/conn/cloud/create_test.go diff --git a/pkg/ui/cloud/doc.go b/pkg/ui/conn/cloud/doc.go similarity index 100% rename from pkg/ui/cloud/doc.go rename to pkg/ui/conn/cloud/doc.go diff --git a/pkg/ui/cloud/open.go b/pkg/ui/conn/cloud/open.go similarity index 91% rename from pkg/ui/cloud/open.go rename to pkg/ui/conn/cloud/open.go index 89638a1..e22344c 100644 --- a/pkg/ui/cloud/open.go +++ b/pkg/ui/conn/cloud/open.go @@ -7,7 +7,7 @@ import ( tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" config "github.com/prompt-ops/pops/pkg/config" - "github.com/prompt-ops/pops/pkg/connection" + "github.com/prompt-ops/pops/pkg/conn" "github.com/prompt-ops/pops/pkg/ui" ) @@ -34,8 +34,8 @@ type ( type model struct { currentStep step cursor int - connections []connection.Connection - selected connection.Connection + connections []conn.Connection + selected conn.Connection err error spinner spinner.Model } @@ -62,7 +62,7 @@ func (m model) Init() tea.Cmd { // loadConnectionsCmd fetches existing cloud connections func (m model) loadConnectionsCmd() tea.Cmd { return func() tea.Msg { - cloudConnections, err := config.GetConnectionsByType(connection.ConnectionTypeCloud) + cloudConnections, err := config.GetConnectionsByType(conn.ConnectionTypeCloud) if err != nil { return err } @@ -76,7 +76,7 @@ func (m model) loadConnectionsCmd() tea.Cmd { } type connectionsMsg struct { - connections []connection.Connection + connections []conn.Connection } func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { @@ -142,7 +142,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, cmd } -func transitionCmd(conn connection.Connection) tea.Cmd { +func transitionCmd(conn conn.Connection) tea.Cmd { return func() tea.Msg { return ui.TransitionToShellMsg{ Connection: conn, @@ -167,7 +167,7 @@ func (m model) View() string { } s += unselectedStyle.Render(fmt.Sprintf("%s%s", cursor, conn.Name)) + "\n" } - s += "\n" + helpStyle.Render("Press 'q' or 'esc' or Ctrl+C to quit.") + s += "\n" + helpStyle.Render(ui.QuitMessage) return clearScreen + s case stepOpenSpinner: diff --git a/pkg/ui/cloud/types.go b/pkg/ui/conn/cloud/types.go similarity index 100% rename from pkg/ui/cloud/types.go rename to pkg/ui/conn/cloud/types.go diff --git a/pkg/ui/db/create.go b/pkg/ui/conn/db/create.go similarity index 91% rename from pkg/ui/db/create.go rename to pkg/ui/conn/db/create.go index 12de0b0..8cfa64f 100644 --- a/pkg/ui/db/create.go +++ b/pkg/ui/conn/db/create.go @@ -10,7 +10,7 @@ import ( tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" config "github.com/prompt-ops/pops/pkg/config" - "github.com/prompt-ops/pops/pkg/connection" + "github.com/prompt-ops/pops/pkg/conn" "github.com/prompt-ops/pops/pkg/ui" ) @@ -26,11 +26,11 @@ const ( stepCreateDone ) -var availableDatabaseConnections = connection.AvailableDatabaseConnectionTypes +var availableDatabaseConnections = conn.AvailableDatabaseConnectionTypes type ( doneWaitingMsg struct { - Connection connection.Connection + Connection conn.Connection } errMsg struct { @@ -43,8 +43,8 @@ type createModel struct { cursor int connectionString string - selectedDatabaseConnection connection.AvailableDatabaseConnectionType - connection connection.Connection + selectedDatabaseConnection conn.AvailableDatabaseConnectionType + connection conn.Connection input textinput.Model connectionInput textinput.Model @@ -56,7 +56,7 @@ type createModel struct { func NewCreateModel() *createModel { ti := textinput.New() - ti.Placeholder = "Enter connection name..." + ti.Placeholder = ui.EnterConnectionNameMessage ti.CharLimit = 256 ti.Width = 30 @@ -162,7 +162,7 @@ func (m *createModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, nil } - m.connection = connection.NewDatabaseConnection(name, m.selectedDatabaseConnection, m.connectionString) + m.connection = conn.NewDatabaseConnection(name, m.selectedDatabaseConnection, m.connectionString) if err := config.SaveConnection(m.connection); err != nil { m.err = err m.currentStep = stepCreateDone @@ -194,7 +194,7 @@ func (m *createModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case errMsg: m.err = msg.err m.currentStep = stepCreateDone - m.connection = connection.Connection{} + m.connection = conn.Connection{} return m, nil case tea.KeyMsg: if quitCmd := handleQuit(msg); quitCmd != nil { @@ -231,7 +231,7 @@ func (m *createModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, tea.Batch(cmds...) } -func waitTwoSecondsCmd(conn connection.Connection) tea.Cmd { +func waitTwoSecondsCmd(conn conn.Connection) tea.Cmd { return tea.Tick(2*time.Second, func(t time.Time) tea.Msg { return doneWaitingMsg{ Connection: conn, @@ -287,7 +287,7 @@ func (m *createModel) View() string { if m.err != nil { return clearScreen + fmt.Sprintf("❌ Error: %v\n\nPress 'q', 'esc', or Ctrl+C to quit.", m.err) } - return clearScreen + fmt.Sprintf("Saving connection... %s", m.spinner.View()) + return clearScreen + fmt.Sprintf("Saving conn... %s", m.spinner.View()) case stepCreateDone: if m.err != nil { diff --git a/pkg/ui/db/doc.go b/pkg/ui/conn/db/doc.go similarity index 100% rename from pkg/ui/db/doc.go rename to pkg/ui/conn/db/doc.go diff --git a/pkg/ui/db/open.go b/pkg/ui/conn/db/open.go similarity index 91% rename from pkg/ui/db/open.go rename to pkg/ui/conn/db/open.go index 439ded6..d622e9f 100644 --- a/pkg/ui/db/open.go +++ b/pkg/ui/conn/db/open.go @@ -7,7 +7,7 @@ import ( tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" config "github.com/prompt-ops/pops/pkg/config" - "github.com/prompt-ops/pops/pkg/connection" + "github.com/prompt-ops/pops/pkg/conn" "github.com/prompt-ops/pops/pkg/ui" ) @@ -30,8 +30,8 @@ type ( type model struct { currentStep step cursor int - connections []connection.Connection - selected connection.Connection + connections []conn.Connection + selected conn.Connection err error spinner spinner.Model } @@ -57,7 +57,7 @@ func (m model) Init() tea.Cmd { // loadConnectionsCmd fetches existing database connections func (m model) loadConnectionsCmd() tea.Cmd { return func() tea.Msg { - databaseConnections, err := config.GetConnectionsByType(connection.ConnectionTypeDatabase) + databaseConnections, err := config.GetConnectionsByType(conn.ConnectionTypeDatabase) if err != nil { return err } @@ -72,7 +72,7 @@ func (m model) loadConnectionsCmd() tea.Cmd { // connectionsMsg holds the list of database connections type connectionsMsg struct { - connections []connection.Connection + connections []conn.Connection } // Update handles incoming messages and updates the model accordingly @@ -140,7 +140,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } // transitionCmd sends the TransitionToShellMsg after spinner -func transitionCmd(conn connection.Connection) tea.Cmd { +func transitionCmd(conn conn.Connection) tea.Cmd { return func() tea.Msg { return ui.TransitionToShellMsg{ Connection: conn, @@ -166,7 +166,7 @@ func (m model) View() string { } s += unselectedStyle.Render(fmt.Sprintf("%s%s", cursor, conn.Name)) + "\n" } - s += "\n" + helpStyle.Render("Press 'q' or 'esc' or Ctrl+C to quit.") + s += "\n" + helpStyle.Render(ui.QuitMessage) return clearScreen + s case stepOpenSpinner: diff --git a/pkg/ui/db/types.go b/pkg/ui/conn/db/types.go similarity index 100% rename from pkg/ui/db/types.go rename to pkg/ui/conn/db/types.go diff --git a/pkg/ui/kubernetes/create.go b/pkg/ui/conn/k8s/create.go similarity index 91% rename from pkg/ui/kubernetes/create.go rename to pkg/ui/conn/k8s/create.go index ec30f76..dab0ec4 100644 --- a/pkg/ui/kubernetes/create.go +++ b/pkg/ui/conn/k8s/create.go @@ -1,4 +1,4 @@ -package kubernetes +package k8s import ( "fmt" @@ -11,7 +11,7 @@ import ( tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" config "github.com/prompt-ops/pops/pkg/config" - "github.com/prompt-ops/pops/pkg/connection" + "github.com/prompt-ops/pops/pkg/conn" "github.com/prompt-ops/pops/pkg/ui" ) @@ -29,7 +29,7 @@ const ( type ( doneWaitingMsg struct { - Connection connection.Connection + Connection conn.Connection } contextsMsg struct { @@ -53,13 +53,13 @@ type createModel struct { // Spinner for the 2-second wait spinner spinner.Model - connection connection.Connection + connection conn.Connection } // NewCreateModel initializes the createModel for Kubernetes func NewCreateModel() *createModel { ti := textinput.New() - ti.Placeholder = "Enter connection name..." + ti.Placeholder = ui.EnterConnectionNameMessage ti.CharLimit = 256 ti.Width = 30 @@ -93,7 +93,7 @@ func (m *createModel) loadContextsCmd() tea.Cmd { } // waitTwoSecondsCmd simulates a delay for saving the connection asynchronously -func waitTwoSecondsCmd(conn connection.Connection) tea.Cmd { +func waitTwoSecondsCmd(conn conn.Connection) tea.Cmd { return tea.Tick(2*time.Second, func(t time.Time) tea.Msg { return doneWaitingMsg{ Connection: conn, @@ -167,7 +167,7 @@ func (m *createModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, nil } - connection := connection.NewKubernetesConnection(name, m.selectedCtx) + connection := conn.NewKubernetesConnection(name, m.selectedCtx) if err := config.SaveConnection(connection); err != nil { m.err = err return m, nil @@ -203,7 +203,7 @@ func (m *createModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case errMsg: m.err = msg.err m.currentStep = stepCreateDone - m.connection = connection.Connection{} + m.connection = conn.Connection{} return m, nil case tea.KeyMsg: @@ -254,7 +254,7 @@ func (m *createModel) View() string { } s += unselectedStyle.Render(cursor+ctx) + "\n" } - s += "\n" + helpStyle.Render("Press 'q' or 'esc' or Ctrl+C to quit.") + s += "\n" + helpStyle.Render(ui.QuitMessage) return clearScreen + s case stepEnterConnectionName: @@ -265,11 +265,11 @@ func (m *createModel) View() string { s += "\n" } s += m.input.View() - s += "\n" + helpStyle.Render("Press 'q' or 'esc' or Ctrl+C to quit.") + s += "\n" + helpStyle.Render(ui.QuitMessage) return clearScreen + s case stepCreateSpinner: - return clearScreen + outputStyle.Render("Saving connection... ") + m.spinner.View() + return clearScreen + outputStyle.Render("Saving conn... ") + m.spinner.View() case stepCreateDone: if m.err != nil { diff --git a/pkg/ui/kubernetes/doc.go b/pkg/ui/conn/k8s/doc.go similarity index 77% rename from pkg/ui/kubernetes/doc.go rename to pkg/ui/conn/k8s/doc.go index 055a224..13223f8 100644 --- a/pkg/ui/kubernetes/doc.go +++ b/pkg/ui/conn/k8s/doc.go @@ -1,3 +1,3 @@ -package kubernetes +package k8s // This package provides Kubernetes UI components and utilities. diff --git a/pkg/ui/kubernetes/open.go b/pkg/ui/conn/k8s/open.go similarity index 90% rename from pkg/ui/kubernetes/open.go rename to pkg/ui/conn/k8s/open.go index 620c54f..dafbb4a 100644 --- a/pkg/ui/kubernetes/open.go +++ b/pkg/ui/conn/k8s/open.go @@ -1,4 +1,4 @@ -package kubernetes +package k8s import ( "fmt" @@ -6,7 +6,7 @@ import ( "github.com/charmbracelet/bubbles/spinner" tea "github.com/charmbracelet/bubbletea" config "github.com/prompt-ops/pops/pkg/config" - "github.com/prompt-ops/pops/pkg/connection" + "github.com/prompt-ops/pops/pkg/conn" "github.com/prompt-ops/pops/pkg/ui" ) @@ -26,8 +26,8 @@ type ( type openModel struct { currentStep step cursor int - connections []connection.Connection - selected connection.Connection + connections []conn.Connection + selected conn.Connection err error // Spinner for transitions @@ -56,7 +56,7 @@ func (m *openModel) Init() tea.Cmd { // loadConnectionsCmd fetches existing Kubernetes connections func (m *openModel) loadConnectionsCmd() tea.Cmd { return func() tea.Msg { - k8sConnections, err := config.GetConnectionsByType(connection.ConnectionTypeKubernetes) + k8sConnections, err := config.GetConnectionsByType(conn.ConnectionTypeKubernetes) if err != nil { return err } @@ -71,7 +71,7 @@ func (m *openModel) loadConnectionsCmd() tea.Cmd { // connectionsMsg holds the list of Kubernetes connections type connectionsMsg struct { - connections []connection.Connection + connections []conn.Connection } // Update handles incoming messages and updates the openModel accordingly @@ -140,7 +140,7 @@ func (m *openModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, cmd } -func transitionCmd(conn connection.Connection) tea.Cmd { +func transitionCmd(conn conn.Connection) tea.Cmd { return func() tea.Msg { return ui.TransitionToShellMsg{ Connection: conn, @@ -165,7 +165,7 @@ func (m *openModel) View() string { } s += unselectedStyle.Render(fmt.Sprintf("%s%s", cursor, conn.Name)) + "\n" } - s += "\n" + helpStyle.Render("Press 'q' or 'esc' or Ctrl+C to quit.") + s += "\n" + helpStyle.Render(ui.QuitMessage) return clearScreen + s case stepOpenSpinner: diff --git a/pkg/ui/kubernetes/types.go b/pkg/ui/conn/k8s/types.go similarity index 95% rename from pkg/ui/kubernetes/types.go rename to pkg/ui/conn/k8s/types.go index 6f5866b..f4636d5 100644 --- a/pkg/ui/kubernetes/types.go +++ b/pkg/ui/conn/k8s/types.go @@ -1,4 +1,4 @@ -package kubernetes +package k8s import "github.com/charmbracelet/lipgloss" diff --git a/cmd/pops/app/connection/open.go b/pkg/ui/conn/open.go similarity index 51% rename from cmd/pops/app/connection/open.go rename to pkg/ui/conn/open.go index f9ad4ee..19f399b 100644 --- a/cmd/pops/app/connection/open.go +++ b/pkg/ui/conn/open.go @@ -1,60 +1,23 @@ -package connection +package conn import ( "fmt" "github.com/prompt-ops/pops/pkg/config" - "github.com/prompt-ops/pops/pkg/connection" "github.com/prompt-ops/pops/pkg/ui" "github.com/charmbracelet/bubbles/table" tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" "github.com/fatih/color" - "github.com/spf13/cobra" ) -// newOpenCmd creates the open command -func newOpenCmd() *cobra.Command { - openCmd := &cobra.Command{ - Use: "open", - Short: "Open a connection", - Long: "Open a connection", - Run: func(cmd *cobra.Command, args []string) { - if len(args) == 1 { - conn, err := config.GetConnectionByName(args[0]) - if err != nil { - color.Red("Error getting connection: %v", err) - return - } - - shell := ui.NewShellModel(conn) - p := tea.NewProgram(shell) - if _, err := p.Run(); err != nil { - color.Red("Error opening shell UI: %v", err) - } - } else { - root := NewOpenRootModel() - p := tea.NewProgram(root) - if _, err := p.Run(); err != nil { - color.Red("Error: %v", err) - return - } - } - }, - } - - return openCmd -} - -// The root model for "open" type openRootModel struct { step openStep tableModel tableModel shellModel tea.Model } -// openStep enumerates which sub-UI is active. type openStep int const ( @@ -62,28 +25,19 @@ const ( stepShell ) -// connectionSelectedMsg signals that the user picked a connection -type connectionSelectedMsg struct { - Conn connection.Connection -} - type tableModel interface { tea.Model Selected() string } -// NewOpenRootModel creates the root model in "pick" mode +// NewOpenRootModel initializes the openRootModel with connections. func NewOpenRootModel() *openRootModel { - // Build the table connections, err := config.GetAllConnections() if err != nil { - // In a real app, handle this more gracefully color.Red("Error getting connections: %v", err) - // Return an empty model or handle error return &openRootModel{} } - // Prepare rows items := make([]table.Row, len(connections)) for i, conn := range connections { items[i] = table.Row{conn.Name, conn.Type.GetMainType(), conn.Type.GetSubtype()} @@ -117,15 +71,11 @@ func NewOpenRootModel() *openRootModel { onSelect := func(selected string) tea.Msg { conn, err := config.GetConnectionByName(selected) if err != nil { - return func() tea.Msg { - return fmt.Errorf("error getting connection %s: %w", selected, err) - } + return fmt.Errorf("error getting connection %s: %w", selected, err) } - return func() tea.Msg { - return connectionSelectedMsg{ - Conn: conn, - } + return ui.TransitionToShellMsg{ + Connection: conn, } } @@ -137,60 +87,51 @@ func NewOpenRootModel() *openRootModel { } } -// Init initializes whichever sub-UI we’re starting with +// Init initializes the openRootModel. func (m *openRootModel) Init() tea.Cmd { - // Start with the table model return m.tableModel.Init() } -// Update handles messages. -// If we get a `connectionSelectedMsg`, we switch to the shell. +// Update handles messages and updates the model state. func (m *openRootModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg := msg.(type) { - case connectionSelectedMsg: - fmt.Println("Selected connection:", msg.Conn.Name) - - // The user picked a connection from the table. Build the shell model: - m.shellModel = ui.NewShellModel(msg.Conn) + case ui.TransitionToShellMsg: + fmt.Println("Selected connection:", msg.Connection.Name) + m.shellModel = ui.NewShellModel(msg.Connection) m.step = stepShell - // Return the shell model as the new top-level model with its Init. return m.shellModel, m.shellModel.Init() - // If the table tried to look up the connection and failed case error: color.Red("Error: %v", msg) - // You could handle it, or just stay in the table. - + return m, nil } - // If we’re not transitioning, update the current sub-UI if m.step == stepPick { var cmd tea.Cmd updatedTable, cmd := m.tableModel.Update(msg) - // Because tableModel is an interface, we need to store it back: m.tableModel = updatedTable.(tableModel) return m, cmd } - // If we’re in shell mode, pass the message to the shell if m.step == stepShell && m.shellModel != nil { var cmd tea.Cmd m.shellModel, cmd = m.shellModel.Update(msg) return m, cmd } - // Default fallback return m, nil } -// View renders whichever sub-UI we’re using +// View renders the current view based on the model state. func (m *openRootModel) View() string { if m.step == stepPick { return m.tableModel.View() } + if m.step == stepShell && m.shellModel != nil { return m.shellModel.View() } + return "No view" } diff --git a/pkg/ui/shell.go b/pkg/ui/shell.go index b285033..758e111 100644 --- a/pkg/ui/shell.go +++ b/pkg/ui/shell.go @@ -8,7 +8,7 @@ import ( "github.com/charmbracelet/bubbles/textinput" tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" - "github.com/prompt-ops/pops/pkg/connection" + "github.com/prompt-ops/pops/pkg/conn" ) var ( @@ -72,15 +72,15 @@ type shellModel struct { err error history []historyEntry historyIndex int - connection connection.Connection - popsConnection connection.ConnectionInterface + connection conn.Connection + popsConnection conn.ConnectionInterface spinner spinner.Model checkPassed bool mode queryMode windowWidth int } -func NewShellModel(conn connection.Connection) shellModel { +func NewShellModel(connection conn.Connection) shellModel { ti := textinput.New() ti.Placeholder = "Enter your prompt..." ti.Focus() @@ -96,7 +96,7 @@ func NewShellModel(conn connection.Connection) shellModel { sp.Spinner = spinner.Dot // Get the right connection implementation - popsConn, err := connection.GetConnection(conn) + popsConn, err := conn.GetConnection(connection) if err != nil { panic(err) } @@ -106,7 +106,7 @@ func NewShellModel(conn connection.Connection) shellModel { promptInput: ti, confirmInput: ci, history: []historyEntry{}, - connection: conn, + connection: connection, popsConnection: popsConn, spinner: sp, mode: modeCommand, @@ -165,7 +165,6 @@ func (m shellModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, cmd case stepShowContext: - // This step is now handled in the checkPassedMsg case return m, nil case stepEnterPrompt: @@ -499,11 +498,17 @@ func (m shellModel) runCommand(command string) tea.Cmd { return errMsg{err} } + fmt.Println("Output:") + fmt.Println(string(out)) + outStr, err := m.popsConnection.FormatResultAsTable(out) if err != nil { return errMsg{err} } + fmt.Println("Formatted Output:") + fmt.Println(outStr) + return outputMsg{ output: outStr, } diff --git a/pkg/ui/types.go b/pkg/ui/types.go index 5829bbd..d1a2891 100644 --- a/pkg/ui/types.go +++ b/pkg/ui/types.go @@ -1,15 +1,25 @@ package ui -import "github.com/prompt-ops/pops/pkg/connection" +import ( + "github.com/prompt-ops/pops/pkg/conn" +) type answerMsg struct { answer string } type TransitionToShellMsg struct { - Connection connection.Connection + Connection conn.Connection } type TransitionToCreateMsg struct { ConnectionType string } + +var ( + // EnterConnectionNameMessage is the message displayed when the user is prompted to enter a connection name. + EnterConnectionNameMessage = "Enter connection name:" + + // QuitMessage is the message displayed to show user how to quit the application. + QuitMessage = "Press 'q' or 'esc' or Ctrl+C to quit." +)