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",
|
2023-10-22 01:33:18 +05:30
|
|
|
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
|
|
|
}
|