filter.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. Copyright © 2024 NAME HERE <EMAIL ADDRESS>
  3. */
  4. package cmd
  5. import (
  6. "fmt"
  7. "os"
  8. "git.andreafazzi.eu/andrea/probo/cmd/filter"
  9. tea "github.com/charmbracelet/bubbletea"
  10. "github.com/spf13/cobra"
  11. )
  12. // filterCmd represents the filter command
  13. var filterCmd = &cobra.Command{
  14. Use: "filter",
  15. Short: "Create a new filter",
  16. Long: "Create a new filter to select quizzes and participants",
  17. Run: createFilter,
  18. }
  19. func init() {
  20. createCmd.AddCommand(filterCmd)
  21. // Here you will define your flags and configuration settings.
  22. // Cobra supports Persistent Flags which will work for this command
  23. // and all subcommands, e.g.:
  24. // filterCmd.PersistentFlags().String("foo", "", "A help for foo")
  25. // Cobra supports local flags which will only run when this command
  26. // is called directly, e.g.:
  27. // filterCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
  28. }
  29. func createFilter(cmd *cobra.Command, args []string) {
  30. if len(os.Getenv("DEBUG")) > 0 {
  31. f, err := tea.LogToFile("debug.log", "debug")
  32. if err != nil {
  33. fmt.Println("fatal:", err)
  34. os.Exit(1)
  35. }
  36. defer f.Close()
  37. }
  38. if _, err := tea.NewProgram(filter.New()).Run(); err != nil {
  39. fmt.Println("Error running program:", err)
  40. os.Exit(1)
  41. }
  42. }