pee/project-manager/main.go

51 lines
1.0 KiB
Go
Raw Normal View History

2023-10-22 01:12:58 +05:30
package projectmanager
import (
2023-10-22 01:24:16 +05:30
projectconfig "github.com/xrehpicx/pee/config"
"github.com/xrehpicx/pee/controller"
2023-10-22 01:12:58 +05:30
"github.com/charmbracelet/log"
"github.com/spf13/cobra"
)
var RootCmd = &cobra.Command{
Use: "pee",
Args: cobra.ExactArgs(1),
2023-10-22 01:12:58 +05:30
Run: func(cmd *cobra.Command, args []string) {
ExecuteProjectEnv(args[0])
},
}
2023-10-23 01:22:07 +05:30
var KillTmuxSessionCmd = &cobra.Command{
Use: "kill",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
sessionName := args[0]
err := controller.KillTmuxSession(sessionName)
if err != nil {
log.Error(err)
return
}
log.Debug("Killed tmux session", "name", sessionName)
},
}
func init() {
RootCmd.AddCommand(KillTmuxSessionCmd)
}
2023-10-22 01:12:58 +05:30
func ExecuteProjectEnv(projectName string) {
config, err := projectconfig.GetProjectConfig(projectName)
if err != nil {
log.Error(err)
return
}
err = controller.CreateTmuxSession(config)
if err != nil {
log.Error(err)
return
}
projectconfig.UpdateLastOpened(projectName)
2023-10-22 14:01:39 +05:30
log.Debug("Created tmux session", "name", config.SessionName)
2023-10-22 01:12:58 +05:30
}