I'm trying to work on a PoC with adding exec.Command's to cli plugin, however I'm struggling with how to get it to accept user input with the command. I admit I am fairly new to Go, coming from PHP and Bash scripting so...I am sure I'm missing something very basic here and it's a little embarrassing.
I've tried setting variables, adding the variables to the output, adding in bufio, and trying to prompt with no luck.
out, err := exec.Command("mtr", "-c", "10", "-r", destIP).Output()
was the most recent fail...
type Mtr struct{}
func (m *Mtr) Run(command []string, context plugin.PluginContext, ui terminal.UI) {
// var destIP string - commented out simply so I could rebuild the file and get the plugin working again.
ui.Say("")
ui.Say(terminal.AdvisoryColor("Wait while we run a traceroute..."))
ui.Say("")
out, err := exec.Command("mtr", "-c", "10", "-r").Output()
if err != nil {
ui.Say(fmt.Sprintf("%s", err))
}
output := string(out[:])
table := ui.Table([]string{"", ""})
table.Add("", output)
table.Print()
I literally just want it to be able to accept something like this
mainprogram plugin mtr Currently I have it set to just force Google, but that is not really what I want out of this...
out, err := exec.Command("mtr", "-c", "10", "-r", "8.8.8.8").Output()
Current output with the botched attempts yields -
Shawns-MBP-2:directoryhere $ mainprog plugin mtr 4.4.4.4
Wait while we run a traceroute...
Shawns-MBP-2:directoryhere$
With the forced Google DNS, it obviously shows -
Shawns-MBP-2:directoryhere $ mainprog plugin mtr
Wait while we run a traceroute...
Start: 2019-05-03T15:41:18-0500
HOST: stuff Loss% Snt Last Avg Best Wrst StDev
1.|-- stuff 0.0% 10 1.6 1.7 1.2 3.1 0.5
2.|-- stuff 0.0% 10 2.6 6.5 2.0 12.4 4.5
3.|-- stuff 0.0% 10 3.3 3.3 2.7 4.1 0.4
4.|-- stuff 0.0% 10 13.6 12.2 9.1 15.6 2.5
5.|-- stuff 0.0% 10 9.2 12.9 9.2 17.7 2.5
6.|-- stuff 0.0% 10 8.7 9.1 8.0 10.5 0.6
7.|-- stuff 0.0% 10 9.1 9.2 8.2 10.1 0.5
8.|-- stuff 0.0% 10 10.3 10.1 9.7 10.4 0.3
9.|-- stuff 0.0% 10 8.8 9.2 8.5 10.7 0.6
10.|-- google-public-dns-a.googl 0.0% 10 8.7 8.9 8.2 10.0 0.4