@@ -26,7 +26,7 @@ func stat() *cobra.Command {
2626 return fmt .Errorf ("getting the statistics: %w" , err )
2727 }
2828 if rsp .StatusCode () != http .StatusOK {
29- return fmt .Errorf ("getting the statistics: %s" , string (rsp .Body ))
29+ return fmt .Errorf ("getting the statistics: %s" , extractErrorMessage (rsp .Body ))
3030 }
3131
3232 if output .Format (cmd ) == output .FmtJSON {
@@ -56,7 +56,7 @@ func stat() *cobra.Command {
5656 }
5757
5858 var cmdCalls = & cobra.Command {
59- Use : "calls <app_name>" ,
59+ Use : "calls [ <app_name>] " ,
6060 Aliases : []string {"calls" },
6161 Short : "Show app calls statistic" ,
6262 Long : `Show number of app calls, grouped by time slots and HTTP statuses.
@@ -65,11 +65,15 @@ but you can change reporting interval using "--from" and "--to" flags
6565(specifying date/time in format "YYYY-MM-DD HH:mm:SS", where either date or time,
6666can be omitted, or as UNIX timestamp) and reporting step duration with flag
6767"--step" (in seconds).` ,
68- Args : cobra .ExactArgs (1 ),
68+ Args : cobra .MaximumNArgs (1 ),
6969 RunE : func (cmd * cobra.Command , args []string ) error {
70- id , err := getAppIdByName (args [0 ])
71- if err != nil {
72- return fmt .Errorf ("cannot find app by name: %w" , err )
70+ var appId * int64
71+ if len (args ) > 0 {
72+ id , err := getAppIdByName (args [0 ])
73+ if err != nil {
74+ return fmt .Errorf ("cannot find app by name: %w" , err )
75+ }
76+ appId = & id
7377 }
7478
7579 from , err := parseTimeFlag (cmd , "from" )
@@ -87,10 +91,10 @@ can be omitted, or as UNIX timestamp) and reporting step duration with flag
8791 return fmt .Errorf ("cannot parse reporting step: %w" , err )
8892 }
8993
90- rsp , err := client .AppCallsWithResponse (
94+ rsp , err := client .StatsCallsWithResponse (
9195 context .Background (),
92- id ,
93- & sdk. AppCallsParams {
96+ & sdk. StatsCallsParams {
97+ Id : appId ,
9498 From : from ,
9599 To : to ,
96100 Step : step ,
@@ -100,7 +104,7 @@ can be omitted, or as UNIX timestamp) and reporting step duration with flag
100104 return fmt .Errorf ("cannot get statistics: %w" , err )
101105 }
102106 if rsp .StatusCode () != http .StatusOK {
103- return fmt .Errorf ("cannot get statistics: %s" , string (rsp .Body ))
107+ return fmt .Errorf ("cannot get statistics: %s" , extractErrorMessage (rsp .Body ))
104108 }
105109
106110 if output .Format (cmd ) == output .FmtJSON {
@@ -168,7 +172,7 @@ can be omitted, or as UNIX timestamp) and reporting step duration with flag
168172 statFlags (cmdCalls )
169173
170174 var cmdDuration = & cobra.Command {
171- Use : "duration <app_name>" ,
175+ Use : "duration [ <app_name>] " ,
172176 Aliases : []string {"duration" , "time" , "timing" },
173177 Short : "Show app execution duration" ,
174178 Long : `Show duration of app calls, grouped by time slots. All times are in msec
@@ -177,11 +181,15 @@ but you can change reporting interval using "--from" and "--to" flags
177181(specifying date/time in format "YYYY-MM-DD HH:mm:SS", where either date or time,
178182can be omitted, or as UNIX timestamp) and reporting step duration with flag
179183"--step" (in seconds).` ,
180- Args : cobra .ExactArgs (1 ),
184+ Args : cobra .MaximumNArgs (1 ),
181185 RunE : func (cmd * cobra.Command , args []string ) error {
182- id , err := getAppIdByName (args [0 ])
183- if err != nil {
184- return fmt .Errorf ("cannot find app by name: %w" , err )
186+ var appId * int64
187+ if len (args ) > 0 {
188+ id , err := getAppIdByName (args [0 ])
189+ if err != nil {
190+ return fmt .Errorf ("cannot find app by name: %w" , err )
191+ }
192+ appId = & id
185193 }
186194
187195 from , err := parseTimeFlag (cmd , "from" )
@@ -199,10 +207,10 @@ can be omitted, or as UNIX timestamp) and reporting step duration with flag
199207 return fmt .Errorf ("cannot parse reporting step: %w" , err )
200208 }
201209
202- rsp , err := client .AppDurationWithResponse (
210+ rsp , err := client .StatsDurationWithResponse (
203211 context .Background (),
204- id ,
205- & sdk. AppDurationParams {
212+ & sdk. StatsDurationParams {
213+ Id : appId ,
206214 From : from ,
207215 To : to ,
208216 Step : step ,
@@ -212,7 +220,7 @@ can be omitted, or as UNIX timestamp) and reporting step duration with flag
212220 return fmt .Errorf ("cannot get statistics: %w" , err )
213221 }
214222 if rsp .StatusCode () != http .StatusOK {
215- return fmt .Errorf ("cannot get statistics: %s" , string (rsp .Body ))
223+ return fmt .Errorf ("cannot get statistics: %s" , extractErrorMessage (rsp .Body ))
216224 }
217225
218226 if output .Format (cmd ) == output .FmtJSON {
0 commit comments