1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-29 01:12:24 +08:00

verbose mode

License: MIT
Signed-off-by: Jeromy <jeromyj@gmail.com>
This commit is contained in:
Jeromy
2016-02-01 17:21:13 -08:00
parent 6e863830bf
commit df0f87a8eb

View File

@ -20,6 +20,9 @@ Lists running and recently run commands.
Run: func(req cmds.Request, res cmds.Response) {
res.SetOutput(req.InvocContext().ReqLog.Report())
},
Options: []cmds.Option{
cmds.BoolOption("v", "verbose", "print more verbose output"),
},
Marshalers: map[cmds.EncodingType]cmds.Marshaler{
cmds.Text: func(res cmds.Response) (io.Reader, error) {
out, ok := res.Output().(*[]*cmds.ReqLogEntry)
@ -29,14 +32,33 @@ Lists running and recently run commands.
}
buf := new(bytes.Buffer)
verbose, _, _ := res.Request().Option("v").Bool()
w := tabwriter.NewWriter(buf, 4, 4, 2, ' ', 0)
fmt.Fprintln(w, "Command\tActive\tStartTime\tRunTime")
fmt.Fprint(w, "Command\t")
if verbose {
fmt.Fprint(w, "Arguments\tOptions\t")
}
fmt.Fprintln(w, "Active\tStartTime\tRunTime")
for _, req := range *out {
if req.Active {
fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", req.Command, "true", req.StartTime, time.Now().Sub(req.StartTime))
} else {
fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", req.Command, "false", req.StartTime, req.EndTime.Sub(req.StartTime))
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)
}
fmt.Fprintf(w, "]\t")
}
var live time.Duration
if req.Active {
live = time.Now().Sub(req.StartTime)
} else {
live = req.EndTime.Sub(req.StartTime)
}
t := req.StartTime.Format(time.Stamp)
fmt.Fprintf(w, "%t\t%s\t%s\n", req.Active, t, live)
}
w.Flush()