-
Notifications
You must be signed in to change notification settings - Fork 10
/
disconnect.go
39 lines (31 loc) · 938 Bytes
/
disconnect.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package commands
import (
"fmt"
"strings"
"github.com/AbGuthrie/goquery/v2/config"
"github.com/AbGuthrie/goquery/v2/hosts"
"github.com/AbGuthrie/goquery/v2/models"
prompt "github.com/c-bata/go-prompt"
)
func disconnect(api models.GoQueryAPI, config *config.Config, cmdline string) error {
args := strings.Split(cmdline, " ") // Separate command and arguments
if len(args) == 1 {
return fmt.Errorf("Host UUID required")
}
uuid := args[1]
if err := hosts.Disconnect(uuid); err != nil {
return fmt.Errorf("Error disconnecting from host: %s", err)
}
fmt.Printf("Disconnected from '%s'\n", uuid)
return nil
}
func disconnectHelp() string {
return "Disconnect from a host with UUID"
}
func disconnectSuggest(cmdline string) []prompt.Suggest {
prompts := []prompt.Suggest{}
for _, host := range hosts.GetCurrentHosts() {
prompts = append(prompts, prompt.Suggest{host.UUID, host.ComputerName})
}
return prompts
}