MCPcopy Create free account
hub / github.com/Driver-C/tryssh / SetAlias

Method SetAlias

pkg/control/alias.go:19–48  ·  view source on GitHub ↗

SetAlias assigns the configured alias to all server entries matching the target IP.

()

Source from the content-addressed store, hash-verified

17
18// SetAlias assigns the configured alias to all server entries matching the target IP.
19func (ac *AliasController) SetAlias() bool {
20 aliasServerList := config.FindAlias(ac.alias, ac.configuration)
21 if len(aliasServerList) != 0 {
22 ac.ListAlias()
23 utils.Errorf(
24 "The alias \"%s\" has already been set, try another alias or delete it and set again.\n",
25 ac.alias)
26 return false
27 }
28 var beSetCount int
29 for index, server := range ac.configuration.ServerLists {
30 if server.IP == ac.targetIP {
31 ac.configuration.ServerLists[index].Alias = ac.alias
32 utils.Infof(
33 "The server %s@%s:%s's alias \"%s\" will be set.\n",
34 server.User, server.IP, server.Port, ac.alias)
35 beSetCount++
36 }
37 }
38 if beSetCount == 0 {
39 utils.Warnf("No matching server for IP: %s\n", ac.targetIP)
40 return false
41 }
42 if err := config.UpdateConfig(ac.configuration); err == nil {
43 utils.Infof("%d cache information has been changed.\n", beSetCount)
44 return true
45 }
46 utils.Errorln("Main config update failed.")
47 return false
48}
49
50// ListAlias prints all configured aliases, or only those matching the configured alias filter.
51func (ac *AliasController) ListAlias() {

Calls 7

ListAliasMethod · 0.95
FindAliasFunction · 0.92
ErrorfFunction · 0.92
InfofFunction · 0.92
WarnfFunction · 0.92
UpdateConfigFunction · 0.92
ErrorlnFunction · 0.92