github.com/scaleway/scaleway-cli@v1.11.1/pkg/cli/cmd_attach.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 cmdAttach = &Command{
    10  	Exec:        runAttach,
    11  	UsageLine:   "attach [OPTIONS] SERVER",
    12  	Description: "Attach to a server serial console",
    13  	Help:        "Attach to a running server serial console.",
    14  	Examples: `
    15      $ scw attach my-running-server
    16      $ scw attach $(scw start my-stopped-server)
    17      $ scw attach $(scw start $(scw create ubuntu-vivid))
    18  `,
    19  }
    20  
    21  func init() {
    22  	cmdAttach.Flag.BoolVar(&attachHelp, []string{"h", "-help"}, false, "Print usage")
    23  	cmdAttach.Flag.BoolVar(&attachNoStdin, []string{"-no-stdin"}, false, "Do not attach stdin")
    24  }
    25  
    26  // Flags
    27  var attachHelp bool    // -h, --help flag
    28  var attachNoStdin bool // --no-stdin flag
    29  
    30  func runAttach(cmd *Command, rawArgs []string) error {
    31  	if attachHelp {
    32  		return cmd.PrintUsage()
    33  	}
    34  	if len(rawArgs) != 1 {
    35  		return cmd.PrintShortUsage()
    36  	}
    37  
    38  	args := commands.AttachArgs{
    39  		NoStdin: attachNoStdin,
    40  		Server:  rawArgs[0],
    41  	}
    42  	ctx := cmd.GetContext(rawArgs)
    43  	return commands.RunAttach(ctx, args)
    44  }