probo/cmd/session.go

55 lines
1.1 KiB
Go
Raw Normal View History

2024-03-25 15:53:20 +01:00
/*
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
*/
package cmd
import (
"fmt"
2024-04-22 14:24:29 +02:00
"os"
2024-03-25 15:53:20 +01:00
2024-04-22 14:24:29 +02:00
"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"
2024-03-25 15:53:20 +01:00
"github.com/spf13/cobra"
)
// sessionCmd represents the session command
var sessionCmd = &cobra.Command{
Use: "session",
2024-04-22 14:24:29 +02:00
Short: "Create a new session or update a given one",
Long: "Create a new session or update a given one.",
Run: updateSession,
2024-03-25 15:53:20 +01:00
}
func init() {
2024-04-22 14:24:29 +02:00
updateCmd.AddCommand(sessionCmd)
2024-03-25 15:53:20 +01:00
2024-04-22 14:24:29 +02:00
sessionCmd.Flags().StringP("script", "s", "", "Execute a tengo script to initiate a session")
}
2024-03-25 15:53:20 +01:00
2024-04-22 14:24:29 +02:00
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)
2024-04-24 09:29:01 +02:00
_, err = tea.NewProgram(
2024-04-22 14:24:29 +02:00
session.New(path, util.ReadStdin()),
tea.WithOutput(os.Stderr),
).Run()
if err != nil {
fmt.Println("Error running program:", err)
os.Exit(1)
}
2024-03-25 15:53:20 +01:00
}