2019-01-31 23:40:05 +00:00
|
|
|
package data
|
|
|
|
|
|
|
|
import (
|
2019-03-10 04:41:23 +00:00
|
|
|
"github.com/sqshq/sampler/config"
|
2019-02-16 16:59:35 +00:00
|
|
|
ui "github.com/sqshq/termui"
|
2019-01-31 23:40:05 +00:00
|
|
|
"os/exec"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Item struct {
|
2019-03-08 04:04:46 +00:00
|
|
|
Label string
|
|
|
|
Script string
|
2019-03-10 04:41:23 +00:00
|
|
|
Color *ui.Color
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewItems(cfgs []config.Item) []Item {
|
|
|
|
|
|
|
|
items := make([]Item, 0)
|
|
|
|
|
|
|
|
for _, i := range cfgs {
|
|
|
|
item := Item{Label: *i.Label, Script: i.Script, Color: i.Color}
|
|
|
|
items = append(items, item)
|
|
|
|
}
|
|
|
|
|
|
|
|
return items
|
2019-01-31 23:40:05 +00:00
|
|
|
}
|
|
|
|
|
2019-02-17 01:54:48 +00:00
|
|
|
func (i *Item) nextValue() (value string, err error) {
|
2019-01-31 23:40:05 +00:00
|
|
|
|
2019-02-17 01:54:48 +00:00
|
|
|
output, err := exec.Command("sh", "-c", i.Script).Output()
|
2019-01-31 23:40:05 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
return strings.TrimSpace(string(output)), nil
|
|
|
|
}
|