diff --git a/cli/commands/backend.go b/cli/commands/backend.go index 838883709..f59940e56 100644 --- a/cli/commands/backend.go +++ b/cli/commands/backend.go @@ -10,29 +10,29 @@ import ( ) var backendCmd = &cli.Command{ - Name: "backend", - Usage: "Starts the backend server in development mode", - Action: func(c *cli.Context) error { - cmd := exec.Command("go", "run", "backend/main.go", "--use-dev-dot-env") - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - err := cmd.Run() - if err != nil { - return fmt.Errorf("error starting backend: %w", err) - } - return nil - }, + Name: "backend", + Usage: "Starts the backend server in development mode", + Action: func(c *cli.Context) error { + cmd := exec.Command("go", "run", "backend/main.go", "--use-dev-dot-env") + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + err := cmd.Run() + if err != nil { + return fmt.Errorf("error starting backend: %w", err) + } + return nil + }, } func BackendCommand() *cli.Command { command := &cli.Command{ - Name: "backend", - Usage: "Starts the backend server", + Name: "backend", + Usage: "Starts the backend server", Aliases: []string{"be"}, Flags: []cli.Flag{ &cli.BoolFlag{ - Name: "use-dev-dot-env", - Usage: "Use the .env file in the backend directory", + Name: "use-dev-dot-env", + Usage: "Use the .env file in the backend directory", Aliases: []string{"d"}, }, }, @@ -56,4 +56,4 @@ func RunBackend() error { return fmt.Errorf("error starting backend: %w", err) } return nil -} \ No newline at end of file +} diff --git a/cli/commands/clean_tests.go b/cli/commands/clean_tests.go index c1f79c6bd..da92e3db7 100644 --- a/cli/commands/clean_tests.go +++ b/cli/commands/clean_tests.go @@ -34,62 +34,62 @@ func ClearDBCommand() *cli.Command { } func CleanTestDBs() error { - fmt.Println("Cleaning test databases") + fmt.Println("Cleaning test databases") - db, err := sql.Open("postgres", CONFIG.Database.WithDb()) - if err != nil { - return err - } + db, err := sql.Open("postgres", CONFIG.Database.WithDb()) + if err != nil { + return err + } - defer db.Close() + defer db.Close() - currentUser, err := user.Current() - if err != nil { - return fmt.Errorf("failed to get current user: %w", err) - } + currentUser, err := user.Current() + if err != nil { + return fmt.Errorf("failed to get current user: %w", err) + } - query := "SELECT datname FROM pg_database WHERE datistemplate = false AND datname != 'postgres' AND datname != $1 AND datname != $2 AND datname LIKE 'sac_test_%';" - rows, err := db.Query(query, currentUser.Username, CONFIG.Database.DatabaseName) - if err != nil { - return err - } + query := "SELECT datname FROM pg_database WHERE datistemplate = false AND datname != 'postgres' AND datname != $1 AND datname != $2 AND datname LIKE 'sac_test_%';" + rows, err := db.Query(query, currentUser.Username, CONFIG.Database.DatabaseName) + if err != nil { + return err + } - defer rows.Close() + defer rows.Close() - var wg sync.WaitGroup - var dropped, failed int + var wg sync.WaitGroup + var dropped, failed int - for rows.Next() { - var dbName string + for rows.Next() { + var dbName string - if err := rows.Scan(&dbName); err != nil { - return err - } + if err := rows.Scan(&dbName); err != nil { + return err + } - wg.Add(1) + wg.Add(1) - go func(dbName string) { - defer wg.Done() + go func(dbName string) { + defer wg.Done() - fmt.Printf("Dropping database %s\n", dbName) + fmt.Printf("Dropping database %s\n", dbName) - _, err := db.Exec(fmt.Sprintf("DROP DATABASE %s", dbName)) - if err != nil { - fmt.Printf("Failed to drop database %s: %v\n", dbName, err) - failed++ - } else { - dropped++ - } - }(dbName) - } + _, err := db.Exec(fmt.Sprintf("DROP DATABASE %s", dbName)) + if err != nil { + fmt.Printf("Failed to drop database %s: %v\n", dbName, err) + failed++ + } else { + dropped++ + } + }(dbName) + } - wg.Wait() + wg.Wait() - fmt.Printf("\nSummary:\n - Databases dropped: %d\n - Databases failed to drop: %d\n", dropped, failed) + fmt.Printf("\nSummary:\n - Databases dropped: %d\n - Databases failed to drop: %d\n", dropped, failed) - if failed > 0 { - return fmt.Errorf("failed to drop %d database(s)", failed) - } + if failed > 0 { + return fmt.Errorf("failed to drop %d database(s)", failed) + } - return nil + return nil }