⛳ alerts for any ctfd instance via ntfy
1package main
2
3import (
4 "context"
5 "log"
6 "os"
7
8 "github.com/charmbracelet/fang"
9 "github.com/spf13/cobra"
10 "github.com/taciturnaxolotl/ctfd-alerts/clients"
11 "github.com/taciturnaxolotl/ctfd-alerts/cmd/server"
12 "github.com/taciturnaxolotl/ctfd-alerts/cmd/status"
13)
14
15var (
16 debugLog *log.Logger
17)
18
19// rootCmd represents the base command
20var cmd = &cobra.Command{
21 Use: "ctfd-alerts",
22 Short: "A tool for monitoring CTFd competitions",
23 Long: `ctfd-alerts is a command-line tool that helps you monitor CTFd-based
24competitions by providing real-time updates, notifications, and status information.`,
25 PersistentPreRun: func(cmd *cobra.Command, args []string) {
26 configFile, _ := cmd.Flags().GetString("config")
27 var err error
28 config, err = loadConfig(configFile)
29 if err != nil {
30 log.Fatalf("Error loading config: %v", err)
31 }
32
33 setupLogging(config.Debug)
34
35 // Create a new CTFd client and add it to context
36 ctfdClient := clients.NewCTFdClient(config.CTFdConfig.ApiBase, config.CTFdConfig.ApiKey)
37 ctx := context.WithValue(cmd.Context(), "ctfd_client", ctfdClient)
38 ctx = context.WithValue(ctx, "config", config)
39 cmd.SetContext(ctx)
40 },
41}
42
43func init() {
44 // Add persistent flags that work across all commands
45 cmd.PersistentFlags().StringP("config", "c", "config.toml", "config file path")
46
47 // Add commands
48 cmd.AddCommand(status.StatusCmd)
49 cmd.AddCommand(server.ServerCmd)
50}
51
52func main() {
53 if err := fang.Execute(
54 context.Background(),
55 cmd,
56 ); err != nil {
57 os.Exit(1)
58 }
59}