MCPcopy Index your code
hub / github.com/koding/kite / Run

Method Run

kitectl/command/tell.go:47–104  ·  view source on GitHub ↗
(args []string)

Source from the content-addressed store, hash-verified

45}
46
47func (c *Tell) Run(args []string) int {
48
49 var to, method string
50 var timeout time.Duration
51
52 flags := flag.NewFlagSet("tell", flag.ExitOnError)
53 flags.StringVar(&to, "to", "", "URL of remote kite")
54 flags.StringVar(&method, "method", "", "method to be called")
55 flags.DurationVar(&timeout, "timeout", 4*time.Second, "timeout of tell method")
56 flags.Parse(args)
57
58 if to == "" || method == "" {
59 c.Ui.Output(c.Help())
60 return 1
61 }
62
63 key, err := kitekey.Read()
64 if err != nil {
65 c.Ui.Error(err.Error())
66 return 1
67 }
68
69 remote := c.KiteClient.NewClient(to)
70 remote.Auth = &kite.Auth{
71 Type: "kiteKey",
72 Key: key,
73 }
74
75 if err = remote.Dial(); err != nil {
76 c.Ui.Error(err.Error())
77 return 1
78 }
79
80 // Convert args to []interface{} in order to pass it to Tell() method.
81 methodArgs := flags.Args()
82 params := make([]interface{}, len(methodArgs))
83 for i, arg := range methodArgs {
84 if number, err := strconv.Atoi(arg); err != nil {
85 params[i] = arg
86 } else {
87 params[i] = number
88 }
89 }
90
91 result, err := remote.TellWithTimeout(method, timeout, params...)
92 if err != nil {
93 c.Ui.Error(err.Error())
94 return 1
95 }
96
97 if result == nil {
98 c.Ui.Info("nil")
99 } else {
100 c.Ui.Info(string(result.Raw))
101 }
102
103 return 0
104}

Callers

nothing calls this directly

Calls 7

HelpMethod · 0.95
DialMethod · 0.95
TellWithTimeoutMethod · 0.95
NewClientMethod · 0.80
InfoMethod · 0.80
ErrorMethod · 0.65
ReadMethod · 0.45

Tested by

no test coverage detected