@@ -618,12 +618,8 @@ Examples:
618618// OutputService represents a service with computed fields for output
619619type OutputService struct {
620620 api.Service
621- ConnectionString * string `json:"connection_string,omitempty" yaml:"connection_string,omitempty"`
622- Password * string `json:"password,omitempty" yaml:"password,omitempty"`
623- Role * string `json:"role,omitempty" yaml:"role,omitempty"`
624- Host * string `json:"host,omitempty" yaml:"host,omitempty"`
625- Port * int `json:"port,omitempty" yaml:"port,omitempty"`
626- Database * string `json:"database,omitempty" yaml:"database,omitempty"`
621+ password.ConnectionDetails
622+ ConnectionString string `json:"connection_string,omitempty" yaml:"connection_string,omitempty"`
627623}
628624
629625// Convert to JSON to respect omitempty tags, then unmarshal
@@ -693,20 +689,12 @@ func outputServices(cmd *cobra.Command, services []api.Service, format string, w
693689
694690// outputServiceEnv outputs service details in environment variable format
695691func outputServiceEnv (service OutputService , output io.Writer ) error {
696- if service .Host != nil {
697- fmt .Fprintf (output , "PGHOST=%s\n " , * service .Host )
698- }
699- if service .Role != nil {
700- fmt .Fprintf (output , "PGUSER=%s\n " , * service .Role )
701- }
702- if service .Password != nil {
703- fmt .Fprintf (output , "PGPASSWORD=%s\n " , * service .Password )
704- }
705- if service .Database != nil {
706- fmt .Fprintf (output , "PGDATABASE=%s\n " , * service .Database )
707- }
708- if service .Port != nil {
709- fmt .Fprintf (output , "PGPORT=%d\n " , * service .Port )
692+ fmt .Fprintf (output , "PGHOST=%s\n " , service .Host )
693+ fmt .Fprintf (output , "PGPORT=%d\n " , service .Port )
694+ fmt .Fprintf (output , "PGDATABASE=%s\n " , service .Database )
695+ fmt .Fprintf (output , "PGUSER=%s\n " , service .Role )
696+ if service .Password != "" {
697+ fmt .Fprintf (output , "PGPASSWORD=%s\n " , service .Password )
710698 }
711699 return nil
712700}
@@ -788,13 +776,13 @@ func outputServiceTable(service OutputService, output io.Writer) error {
788776 }
789777
790778 // Output password if available
791- if service .Password != nil {
792- table .Append ("Password" , * service .Password )
779+ if service .Password != "" {
780+ table .Append ("Password" , service .Password )
793781 }
794782
795783 // Output connection string if available
796- if service .ConnectionString != nil {
797- table .Append ("Connection String" , * service .ConnectionString )
784+ if service .ConnectionString != "" {
785+ table .Append ("Connection String" , service .ConnectionString )
798786 }
799787
800788 return table .Render ()
@@ -813,7 +801,7 @@ func outputServicesTable(services []OutputService, output io.Writer) error {
813801 util .DerefStr (service .ServiceType ),
814802 util .Deref (service .RegionCode ),
815803 formatTimePtr (service .Created ),
816- util . Deref ( service .ConnectionString ) ,
804+ service .ConnectionString ,
817805 )
818806 }
819807
@@ -844,21 +832,15 @@ func prepareServiceForOutput(service api.Service, withPassword bool, output io.W
844832 fmt .Fprintf (output , "⚠️ Warning: Failed to get connection details: %v\n " , err )
845833 }
846834 } else {
847- outputSvc .Role = & connectionDetails .Role
848- outputSvc .Host = & connectionDetails .Host
849- outputSvc .Port = & connectionDetails .Port
850- outputSvc .Database = & connectionDetails .Database
851- if connectionDetails .Password != "" {
852- outputSvc .Password = & connectionDetails .Password
853- }
835+ outputSvc .ConnectionDetails = * connectionDetails
854836 }
855837
856838 if connectionString , err := password .BuildConnectionString (service , opts ); err != nil {
857839 if output != nil {
858840 fmt .Fprintf (output , "⚠️ Warning: Failed to get connection string: %v\n " , err )
859841 }
860842 } else {
861- outputSvc .ConnectionString = & connectionString
843+ outputSvc .ConnectionString = connectionString
862844 }
863845
864846 return outputSvc
0 commit comments