mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-28 17:03:58 +08:00
sort options and add id to verbose output
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
This commit is contained in:
@ -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 {
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"sort"
|
||||
"text/tabwriter"
|
||||
"time"
|
||||
|
||||
@ -35,6 +36,9 @@ 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")
|
||||
@ -42,11 +46,20 @@ Lists running and recently run commands.
|
||||
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")
|
||||
}
|
||||
|
Reference in New Issue
Block a user