package main import ( "log" "os" "git.andreafazzi.eu/andrea/probo/session" "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) } 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() if err != nil { log.Fatalf("An error occurred: %v", err) } log.Printf("Session upload completed with success. URL: https://localhost:8080/%v", id) for _, p := range pStore.ReadAll() { log.Printf("http://localhost:8080/%v/%v", id, p.Token) } return nil }, }, }, }, }, } if err := app.Run(os.Args); err != nil { log.Fatal(err) } }