session.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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/session"
  9. "git.andreafazzi.eu/andrea/probo/cmd/util"
  10. tea "github.com/charmbracelet/bubbletea"
  11. "github.com/charmbracelet/lipgloss"
  12. "github.com/muesli/termenv"
  13. "github.com/spf13/cobra"
  14. )
  15. // sessionCmd represents the session command
  16. var sessionCmd = &cobra.Command{
  17. Use: "session",
  18. Short: "Create a new session or update a given one",
  19. Long: "Create a new session or update a given one.",
  20. Run: updateSession,
  21. }
  22. func init() {
  23. updateCmd.AddCommand(sessionCmd)
  24. sessionCmd.Flags().StringP("script", "s", "", "Execute a tengo script to initiate a session")
  25. }
  26. func updateSession(cmd *cobra.Command, args []string) {
  27. f := util.LogToFile()
  28. if f != nil {
  29. defer f.Close()
  30. }
  31. path, err := cmd.Flags().GetString("script")
  32. if err != nil {
  33. panic(err)
  34. }
  35. lipgloss.SetColorProfile(termenv.TrueColor)
  36. _, err = tea.NewProgram(
  37. session.New(path, util.ReadStdin()),
  38. tea.WithOutput(os.Stderr),
  39. ).Run()
  40. if err != nil {
  41. fmt.Println("Error running program:", err)
  42. os.Exit(1)
  43. }
  44. }