participant.go 644 B

12345678910111213141516171819202122232425262728293031
  1. package main
  2. import (
  3. "fmt"
  4. "log/slog"
  5. "git.andreafazzi.eu/andrea/probo/pkg/store/file"
  6. "github.com/urfave/cli/v2"
  7. )
  8. func importCSV(cCtx *cli.Context) error {
  9. path := cCtx.Args().First()
  10. if path == "" {
  11. return cli.Exit("Path for the CSV file not given.", 1)
  12. }
  13. pStore, err := file.NewDefaultParticipantFileStore()
  14. if err != nil {
  15. return cli.Exit(fmt.Sprintf("An error occurred: %v", err), 1)
  16. }
  17. participants, err := pStore.ImportCSV(path)
  18. if err != nil {
  19. return cli.Exit(fmt.Sprintf("An error occurred: %v", err), 1)
  20. }
  21. slog.Info("Imported participants from csv file", "nParticipants", len(participants))
  22. return nil
  23. }