verbose mode
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
Jeromy committed
Feb 1, 2016 at 17:21 UTC
df0f87a8ebda62fe0b7d35ea85048fef8b922c2a
1 file changed
+25
-3
core/commands/active.go
+25
-3
@@ -20,6 +20,9 @@ Lists running and recently run commands.
20
Run: func(req cmds.Request, res cmds.Response) {
21
res.SetOutput(req.InvocContext().ReqLog.Report())
22
},
23
+ Options: []cmds.Option{
24
+ cmds.BoolOption("v", "verbose", "print more verbose output"),
25
+ },
26
Marshalers: map[cmds.EncodingType]cmds.Marshaler{
27
cmds.Text: func(res cmds.Response) (io.Reader, error) {
28
out, ok := res.Output().(*[]*cmds.ReqLogEntry)
@@ -29,14 +32,33 @@ Lists running and recently run commands.
32
}
33
buf := new(bytes.Buffer)
34
35
+ verbose, _, _ := res.Request().Option("v").Bool()
36
+
37
w := tabwriter.NewWriter(buf, 4, 4, 2, ' ', 0)
33
- fmt.Fprintln(w, "Command\tActive\tStartTime\tRunTime")
38
+ fmt.Fprint(w, "Command\t")
39
+ if verbose {
40
+ fmt.Fprint(w, "Arguments\tOptions\t")
41
+ }
42
+ fmt.Fprintln(w, "Active\tStartTime\tRunTime")
43
+
44
for _, req := range *out {
45
+ fmt.Fprintf(w, "%s\t", req.Command)
46
+ if verbose {
47
+ fmt.Fprintf(w, "%v\t[", req.Args)
48
+ for k, v := range req.Options {
49
+ fmt.Fprintf(w, "%s=%v,", k, v)
50
+ }
51
+ fmt.Fprintf(w, "]\t")
52
+ }
53
+
54
+ var live time.Duration
55
if req.Active {
36
- fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", req.Command, "true", req.StartTime, time.Now().Sub(req.StartTime))
56
+ live = time.Now().Sub(req.StartTime)
57
} else {
38
- fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", req.Command, "false", req.StartTime, req.EndTime.Sub(req.StartTime))
58
+ live = req.EndTime.Sub(req.StartTime)
59
}
60
+ t := req.StartTime.Format(time.Stamp)
61
+ fmt.Fprintf(w, "%t\t%s\t%s\n", req.Active, t, live)
62
}
63
w.Flush()
64