1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- /*
- 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)
- model, 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)
- }
- result := model.(*session.SessionModel)
- if result.Result != "" {
- fmt.Fprintf(os.Stdout, result.Result)
- }
- fmt.Println("session called", path, model)
- }
|