2023-12-27 15:05:11 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log/slog"
|
|
|
|
|
2024-02-06 09:03:57 +01:00
|
|
|
"git.andreafazzi.eu/andrea/probo/pkg/store/file"
|
2023-12-27 15:05:11 +01:00
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
func importCSV(cCtx *cli.Context) error {
|
|
|
|
path := cCtx.Args().First()
|
|
|
|
if path == "" {
|
|
|
|
return cli.Exit("Path for the CSV file not given.", 1)
|
|
|
|
}
|
|
|
|
|
2024-02-06 08:35:07 +01:00
|
|
|
pStore, err := file.NewDefaultParticipantFileStore()
|
2023-12-27 15:05:11 +01:00
|
|
|
if err != nil {
|
|
|
|
return cli.Exit(fmt.Sprintf("An error occurred: %v", err), 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
participants, err := pStore.ImportCSV(path)
|
|
|
|
if err != nil {
|
|
|
|
return cli.Exit(fmt.Sprintf("An error occurred: %v", err), 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
slog.Info("Imported participants from csv file", "nParticipants", len(participants))
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|