use better naming for uri and check it

This commit is contained in:
Robin Olsen
2026-03-10 13:31:18 +01:00
parent 8945341250
commit ce4c815ef5
3 changed files with 19 additions and 5 deletions

View File

@@ -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")
}

View File

@@ -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)
}

View File

@@ -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
}