cmd/dlv: Add ability to connect to headless server
Fixes #201. Use to connect to a running headless server
This commit is contained in:
parent
5d489bef99
commit
96dd44bd6e
@ -222,9 +222,41 @@ starts and attaches to it, and enable you to immediately begin debugging your pr
|
||||
}
|
||||
rootCommand.AddCommand(attachCommand)
|
||||
|
||||
// 'connect' subcommand.
|
||||
connectCommand := &cobra.Command{
|
||||
Use: "connect [addr]",
|
||||
Short: "Connect to a headless debug server.",
|
||||
Long: "Connect to a headless debug server.",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) == 0 {
|
||||
fmt.Fprintf(os.Stderr, "An address was not provided. You must provide an address as the first argument.\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
addr := args[0]
|
||||
if addr == "" {
|
||||
fmt.Fprintf(os.Stderr, "An empty address was provided. You must provide an address as the first argument.\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
os.Exit(connect(addr))
|
||||
},
|
||||
}
|
||||
rootCommand.AddCommand(connectCommand)
|
||||
|
||||
rootCommand.Execute()
|
||||
}
|
||||
|
||||
func connect(addr string) int {
|
||||
// Create and start a terminal - attach to running instance
|
||||
var client service.Client
|
||||
client = rpc.NewClient(addr)
|
||||
term := terminal.New(client)
|
||||
err, status := term.Run()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
return status
|
||||
}
|
||||
|
||||
func execute(attachPid int, processArgs []string) int {
|
||||
// Make a TCP listener
|
||||
listener, err := net.Listen("tcp", Addr)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user