@@ -19,31 +19,38 @@ import (
19
19
// ProcessCommand displays information about a Go process.
20
20
func ProcessCommand () * cobra.Command {
21
21
return & cobra.Command {
22
- Use : "process" ,
22
+ Use : "process <pid> [period] " ,
23
23
Aliases : []string {"pid" , "proc" },
24
24
Short : "Prints information about a Go process." ,
25
+ Args : cobra .MinimumNArgs (1 ),
25
26
RunE : func (cmd * cobra.Command , args []string ) error {
26
- ProcessInfo (args )
27
- return nil
27
+ return ProcessInfo (args )
28
28
},
29
29
}
30
30
}
31
31
32
32
// ProcessInfo takes arguments starting with pid|:addr and grabs all kinds of
33
33
// useful Go process information.
34
- func ProcessInfo (args []string ) {
34
+ func ProcessInfo (args []string ) error {
35
35
pid , err := strconv .Atoi (args [0 ])
36
+ if err != nil {
37
+ return fmt .Errorf ("error parsing the first argument: %w" , err )
38
+ }
36
39
37
40
var period time.Duration
38
41
if len (args ) >= 2 {
39
42
period , err = time .ParseDuration (args [1 ])
40
43
if err != nil {
41
- secs , _ := strconv .Atoi (args [1 ])
44
+ secs , err := strconv .Atoi (args [1 ])
45
+ if err != nil {
46
+ return fmt .Errorf ("error parsing the second argument: %w" , err )
47
+ }
42
48
period = time .Duration (secs ) * time .Second
43
49
}
44
50
}
45
51
46
52
processInfo (pid , period )
53
+ return nil
47
54
}
48
55
49
56
func processInfo (pid int , period time.Duration ) {
0 commit comments