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