| OLD | NEW |
| 1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package cli | 5 package cli |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "bufio" | 8 "bufio" |
| 9 "encoding/json" | 9 "encoding/json" |
| 10 "io" | 10 "io" |
| 11 "os" | 11 "os" |
| 12 | 12 |
| 13 "github.com/luci/luci-go/common/clock/clockflag" | 13 "github.com/luci/luci-go/common/clock/clockflag" |
| 14 "github.com/luci/luci-go/common/errors" |
| 14 log "github.com/luci/luci-go/common/logging" | 15 log "github.com/luci/luci-go/common/logging" |
| 15 "github.com/luci/luci-go/logdog/api/logpb" | 16 "github.com/luci/luci-go/logdog/api/logpb" |
| 16 "github.com/luci/luci-go/logdog/client/butlerlib/streamproto" | 17 "github.com/luci/luci-go/logdog/client/butlerlib/streamproto" |
| 17 "github.com/luci/luci-go/logdog/client/coordinator" | 18 "github.com/luci/luci-go/logdog/client/coordinator" |
| 18 | 19 |
| 19 "github.com/maruel/subcommands" | 20 "github.com/maruel/subcommands" |
| 20 "golang.org/x/net/context" | 21 "golang.org/x/net/context" |
| 21 ) | 22 ) |
| 22 | 23 |
| 23 const ( | 24 const ( |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 func (cmd *queryCommandRun) Run(scApp subcommands.Application, args []string, _
subcommands.Env) int { | 68 func (cmd *queryCommandRun) Run(scApp subcommands.Application, args []string, _
subcommands.Env) int { |
| 68 a := scApp.(*application) | 69 a := scApp.(*application) |
| 69 | 70 |
| 70 // User-friendly: trim any leading or trailing slashes from the path. | 71 // User-friendly: trim any leading or trailing slashes from the path. |
| 71 project, path, unified, err := a.splitPath(cmd.path) | 72 project, path, unified, err := a.splitPath(cmd.path) |
| 72 if err != nil { | 73 if err != nil { |
| 73 log.WithError(err).Errorf(a, "Invalid path specifier.") | 74 log.WithError(err).Errorf(a, "Invalid path specifier.") |
| 74 return 1 | 75 return 1 |
| 75 } | 76 } |
| 76 | 77 |
| 78 coord, err := a.coordinatorClient("") |
| 79 if err != nil { |
| 80 errors.Log(a, errors.Annotate(err).Reason("could not create Coor
dinator client").Err()) |
| 81 return 1 |
| 82 } |
| 83 |
| 77 // Open our output file, if necessary. | 84 // Open our output file, if necessary. |
| 78 w := io.Writer(nil) | 85 w := io.Writer(nil) |
| 79 switch cmd.out { | 86 switch cmd.out { |
| 80 case "-": | 87 case "-": |
| 81 w = os.Stdout | 88 w = os.Stdout |
| 82 default: | 89 default: |
| 83 f, err := os.OpenFile(cmd.out, os.O_WRONLY|os.O_CREATE|os.O_TRUN
C, 0643) | 90 f, err := os.OpenFile(cmd.out, os.O_WRONLY|os.O_CREATE|os.O_TRUN
C, 0643) |
| 84 if err != nil { | 91 if err != nil { |
| 85 log.Fields{ | 92 log.Fields{ |
| 86 log.ErrorKey: err, | 93 log.ErrorKey: err, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 112 State: cmd.json, | 119 State: cmd.json, |
| 113 Before: cmd.before.Time(), | 120 Before: cmd.before.Time(), |
| 114 After: cmd.after.Time(), | 121 After: cmd.after.Time(), |
| 115 Purged: cmd.purged.Trinary(), | 122 Purged: cmd.purged.Trinary(), |
| 116 } | 123 } |
| 117 count := 0 | 124 count := 0 |
| 118 log.Debugf(a, "Issuing query...") | 125 log.Debugf(a, "Issuing query...") |
| 119 | 126 |
| 120 tctx, _ := a.timeoutCtx(a) | 127 tctx, _ := a.timeoutCtx(a) |
| 121 ierr := error(nil) | 128 ierr := error(nil) |
| 122 » err = a.coord.Query(tctx, project, path, qo, func(s *coordinator.LogStre
am) bool { | 129 » err = coord.Query(tctx, project, path, qo, func(s *coordinator.LogStream
) bool { |
| 123 if err := o.emit(s); err != nil { | 130 if err := o.emit(s); err != nil { |
| 124 ierr = err | 131 ierr = err |
| 125 return false | 132 return false |
| 126 } | 133 } |
| 127 | 134 |
| 128 count++ | 135 count++ |
| 129 return !(cmd.results > 0 && count >= cmd.results) | 136 return !(cmd.results > 0 && count >= cmd.results) |
| 130 }) | 137 }) |
| 131 if err == nil { | 138 if err == nil { |
| 132 // Propagate internal error. | 139 // Propagate internal error. |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 } | 264 } |
| 258 | 265 |
| 259 func (p *jsonQueryOutput) end() error { | 266 func (p *jsonQueryOutput) end() error { |
| 260 if err := p.ensureStart(); err != nil { | 267 if err := p.ensureStart(); err != nil { |
| 261 return err | 268 return err |
| 262 } | 269 } |
| 263 | 270 |
| 264 _, err := p.WriteRune(']') | 271 _, err := p.WriteRune(']') |
| 265 return err | 272 return err |
| 266 } | 273 } |
| OLD | NEW |