gt down --all: also kill tmux server
This commit is contained in:
@@ -36,11 +36,13 @@ This is useful for:
|
|||||||
var (
|
var (
|
||||||
downQuiet bool
|
downQuiet bool
|
||||||
downForce bool
|
downForce bool
|
||||||
|
downAll bool
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
downCmd.Flags().BoolVarP(&downQuiet, "quiet", "q", false, "Only show errors")
|
downCmd.Flags().BoolVarP(&downQuiet, "quiet", "q", false, "Only show errors")
|
||||||
downCmd.Flags().BoolVarP(&downForce, "force", "f", false, "Force kill without graceful shutdown")
|
downCmd.Flags().BoolVarP(&downForce, "force", "f", false, "Force kill without graceful shutdown")
|
||||||
|
downCmd.Flags().BoolVarP(&downAll, "all", "a", false, "Also kill the tmux server")
|
||||||
rootCmd.AddCommand(downCmd)
|
rootCmd.AddCommand(downCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,6 +98,16 @@ func runDown(cmd *cobra.Command, args []string) error {
|
|||||||
printDownStatus("Daemon", true, "not running")
|
printDownStatus("Daemon", true, "not running")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 5. Kill tmux server if --all
|
||||||
|
if downAll {
|
||||||
|
if err := t.KillServer(); err != nil {
|
||||||
|
printDownStatus("Tmux server", false, err.Error())
|
||||||
|
allOK = false
|
||||||
|
} else {
|
||||||
|
printDownStatus("Tmux server", true, "killed")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
if allOK {
|
if allOK {
|
||||||
fmt.Printf("%s All services stopped\n", style.Bold.Render("✓"))
|
fmt.Printf("%s All services stopped\n", style.Bold.Render("✓"))
|
||||||
|
|||||||
@@ -80,6 +80,15 @@ func (t *Tmux) KillSession(name string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// KillServer terminates the entire tmux server and all sessions.
|
||||||
|
func (t *Tmux) KillServer() error {
|
||||||
|
_, err := t.run("kill-server")
|
||||||
|
if errors.Is(err, ErrNoServer) {
|
||||||
|
return nil // Already dead
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// HasSession checks if a session exists.
|
// HasSession checks if a session exists.
|
||||||
func (t *Tmux) HasSession(name string) (bool, error) {
|
func (t *Tmux) HasSession(name string) (bool, error) {
|
||||||
_, err := t.run("has-session", "-t", name)
|
_, err := t.run("has-session", "-t", name)
|
||||||
|
|||||||
Reference in New Issue
Block a user