68 lines
1.6 KiB
Go
68 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
|
|
"git.andreafazzi.eu/andrea/probo/models"
|
|
"git.andreafazzi.eu/andrea/probo/store/file"
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
func main() {
|
|
file.DefaultBaseDir = "testdata"
|
|
|
|
app := &cli.App{
|
|
Name: "probo-cli",
|
|
Usage: "Quiz Management System for Power Teachers!",
|
|
Commands: []*cli.Command{
|
|
{
|
|
Name: "session",
|
|
Aliases: []string{"s"},
|
|
Usage: "options for command 'session'",
|
|
Subcommands: []*cli.Command{
|
|
{
|
|
Name: "create",
|
|
Usage: "Create a new exam session",
|
|
Action: func(cCtx *cli.Context) error {
|
|
if cCtx.Args().Len() < 1 {
|
|
log.Fatalf("Please provide a session name as first argument of create.")
|
|
}
|
|
pStore, err := file.NewParticipantDefaultFileStore()
|
|
if err != nil {
|
|
log.Fatalf("An error occurred: %v", err)
|
|
}
|
|
qStore, err := file.NewDefaultQuizFileStore()
|
|
if err != nil {
|
|
log.Fatalf("An error occurred: %v", err)
|
|
}
|
|
eStore, err := file.NewDefaultExamFileStore()
|
|
if err != nil {
|
|
log.Fatalf("An error occurred: %v", err)
|
|
}
|
|
|
|
for _, p := range pStore.ReadAll() {
|
|
e, err := eStore.Create(&models.Exam{
|
|
Name: cCtx.Args().First(),
|
|
Participant: p,
|
|
Quizzes: qStore.ReadAll(),
|
|
})
|
|
if err != nil {
|
|
log.Fatalf("An error occurred: %v", err)
|
|
}
|
|
log.Printf("Created exam %v... in %v", e.ID[:8], eStore.GetPath(e))
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
if err := app.Run(os.Args); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|