From d3a93968f42650aa865a75f49ae765fa6f3ce40b Mon Sep 17 00:00:00 2001 From: nicksherron Date: Mon, 10 Feb 2020 02:31:44 -0500 Subject: [PATCH] second release --- README.md | 3 ++- cmd/root.go | 39 +++++++++++++++++++++++++++++---------- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 76c4ff0..6f0c4b8 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,7 @@ Then add ```export BH_HOST=localhost:8080``` (or whatever you set your bashhub-s Thats it! Restart your shell with `$SHELL` then re-configure bashhub-client to use your new server by re-running ```bashhub setup``` . -### Setting DB +### Changing default db + ### Using Regex diff --git a/cmd/root.go b/cmd/root.go index f919c11..c68901a 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -23,6 +23,7 @@ import ( "log" "os" "path/filepath" + "strings" "github.com/fatih/color" "github.com/nicksherron/bashhub-server/internal" @@ -32,13 +33,19 @@ import ( var cfgFile string // rootCmd represents the base command when called without any subcommands -var rootCmd = &cobra.Command{ - Run: func(cmd *cobra.Command, args []string) { - cmd.Flags().Parse(args) - startupMessage() - internal.Run() - }, -} +var ( + noWarning bool + rootCmd = &cobra.Command{ + Run: func(cmd *cobra.Command, args []string) { + cmd.Flags().Parse(args) + if !noWarning { + checkBhEnv() + } + startupMessage() + internal.Run() + }, + } +) // Execute runs root command func Execute() { @@ -50,9 +57,10 @@ func Execute() { func init() { cobra.OnInitialize() - rootCmd.PersistentFlags().StringVar(&internal.LogFile, "log", "", `Set filepath for HTTP log. "" logs to stderr.`) + rootCmd.PersistentFlags().StringVar(&internal.LogFile, "log", "", `Set filepath for HTTP log. "" logs to stderr`) rootCmd.PersistentFlags().StringVar(&internal.DbPath, "db", dbPath(), "DB location (sqlite or postgres)") - rootCmd.PersistentFlags().StringVarP(&internal.Addr, "addr", "a", listenAddr(), "Ip and port to listen and serve on.") + rootCmd.PersistentFlags().StringVarP(&internal.Addr, "addr", "a", listenAddr(), "Ip and port to listen and serve on") + rootCmd.PersistentFlags().BoolVarP(&noWarning, "warning-disable", "w", false, `Disable BH_URL env variable startup warning`) } @@ -74,7 +82,7 @@ func startupMessage() { color.HiGreen(banner) fmt.Print("\n") log.Printf("Listening and serving HTTP on %v", internal.Addr) - fmt.Print("\n\n") + fmt.Print("\n") } func listenAddr() string { @@ -108,3 +116,14 @@ func appDir() string { return ch } +func checkBhEnv() { + addr := strings.ReplaceAll(internal.Addr, "http://", "") + bhURL := os.Getenv("BH_URL") + if strings.Contains(bhURL, "https://bashhub.com") { + msg := fmt.Sprintf(` +WARNING: BH_URL is to https://bashhub.com on this machine +If you will be running bashhub-client locally be sure to add +export BH_URL=http://%v to your .bashrc or .zshrc`, addr) + fmt.Println(msg, "\n") + } +}