From 9242a1aee0ce532bcce33a76a13e9aff7b20f584 Mon Sep 17 00:00:00 2001 From: Claudson Oliveira Date: Wed, 28 Dec 2016 15:30:19 -0200 Subject: [PATCH] go fmt --- cmd.go | 2 +- lexical/lexemes.go | 22 ++++++------ runtime/commits.go | 47 +++++++++++++------------- runtime/reference.go | 74 ++++++++++++++++++++--------------------- runtime/remotes.go | 48 +++++++++++++------------- runtime/runtime.go | 2 +- runtime/runtime_test.go | 4 +-- 7 files changed, 99 insertions(+), 100 deletions(-) diff --git a/cmd.go b/cmd.go index 0c4573e..fdd7caa 100644 --- a/cmd.go +++ b/cmd.go @@ -101,7 +101,7 @@ func runQuery(query, folder, typeFormat string) error { return err } - return runtime.Run(ast, &typeFormat); + return runtime.Run(ast, &typeFormat) } func (cmd *Gitql) parseCommandLine() error { diff --git a/lexical/lexemes.go b/lexical/lexemes.go index e8e8b76..9533a4f 100644 --- a/lexical/lexemes.go +++ b/lexical/lexemes.go @@ -1,13 +1,13 @@ package lexical -const L_SELECT = "select"; -const L_FROM = "from"; -const L_WHERE = "where"; -const L_ORDER = "order"; -const L_BY = "by"; -const L_OR = "or"; -const L_AND = "and"; -const L_LIMIT = "limit"; -const L_IN = "in"; -const L_ASC = "asc"; -const L_DESC = "desc"; \ No newline at end of file +const L_SELECT = "select" +const L_FROM = "from" +const L_WHERE = "where" +const L_ORDER = "order" +const L_BY = "by" +const L_OR = "or" +const L_AND = "and" +const L_LIMIT = "limit" +const L_IN = "in" +const L_ASC = "asc" +const L_DESC = "desc" diff --git a/runtime/commits.go b/runtime/commits.go index 086a49b..b7c6e75 100644 --- a/runtime/commits.go +++ b/runtime/commits.go @@ -9,11 +9,10 @@ import ( "github.com/cloudson/gitql/parser" ) - -func walkCommits(n *parser.NodeProgram, visitor *RuntimeVisitor) (*TableData, error){ - builder.walk, _ = repo.Walk() - builder.walk.PushHead() - builder.walk.Sorting(git.SortTime) +func walkCommits(n *parser.NodeProgram, visitor *RuntimeVisitor) (*TableData, error) { + builder.walk, _ = repo.Walk() + builder.walk.PushHead() + builder.walk.Sorting(git.SortTime) s := n.Child.(*parser.NodeSelect) where := s.Where @@ -47,25 +46,25 @@ func walkCommits(n *parser.NodeProgram, visitor *RuntimeVisitor) (*TableData, er return true } - err := builder.walk.Iterate(fn) - if err != nil { - fmt.Printf(err.Error()) - } - rowsSliced := rows[len(rows)-counter+1:] - rowsSliced, err = orderTable(rowsSliced, s.Order) - if err != nil { - return nil, err - } - if usingOrder { - if counter > s.Limit { - counter = s.Limit - } - rowsSliced = rowsSliced[0:counter] - } - tableData := new(TableData) - tableData.rows = rowsSliced - tableData.fields = fields - return tableData, nil + err := builder.walk.Iterate(fn) + if err != nil { + fmt.Printf(err.Error()) + } + rowsSliced := rows[len(rows)-counter+1:] + rowsSliced, err = orderTable(rowsSliced, s.Order) + if err != nil { + return nil, err + } + if usingOrder { + if counter > s.Limit { + counter = s.Limit + } + rowsSliced = rowsSliced[0:counter] + } + tableData := new(TableData) + tableData.rows = rowsSliced + tableData.fields = fields + return tableData, nil } func metadataCommit(identifier string, object *git.Commit) string { diff --git a/runtime/reference.go b/runtime/reference.go index 92fa073..e82d977 100644 --- a/runtime/reference.go +++ b/runtime/reference.go @@ -7,9 +7,9 @@ import ( "github.com/cloudson/gitql/parser" ) -func walkReferences(n *parser.NodeProgram, visitor *RuntimeVisitor) (*TableData, error){ - s := n.Child.(*parser.NodeSelect) - where := s.Where +func walkReferences(n *parser.NodeProgram, visitor *RuntimeVisitor) (*TableData, error) { + s := n.Child.(*parser.NodeSelect) + where := s.Where // @TODO make PR with Repository.WalkReference() iterator, err := builder.repo.NewReferenceIterator() @@ -28,40 +28,40 @@ func walkReferences(n *parser.NodeProgram, visitor *RuntimeVisitor) (*TableData, } for object, inTheEnd := iterator.Next(); inTheEnd == nil; object, inTheEnd = iterator.Next() { - builder.setReference(object) - boolRegister = true - visitor.VisitExpr(where) - if boolRegister { - fields := s.Fields - if s.WildCard { - fields = builder.possibleTables[s.Tables[0]] - } - newRow := make(tableRow) - for _, f := range fields { - newRow[f] = metadataReference(f, object) - } - rows = append(rows, newRow) - counter = counter + 1 - if !usingOrder && counter > s.Limit { - break - } - } - } - rowsSliced := rows[len(rows)-counter+1:] - rowsSliced, err = orderTable(rowsSliced, s.Order) - if err != nil { - return nil, err - } - if usingOrder { - if counter > s.Limit { - counter = s.Limit - } - rowsSliced = rowsSliced[0:counter] - } - tableData := new(TableData) - tableData.rows = rowsSliced - tableData.fields = fields - return tableData, nil + builder.setReference(object) + boolRegister = true + visitor.VisitExpr(where) + if boolRegister { + fields := s.Fields + if s.WildCard { + fields = builder.possibleTables[s.Tables[0]] + } + newRow := make(tableRow) + for _, f := range fields { + newRow[f] = metadataReference(f, object) + } + rows = append(rows, newRow) + counter = counter + 1 + if !usingOrder && counter > s.Limit { + break + } + } + } + rowsSliced := rows[len(rows)-counter+1:] + rowsSliced, err = orderTable(rowsSliced, s.Order) + if err != nil { + return nil, err + } + if usingOrder { + if counter > s.Limit { + counter = s.Limit + } + rowsSliced = rowsSliced[0:counter] + } + tableData := new(TableData) + tableData.rows = rowsSliced + tableData.fields = fields + return tableData, nil } func metadataReference(identifier string, object *git.Reference) string { diff --git a/runtime/remotes.go b/runtime/remotes.go index 54cb834..cdb6cf8 100644 --- a/runtime/remotes.go +++ b/runtime/remotes.go @@ -7,9 +7,9 @@ import ( "github.com/cloudson/gitql/parser" ) -func walkRemotes(n *parser.NodeProgram, visitor *RuntimeVisitor) (*TableData, error){ - s := n.Child.(*parser.NodeSelect) - where := s.Where +func walkRemotes(n *parser.NodeProgram, visitor *RuntimeVisitor) (*TableData, error) { + s := n.Child.(*parser.NodeSelect) + where := s.Where remoteNames, err := builder.repo.ListRemotes() if err != nil { @@ -43,27 +43,27 @@ func walkRemotes(n *parser.NodeProgram, visitor *RuntimeVisitor) (*TableData, er } rows = append(rows, newRow) - counter = counter + 1 - if !usingOrder && counter > s.Limit { - break - } - } - } - rowsSliced := rows[len(rows)-counter+1:] - rowsSliced, err = orderTable(rowsSliced, s.Order) - if err != nil { - return nil, err - } - if usingOrder { - if counter > s.Limit { - counter = s.Limit - } - rowsSliced = rowsSliced[0:counter] - } - tableData := new(TableData) - tableData.rows = rowsSliced - tableData.fields = fields - return tableData, nil + counter = counter + 1 + if !usingOrder && counter > s.Limit { + break + } + } + } + rowsSliced := rows[len(rows)-counter+1:] + rowsSliced, err = orderTable(rowsSliced, s.Order) + if err != nil { + return nil, err + } + if usingOrder { + if counter > s.Limit { + counter = s.Limit + } + rowsSliced = rowsSliced[0:counter] + } + tableData := new(TableData) + tableData.rows = rowsSliced + tableData.fields = fields + return tableData, nil } func metadataRemote(identifier string, object *git.Remote) string { diff --git a/runtime/runtime.go b/runtime/runtime.go index 8b02d29..ed99b88 100644 --- a/runtime/runtime.go +++ b/runtime/runtime.go @@ -5,11 +5,11 @@ import ( "log" "os" + "encoding/json" "github.com/cloudson/git2go" "github.com/cloudson/gitql/parser" "github.com/cloudson/gitql/semantical" "github.com/olekukonko/tablewriter" - "encoding/json" ) const ( diff --git a/runtime/runtime_test.go b/runtime/runtime_test.go index 83e51fb..fa54dd9 100644 --- a/runtime/runtime_test.go +++ b/runtime/runtime_test.go @@ -1,10 +1,10 @@ package runtime import ( - "path/filepath" - "testing" "github.com/cloudson/gitql/parser" "github.com/cloudson/gitql/semantical" + "path/filepath" + "testing" ) func TestErrorWithInvalidTables(t *testing.T) {