main.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package main
  2. import (
  3. "log"
  4. "log/slog"
  5. "os"
  6. "time"
  7. "git.andreafazzi.eu/andrea/probo/pkg/store/file"
  8. "github.com/lmittmann/tint"
  9. "github.com/urfave/cli"
  10. )
  11. func main() {
  12. slog.SetDefault(slog.New(
  13. tint.NewHandler(os.Stdout, &tint.Options{
  14. Level: slog.LevelInfo,
  15. TimeFormat: time.Kitchen,
  16. }),
  17. ))
  18. _, err := os.Stat(file.DefaultBaseDir)
  19. if err != nil {
  20. slog.Info("Base directory not found. Creating the folder structure...")
  21. for _, dir := range file.Dirs {
  22. err := os.MkdirAll(dir, os.ModePerm)
  23. if err != nil {
  24. log.Fatal(err)
  25. }
  26. slog.Info("Create", "directory", dir)
  27. }
  28. slog.Info("Folder structure created without issues.")
  29. os.Exit(0)
  30. }
  31. app := &cli.App{
  32. Name: "probo-cli",
  33. Usage: "Quiz Management System for Hackers!",
  34. Commands: []*cli.Command{
  35. {
  36. Name: "session",
  37. Aliases: []string{"s"},
  38. Usage: "options for command 'session'",
  39. Subcommands: []*cli.Command{
  40. {
  41. Name: "push",
  42. Usage: "Create a new exam session",
  43. Action: push,
  44. },
  45. {
  46. Name: "pull",
  47. Usage: "Download responses from a session",
  48. Action: pull,
  49. },
  50. {
  51. Name: "scores",
  52. Usage: "Show the scores for the given session",
  53. Action: scores,
  54. },
  55. },
  56. },
  57. {
  58. Name: "participant",
  59. Aliases: []string{"p"},
  60. Usage: "options for command 'participant'",
  61. Subcommands: []*cli.Command{
  62. {
  63. Name: "import",
  64. Usage: "Import participants from a CSV file",
  65. Action: importCSV,
  66. },
  67. },
  68. },
  69. },
  70. }
  71. if err := app.Run(os.Args); err != nil {
  72. log.Fatal(err)
  73. }
  74. }