use new interactive db connection in runner
This commit is contained in:
@@ -31,27 +31,36 @@ func runStartCmd(cmd *cobra.Command, args []string) error {
|
|||||||
return fmt.Errorf("application services are not available")
|
return fmt.Errorf("application services are not available")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(args) == 0 {
|
if !cmd.Flags().Changed("dev") {
|
||||||
var noSubmit bool
|
var mongoStorage *storage.MongoStorage
|
||||||
cmd.Println("No MongoDB password provided, survey responses will not be submitted.")
|
var continueWithoutSubmitting bool
|
||||||
cmd.Println("you can manually submit later with `pm survey submit <mongo-password>`.")
|
|
||||||
|
|
||||||
huh.NewConfirm().Title("Are you sure you want to continue without submiting data?").
|
for {
|
||||||
Value(&noSubmit).RunAccessible(cmd.OutOrStdout(), cmd.InOrStdin())
|
db, err := storage.NewMongoStorageInteractive(app.Config.MongoURI)
|
||||||
|
if err == nil {
|
||||||
|
mongoStorage = db
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
if !noSubmit {
|
cmd.Println("Failed to connect to database, survey responses will not be submitted.")
|
||||||
cmd.Println("Exiting. Please run the command again with a MongoDB password to submit your data.")
|
|
||||||
return nil
|
if err := huh.NewConfirm().
|
||||||
|
Title("Do you want to continue without submitting your responses?").
|
||||||
|
Description("You can fix your database connection and submit your responses later with the submit command.").
|
||||||
|
Value(&continueWithoutSubmitting).
|
||||||
|
WithTheme(huh.ThemeBase16()).
|
||||||
|
RunAccessible(cmd.OutOrStdout(), cmd.InOrStdin()); err != nil {
|
||||||
|
return fmt.Errorf("failed to read user input: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if continueWithoutSubmitting {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
mongoPass := args[0]
|
if mongoStorage != nil {
|
||||||
mongoStorage, err := storage.NewMongoStorage(app.Config.MongoURI, "participant", mongoPass)
|
cmd.Println("Connected to Database Successfully. Starting survey...")
|
||||||
if err != nil {
|
time.Sleep(2 * time.Second)
|
||||||
cmd.Println("Failed to connect to MongoDB, survey responses will not be submitted.")
|
|
||||||
cmd.Println("You can manually submit later with `pm survey submit <password>`.")
|
|
||||||
return nil
|
|
||||||
} else {
|
|
||||||
cmd.Println("Connected to MongoDB successfully.")
|
|
||||||
|
|
||||||
defer mongoStorage.Close()
|
defer mongoStorage.Close()
|
||||||
|
|
||||||
@@ -76,6 +85,9 @@ func runStartCmd(cmd *cobra.Command, args []string) error {
|
|||||||
if err := mongoStorage.SubmitSurveyResponsesCmd(ctx); err != nil {
|
if err := mongoStorage.SubmitSurveyResponsesCmd(ctx); err != nil {
|
||||||
cmd.Printf("Failed to submit survey responses: %v\n", err)
|
cmd.Printf("Failed to submit survey responses: %v\n", err)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
cmd.Println("Starting survey without database connection. Your responses will not be submitted...")
|
||||||
|
time.Sleep(2 * time.Second)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,11 +112,11 @@ func runStartCmd(cmd *cobra.Command, args []string) error {
|
|||||||
survey.Task: surveyTasks[survey.Task],
|
survey.Task: surveyTasks[survey.Task],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if !cmd.Flag("dev").Changed {
|
||||||
if err := newIntroModel().Run(); err != nil {
|
if err := newIntroModel().Run(); err != nil {
|
||||||
return returnIfUserQuit(err, "failed to run intro")
|
return returnIfUserQuit(err, "failed to run intro")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := taskLoop(cmd.Context(), app, surveyTasks, interfaces); err != nil {
|
if err := taskLoop(cmd.Context(), app, surveyTasks, interfaces); err != nil {
|
||||||
return returnIfUserQuit(err, "task loop failed")
|
return returnIfUserQuit(err, "task loop failed")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user