mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-29 17:36:38 +08:00
verbose mode
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
This commit is contained in:
@ -20,6 +20,9 @@ Lists running and recently run commands.
|
|||||||
Run: func(req cmds.Request, res cmds.Response) {
|
Run: func(req cmds.Request, res cmds.Response) {
|
||||||
res.SetOutput(req.InvocContext().ReqLog.Report())
|
res.SetOutput(req.InvocContext().ReqLog.Report())
|
||||||
},
|
},
|
||||||
|
Options: []cmds.Option{
|
||||||
|
cmds.BoolOption("v", "verbose", "print more verbose output"),
|
||||||
|
},
|
||||||
Marshalers: map[cmds.EncodingType]cmds.Marshaler{
|
Marshalers: map[cmds.EncodingType]cmds.Marshaler{
|
||||||
cmds.Text: func(res cmds.Response) (io.Reader, error) {
|
cmds.Text: func(res cmds.Response) (io.Reader, error) {
|
||||||
out, ok := res.Output().(*[]*cmds.ReqLogEntry)
|
out, ok := res.Output().(*[]*cmds.ReqLogEntry)
|
||||||
@ -29,14 +32,33 @@ Lists running and recently run commands.
|
|||||||
}
|
}
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
|
|
||||||
|
verbose, _, _ := res.Request().Option("v").Bool()
|
||||||
|
|
||||||
w := tabwriter.NewWriter(buf, 4, 4, 2, ' ', 0)
|
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 {
|
for _, req := range *out {
|
||||||
if req.Active {
|
fmt.Fprintf(w, "%s\t", req.Command)
|
||||||
fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", req.Command, "true", req.StartTime, time.Now().Sub(req.StartTime))
|
if verbose {
|
||||||
} else {
|
fmt.Fprintf(w, "%v\t[", req.Args)
|
||||||
fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", req.Command, "false", req.StartTime, req.EndTime.Sub(req.StartTime))
|
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()
|
w.Flush()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user