Skip to content

Commit

Permalink
sort options and add id to verbose output
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Jeromy <jeromyj@gmail.com>
  • Loading branch information
whyrusleeping committed Feb 2, 2016
1 parent df0f87a commit 4753e6c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
11 changes: 8 additions & 3 deletions commands/reqlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,18 @@ type ReqLogEntry struct {
}

func (r *ReqLogEntry) Finish() {
r.log.lock.Lock()
defer r.log.lock.Unlock()
log := r.log
log.lock.Lock()
defer log.lock.Unlock()

r.Active = false
r.EndTime = time.Now()

r.log.maybeCleanup()

// remove references to save memory
r.req = nil
r.log = nil

}

func (r *ReqLogEntry) Copy() *ReqLogEntry {
Expand Down
17 changes: 15 additions & 2 deletions core/commands/active.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"io"
"sort"
"text/tabwriter"
"time"

Expand Down Expand Up @@ -35,18 +36,30 @@ Lists running and recently run commands.
verbose, _, _ := res.Request().Option("v").Bool()

w := tabwriter.NewWriter(buf, 4, 4, 2, ' ', 0)
if verbose {
fmt.Fprint(w, "ID\t")
}
fmt.Fprint(w, "Command\t")
if verbose {
fmt.Fprint(w, "Arguments\tOptions\t")
}
fmt.Fprintln(w, "Active\tStartTime\tRunTime")

for _, req := range *out {
if verbose {
fmt.Fprintf(w, "%d\t", req.ID)
}
fmt.Fprintf(w, "%s\t", req.Command)
if verbose {
fmt.Fprintf(w, "%v\t[", req.Args)
for k, v := range req.Options {
fmt.Fprintf(w, "%s=%v,", k, v)
var keys []string
for k, _ := range req.Options {
keys = append(keys, k)
}
sort.Strings(keys)

for _, k := range keys {
fmt.Fprintf(w, "%s=%v,", k, req.Options[k])
}
fmt.Fprintf(w, "]\t")
}
Expand Down

0 comments on commit 4753e6c

Please sign in to comment.