github.com/sqlitebrowser/dio@v0.0.0-20240125125356-b587368e5c6b/cmd/info.go (about) 1 package cmd 2 3 import ( 4 "fmt" 5 6 "github.com/spf13/cobra" 7 "github.com/spf13/viper" 8 ) 9 10 // Displays useful information about the dio installation 11 var infoCmd = &cobra.Command{ 12 Use: "info", 13 Short: "Displays useful information about the dio installation", 14 RunE: func(cmd *cobra.Command, args []string) error { 15 fmt.Printf("Dio version %s\n", DIO_VERSION) 16 17 // Display the path to the dio configuration file 18 if confPath := viper.ConfigFileUsed(); confPath != "" { 19 fmt.Println("Configuration file used:", confPath) 20 } 21 22 fmt.Printf("\n** Connection **\n\n") 23 24 // Display the connection URL used for DBHUB.io 25 if found := viper.IsSet("general.cloud"); found == true { 26 fmt.Printf("DBHub.io connection URL: %s\n", viper.Get("general.cloud")) 27 } else { 28 fmt.Println("No custom DBHub.io connection URL is set") 29 } 30 31 // Display the path to our CA Chain and user certificate 32 if found := viper.IsSet("certs.cachain"); found == true { 33 fmt.Printf("Path to CA chain file: %s\n", viper.Get("certs.cachain")) 34 } else { 35 fmt.Println("Path to CA chain not set in configuration file") 36 } 37 if found := viper.IsSet("certs.cert"); found == true { 38 fmt.Printf("Path to user certificate file: %s\n", viper.Get("certs.cert")) 39 } else { 40 fmt.Println("Path to user certificate not set in configuration file") 41 } 42 43 // TODO: Maybe display the user name, server, and expiry date from the cert file? 44 45 fmt.Printf("\n** Commit defaults **\n\n") 46 47 // Display the user name and email address used for commits 48 if found := viper.IsSet("user.name"); found == true { 49 fmt.Printf("User name for commits: %s\n", viper.Get("user.name")) 50 } else { 51 fmt.Println("User name not set in configuration file") 52 } 53 if found := viper.IsSet("user.email"); found == true { 54 fmt.Printf("Email address for commits: %s\n", viper.Get("user.email")) 55 } else { 56 fmt.Println("Email address not set in configuration file") 57 } 58 return nil 59 }, 60 } 61 62 func init() { 63 RootCmd.AddCommand(infoCmd) 64 }