diff --git a/cmd/root.go b/cmd/root.go index f624a20..69d7481 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -30,6 +30,7 @@ var cfgFile string var ( insecure bool + defaultPwd string ) // rootCmd represents the base command when called without any subcommands @@ -48,6 +49,7 @@ to quickly create a Cobra application.`, shared.OpenBrowser("https://bl3.swiss.dev/") opts := server.Options{} opts.Insecure = insecure + opts.DefaultPwd = defaultPwd if err := server.Start(opts); err != nil { panic(err) } @@ -74,6 +76,8 @@ func init() { // Cobra also supports local flags, which will only run // when this action is called directly. rootCmd.Flags().BoolVar(&insecure, "insecure", false, "Run server without cors protection") + var currentPwd, _ = os.Getwd() + rootCmd.Flags().StringVar(&defaultPwd, "path", currentPwd, "Path to save file directory") } // initConfig reads in config file and ENV variables if set. diff --git a/internal/server/options.go b/internal/server/options.go index 86784c1..552586c 100644 --- a/internal/server/options.go +++ b/internal/server/options.go @@ -2,4 +2,5 @@ package server type Options struct { Insecure bool + DefaultPwd string } diff --git a/internal/server/server.go b/internal/server/server.go index 296e312..e14fe56 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -17,10 +17,6 @@ var ( BuiltBy = "" ) -func init() { - pwd, _ = os.Getwd() -} - func Start(opts Options) error { gin.SetMode(gin.ReleaseMode) r := gin.New() @@ -38,6 +34,7 @@ func Start(opts Options) error { } else { cfg.AllowOrigins = []string{"https://bl3.swiss.dev", "http://localhost:4200"} } + pwd = opts.DefaultPwd r.Use(cors.New(cfg)) r.GET("/stats", func(c *gin.Context) {