Skip to content
This repository has been archived by the owner on Jul 25, 2018. It is now read-only.

Commit

Permalink
Merge pull request #29 from rcoh/master
Browse files Browse the repository at this point in the history
Add support for directing output of sumoshell to a file
  • Loading branch information
rcoh committed Feb 26, 2017
2 parents 8c7f3d9 + ffa2fc4 commit 66ad8be
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
8 changes: 4 additions & 4 deletions parse/Parse.go
@@ -1,10 +1,10 @@
package parse

import (
"regexp"
"github.com/SumoLogic/sumoshell/util"
"log"
"regexp"
"strings"
"github.com/SumoLogic/sumoshell/util"
)

type Parser struct {
Expand Down Expand Up @@ -35,7 +35,7 @@ func Build(args []string) (util.SumoOperator, error) {
if as != "as" {
return nil, util.ParseError("Expected `as` got " + as + "\n" + genericError)
}
extractions := make([]string, len(args) - 3)
extractions := make([]string, len(args)-3)
for i, arg := range args[3:] {
extractions[i] = strings.Trim(arg, ",")
}
Expand Down Expand Up @@ -67,7 +67,7 @@ func regexFromPat(pat string) *regexp.Regexp {
func (p Parser) Process(inp map[string]interface{}) {
if util.IsPlus(inp) {
matches := p.regex.FindStringSubmatch(util.ExtractRaw(inp))
if len(matches) == 1 + len(p.extractions) {
if len(matches) == 1+len(p.extractions) {
for i, match := range matches[1:] {
inp[p.extractions[i]] = match
}
Expand Down
14 changes: 11 additions & 3 deletions render/Render.go
Expand Up @@ -30,15 +30,23 @@ func main() {
cmd.Stdin = os.Stdout
out, _ := cmd.Output()
wh := strings.Split(string(out), " ")
hstr := strings.Trim(wh[0], "\n")
wstr := strings.Trim(wh[1], "\n")
var hstr, wstr string
renderAll := false
if len(wh) == 1 {
hstr = "0"
wstr = "0"
renderAll = true
} else {
wstr = strings.Trim(wh[1], "\n")
hstr = strings.Trim(wh[0], "\n")
}
height, _ := strconv.ParseInt(hstr, 10, 64)
width, _ := strconv.ParseInt(wstr, 10, 64)

rows := int64(0)
inRelation := false

if len(os.Args) == 2 && os.Args[1] == "noraw" {
if (len(os.Args) == 2 && os.Args[1] == "noraw") || renderAll {
util.ConnectToStdIn(Renderer{false, &m, &cols, height, width, &rows, &inRelation, 20})
} else if len(os.Args) == 2 && os.Args[1] == "all" {
c := make(chan os.Signal, 2)
Expand Down
10 changes: 5 additions & 5 deletions util/Raw.go
@@ -1,18 +1,18 @@
package util

import (
"io"
"os"
"fmt"
"bufio"
"bytes"
"encoding/json"
"fmt"
"github.com/reiver/go-whitespace"
"io"
"log"
"bytes"
"os"
"sort"
"strconv"
"strings"
"sync"
"github.com/reiver/go-whitespace"
)

type RawInputHandler struct {
Expand Down

0 comments on commit 66ad8be

Please sign in to comment.