github.com/scaleway/scaleway-cli@v1.11.1/pkg/cli/cmd_restart.go (about)

     1  // Copyright (C) 2015 Scaleway. All rights reserved.
     2  // Use of this source code is governed by a MIT-style
     3  // license that can be found in the LICENSE.md file.
     4  
     5  package cli
     6  
     7  import "github.com/scaleway/scaleway-cli/pkg/commands"
     8  
     9  var cmdRestart = &Command{
    10  	Exec:        runRestart,
    11  	UsageLine:   "restart [OPTIONS] SERVER [SERVER...]",
    12  	Description: "Restart a running server",
    13  	Help:        "Restart a running server.",
    14  }
    15  
    16  func init() {
    17  	cmdRestart.Flag.BoolVar(&restartW, []string{"w", "-wait"}, false, "Synchronous restart. Wait for SSH to be ready")
    18  	cmdRestart.Flag.Float64Var(&restartTimeout, []string{"T", "-timeout"}, 0, "Set timeout values to seconds")
    19  	cmdRestart.Flag.BoolVar(&restartHelp, []string{"h", "-help"}, false, "Print usage")
    20  }
    21  
    22  // Flags
    23  var restartW bool          // -w flag
    24  var restartTimeout float64 // -T flag
    25  var restartHelp bool       // -h, --help flag
    26  
    27  func runRestart(cmd *Command, rawArgs []string) error {
    28  	if restartHelp {
    29  		return cmd.PrintUsage()
    30  	}
    31  	if len(rawArgs) < 1 {
    32  		return cmd.PrintShortUsage()
    33  	}
    34  
    35  	args := commands.RestartArgs{
    36  		Timeout: restartTimeout,
    37  		Wait:    restartW,
    38  		Servers: rawArgs,
    39  	}
    40  	ctx := cmd.GetContext(rawArgs)
    41  	return commands.RunRestart(ctx, args)
    42  }