123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- /*
- Copyright © 2024 NAME HERE <EMAIL ADDRESS>
- */
- package cmd
- import (
- "fmt"
- "os"
- "git.andreafazzi.eu/andrea/probo/cmd/session"
- "git.andreafazzi.eu/andrea/probo/cmd/util"
- tea "github.com/charmbracelet/bubbletea"
- "github.com/charmbracelet/lipgloss"
- "github.com/muesli/termenv"
- "github.com/spf13/cobra"
- )
- // sessionCmd represents the session command
- var sessionCmd = &cobra.Command{
- Use: "session",
- Short: "Create a new session or update a given one",
- Long: "Create a new session or update a given one.",
- Run: updateSession,
- }
- func init() {
- updateCmd.AddCommand(sessionCmd)
- sessionCmd.Flags().StringP("script", "s", "", "Execute a tengo script to initiate a session")
- }
- func updateSession(cmd *cobra.Command, args []string) {
- f := util.LogToFile()
- if f != nil {
- defer f.Close()
- }
- path, err := cmd.Flags().GetString("script")
- if err != nil {
- panic(err)
- }
- lipgloss.SetColorProfile(termenv.TrueColor)
- _, err = tea.NewProgram(
- session.New(path, util.ReadStdin()),
- tea.WithOutput(os.Stderr),
- ).Run()
- if err != nil {
- fmt.Println("Error running program:", err)
- os.Exit(1)
- }
- }
|