more knecht
This commit is contained in:
45
knecht/cmd/restart.go
Normal file
45
knecht/cmd/restart.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var restartCmd = &cobra.Command{
|
||||
Use: "restart <stack>",
|
||||
Short: "Stop and start a stack",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
_, client, _, err := setup()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
name := args[0]
|
||||
remote, err := client.GetStackByName(name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if remote == nil {
|
||||
return fmt.Errorf("stack %q not found", name)
|
||||
}
|
||||
|
||||
fmt.Printf("Stopping %q...\n", name)
|
||||
if err := client.StopStack(remote.ID); err != nil {
|
||||
return fmt.Errorf("stop failed: %w", err)
|
||||
}
|
||||
|
||||
fmt.Printf("Starting %q...\n", name)
|
||||
if err := client.StartStack(remote.ID); err != nil {
|
||||
return fmt.Errorf("start failed: %w", err)
|
||||
}
|
||||
|
||||
fmt.Printf("Restarted %q\n", name)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(restartCmd)
|
||||
}
|
||||
Reference in New Issue
Block a user