From ce4c815ef586d2a7e1161b2c6a087cf9c0d7d252 Mon Sep 17 00:00:00 2001 From: Robin Olsen Date: Tue, 10 Mar 2026 13:31:18 +0100 Subject: [PATCH] use better naming for uri and check it --- internal/commands/survey/start.go | 2 ++ internal/commands/survey/submit.go | 7 ++++++- internal/models/config.go | 15 +++++++++++---- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/internal/commands/survey/start.go b/internal/commands/survey/start.go index 88e9621..4cd2fd9 100644 --- a/internal/commands/survey/start.go +++ b/internal/commands/survey/start.go @@ -23,4 +23,6 @@ func init() { StartCmd.Flags().StringVarP(&InterfaceType, "interface", "i", "", "Specify interface.") StartCmd.RegisterFlagCompletionFunc("task", shellcomp.CompletionFunc(task.ListTasks())) StartCmd.RegisterFlagCompletionFunc("interface", shellcomp.CompletionFunc(task.ListInterfaces())) + StartCmd.Flags().BoolVar(&DevFlag, "dev", false, "Enable development mode, which skips database connection, submission, task intro and questionare") + } diff --git a/internal/commands/survey/submit.go b/internal/commands/survey/submit.go index 3da9356..51ef9ef 100644 --- a/internal/commands/survey/submit.go +++ b/internal/commands/survey/submit.go @@ -17,7 +17,12 @@ var SubmitCmd = &cobra.Command{ return fmt.Errorf("application context not initialized") } - db, err := storage.NewMongoStorageInteractive(cmd.Context(), app.Config.MongoURI) + if app.Config.DB_URI == "" { + cmd.Println("No database URI provided in environment, survey responses will not be submitted.") + return nil + } + + db, err := storage.NewMongoStorageInteractive(cmd.Context(), app.Config.DB_URI) if err != nil { return fmt.Errorf("failed to connect to database: %w", err) } diff --git a/internal/models/config.go b/internal/models/config.go index 34fff5c..a2c788d 100644 --- a/internal/models/config.go +++ b/internal/models/config.go @@ -1,7 +1,9 @@ package models +import "os" + type Config struct { - MongoURI string + DB_URI string AutoInit bool RootCmd string WebAddress string @@ -12,7 +14,7 @@ type Config struct { } var BaseConfig = Config{ - MongoURI: "mongodb+srv://lazy.wf9kdi8.mongodb.net/", + DB_URI: "", AutoInit: false, RootCmd: "pm", IssuePrefix: "pm", @@ -21,8 +23,13 @@ var BaseConfig = Config{ StatisticsStoragePath: "./.pm/stats.json", } -func (c Config) WithMongoURI(uri string) Config { - c.MongoURI = uri +func (c Config) LoadFromEnv() Config { + c.DB_URI = os.Getenv("DB_URI") + return c +} + +func (c Config) WithDB_URI(uri string) Config { + c.DB_URI = uri return c }