-
Notifications
You must be signed in to change notification settings - Fork 949
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: letty <[email protected]>
- Loading branch information
Showing
6 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
|
||
"fmt" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// restartDescription is used to describe restart command in detail and auto generate command doc. | ||
var restartDescription = "restart one or more containers" | ||
|
||
// restartCommand uses to implement 'restart' command, it restarts a container. | ||
type RestartCommand struct { | ||
baseCommand | ||
time int | ||
} | ||
|
||
// Init initialize restart command. | ||
func (rc *RestartCommand) Init(c *Cli) { | ||
rc.cli = c | ||
|
||
rc.cmd = &cobra.Command{ | ||
Use: "restart [OPTION] CONTAINER [CONTAINERS]", | ||
Short: "restart one or more containers", | ||
Long: restartDescription, | ||
Args: cobra.MinimumNArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return rc.runrestart(args) | ||
}, | ||
Example: restartExample(), | ||
} | ||
rc.addFlags() | ||
} | ||
|
||
// addFlags adds flags for specific command. | ||
func (rc *RestartCommand) addFlags() { | ||
flagSet := rc.cmd.Flags() | ||
flagSet.IntVarP(&rc.time, "time", "t", 10, | ||
"Seconds to wait for stop before killing the container (default 10)") | ||
} | ||
|
||
// runrestart is the entry of restart command. | ||
func (rc *RestartCommand) runrestart(args []string) error { | ||
ctx := context.Background() | ||
apiClient := rc.cli.Client() | ||
|
||
for _, name := range args { | ||
if err := apiClient.ContainerRestart(ctx, name, rc.time); err != nil { | ||
return fmt.Errorf("failed to restart container: %v", err) | ||
} | ||
fmt.Printf("%s\n", name) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// restartExample shows examples in restart command, and is used in auto-generated cli docs. | ||
func restartExample() string { | ||
return `//TODO` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters