second release

This commit is contained in:
nicksherron 2020-02-10 02:31:44 -05:00
parent 6358b46a1f
commit d3a93968f4
2 changed files with 31 additions and 11 deletions

View file

@ -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 Thats it! Restart your shell with `$SHELL` then re-configure bashhub-client to use your new
server by re-running ```bashhub setup``` . server by re-running ```bashhub setup``` .
### Setting DB ### Changing default db
### Using Regex ### Using Regex

View file

@ -23,6 +23,7 @@ import (
"log" "log"
"os" "os"
"path/filepath" "path/filepath"
"strings"
"github.com/fatih/color" "github.com/fatih/color"
"github.com/nicksherron/bashhub-server/internal" "github.com/nicksherron/bashhub-server/internal"
@ -32,13 +33,19 @@ import (
var cfgFile string var cfgFile string
// rootCmd represents the base command when called without any subcommands // rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{ var (
Run: func(cmd *cobra.Command, args []string) { noWarning bool
cmd.Flags().Parse(args) rootCmd = &cobra.Command{
startupMessage() Run: func(cmd *cobra.Command, args []string) {
internal.Run() cmd.Flags().Parse(args)
}, if !noWarning {
} checkBhEnv()
}
startupMessage()
internal.Run()
},
}
)
// Execute runs root command // Execute runs root command
func Execute() { func Execute() {
@ -50,9 +57,10 @@ func Execute() {
func init() { func init() {
cobra.OnInitialize() 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().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) color.HiGreen(banner)
fmt.Print("\n") fmt.Print("\n")
log.Printf("Listening and serving HTTP on %v", internal.Addr) log.Printf("Listening and serving HTTP on %v", internal.Addr)
fmt.Print("\n\n") fmt.Print("\n")
} }
func listenAddr() string { func listenAddr() string {
@ -108,3 +116,14 @@ func appDir() string {
return ch 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")
}
}