MCPcopy
hub / github.com/nextdns/nextdns / ctlCmd

Function ctlCmd

ctl.go:14–43  ·  view source on GitHub ↗
(args []string)

Source from the content-addressed store, hash-verified

12)
13
14func ctlCmd(args []string) error {
15 cmd := args[0]
16 fs := flag.NewFlagSet(cmd, flag.ExitOnError)
17 control := fs.String("control", config.DefaultControl, "Address to the control socket")
18 _ = fs.Parse(args[1:])
19 cl, err := ctl.Dial(*control)
20 if err != nil {
21 if os.Geteuid() != 0 {
22 return syscall.Exec("/usr/bin/sudo", append([]string{"sudo", os.Args[0]}, args...), os.Environ())
23 }
24 return err
25 }
26 defer cl.Close()
27 data, err := cl.Send(ctl.Event{
28 Name: cmd,
29 })
30 if err != nil {
31 return err
32 }
33 if s, ok := data.(string); ok {
34 fmt.Println(s)
35 return nil
36 }
37 b, err := json.MarshalIndent(data, "", " ")
38 if err != nil {
39 return err
40 }
41 fmt.Println(string(b))
42 return nil
43}

Callers

nothing calls this directly

Calls 5

DialFunction · 0.92
SendMethod · 0.80
StringMethod · 0.65
ParseMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…