-
Notifications
You must be signed in to change notification settings - Fork 4
/
agent_id.go
44 lines (36 loc) · 908 Bytes
/
agent_id.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
40
41
42
43
44
/*
Copyright © 2023 Glif LTD
*/
package cmd
import (
"log"
"time"
"github.com/briandowns/spinner"
"github.com/glifio/glif/v2/util"
"github.com/spf13/cobra"
)
var idCmd = &cobra.Command{
Use: "id",
Short: "Fetches the Agent ID (uses the address in agent.toml by default)",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
agentAddr, err := getAgentAddressWithFlags(cmd)
if err != nil {
logFatal(err)
}
log.Printf("Fetching agent ID for %s", util.TruncateAddr(agentAddr.String()))
s := spinner.New(spinner.CharSets[9], 100*time.Millisecond)
s.Start()
defer s.Stop()
id, err := PoolsSDK.Query().AgentID(cmd.Context(), agentAddr)
if err != nil {
logFatal(err)
}
s.Stop()
log.Printf("Agent %s ID: %s\n", util.TruncateAddr(agentAddr.String()), id)
},
}
func init() {
agentCmd.AddCommand(idCmd)
idCmd.Flags().String("agent-addr", "", "Agent address")
}