2023-12-05 22:11:08 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
|
2023-12-11 09:32:50 +01:00
|
|
|
"git.andreafazzi.eu/andrea/probo/session"
|
2023-12-05 22:11:08 +01:00
|
|
|
"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)
|
|
|
|
}
|
2023-12-11 09:32:50 +01:00
|
|
|
|
|
|
|
session, err := session.NewSession(
|
|
|
|
"http://localhost:8080/create",
|
|
|
|
cCtx.Args().First(),
|
|
|
|
pStore.Storer,
|
|
|
|
qStore.Storer,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("An error occurred: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
id, err := session.Push()
|
2023-12-05 22:11:08 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("An error occurred: %v", err)
|
|
|
|
}
|
|
|
|
|
2023-12-11 09:32:50 +01:00
|
|
|
log.Printf("Session upload completed with success. URL: https://localhost:8080/%v", id)
|
|
|
|
|
2023-12-05 22:11:08 +01:00
|
|
|
for _, p := range pStore.ReadAll() {
|
2023-12-11 09:32:50 +01:00
|
|
|
log.Printf("http://localhost:8080/%v/%v", id, p.Token)
|
2023-12-05 22:11:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := app.Run(os.Args); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|