interactive shell post processing added

This commit is contained in:
sqshq 2019-04-07 21:00:25 -04:00
parent 6c329f76b6
commit 19f2d028a6
3 changed files with 9 additions and 10 deletions

View File

@ -121,4 +121,5 @@ func (s *SparkLine) Draw(buffer *ui.Buffer) {
} }
s.Block.Draw(buffer) s.Block.Draw(buffer)
component.RenderAlert(s.alert, s.Rectangle, buffer)
} }

View File

@ -13,7 +13,7 @@ func TestParseFloat(t *testing.T) {
wantErr bool wantErr bool
}{ }{
{"should parse a regular number", args{"123"}, 123, false}, {"should parse a regular number", args{"123"}, 123, false},
{"should parse a regular number with spaces", args{" 123 "}, 123, false}, {"should parse a regular number with spaces, tabs and line breaks", args{" \t 123 \t \n "}, 123, false},
{"should parse a last line in the given string", args{"123\n456"}, 456, false}, {"should parse a last line in the given string", args{"123\n456"}, 456, false},
} }
for _, tt := range tests { for _, tt := range tests {

View File

@ -60,13 +60,13 @@ func (i *Item) nextValue(variables []string) (string, error) {
if i.InitScript != nil { if i.InitScript != nil {
return i.executeInteractiveShellCmd(variables) return i.executeInteractiveShellCmd(variables)
} else { } else {
return i.executeCmd(variables) return i.executeCmd(variables, i.SampleScript)
} }
} }
func (i *Item) executeCmd(variables []string) (string, error) { func (i *Item) executeCmd(variables []string, script string) (string, error) {
cmd := exec.Command("sh", "-c", i.SampleScript) cmd := exec.Command("sh", "-c", script)
enrichEnvVariables(cmd, variables) enrichEnvVariables(cmd, variables)
output, err := cmd.Output() output, err := cmd.Output()
@ -75,7 +75,7 @@ func (i *Item) executeCmd(variables []string) (string, error) {
return "", err return "", err
} }
return strings.TrimSpace(string(output)), nil return string(output), nil
} }
func (i *Item) initInteractiveShell(variables []string) error { func (i *Item) initInteractiveShell(variables []string) error {
@ -167,13 +167,11 @@ func (i *Item) executeInteractiveShellCmd(variables []string) (string, error) {
func (i *Item) transformInteractiveShellCmd(sample string) (string, error) { func (i *Item) transformInteractiveShellCmd(sample string) (string, error) {
result := sample if i.TransformScript != nil && len(sample) > 0 {
return i.executeCmd([]string{"sample=" + sample}, *i.TransformScript)
if i.TransformScript != nil {
result = result // TODO
} }
return result, nil return sample, nil
} }
func enrichEnvVariables(cmd *exec.Cmd, variables []string) { func enrichEnvVariables(cmd *exec.Cmd, variables []string) {