@@ -17,9 +17,12 @@ const statusSuccess = "success"
17
17
type HistoricalCommand struct {
18
18
argparser.Base
19
19
20
- Input fastly. GetStatsInput
20
+ by string
21
21
formatFlag string
22
+ from string
23
+ region string
22
24
serviceName argparser.OptionalServiceNameID
25
+ to string
23
26
}
24
27
25
28
// NewHistoricalCommand is the "stats historical" subcommand.
@@ -41,10 +44,10 @@ func NewHistoricalCommand(parent argparser.Registerer, g *global.Data) *Historic
41
44
Dst : & c .serviceName .Value ,
42
45
})
43
46
44
- c .CmdClause .Flag ("from" , "From time, accepted formats at https://fastly.dev/reference/api/metrics-stats/historical-stats" ).StringVar (c . Input . From )
45
- c .CmdClause .Flag ("to" , "To time" ).StringVar (c . Input . To )
46
- c .CmdClause .Flag ("by" , "Aggregation period (minute/hour/day)" ).EnumVar (c . Input . By , "minute" , "hour" , "day" )
47
- c .CmdClause .Flag ("region" , "Filter by region ('stats regions' to list)" ).StringVar (c . Input . Region )
47
+ c .CmdClause .Flag ("from" , "From time, accepted formats at https://fastly.dev/reference/api/metrics-stats/historical-stats" ).StringVar (& c . from )
48
+ c .CmdClause .Flag ("to" , "To time" ).StringVar (& c . to )
49
+ c .CmdClause .Flag ("by" , "Aggregation period (minute/hour/day)" ).EnumVar (& c . by , "minute" , "hour" , "day" )
50
+ c .CmdClause .Flag ("region" , "Filter by region ('stats regions' to list)" ).StringVar (& c . region )
48
51
49
52
c .CmdClause .Flag ("format" , "Output format (json)" ).EnumVar (& c .formatFlag , "json" )
50
53
@@ -61,10 +64,24 @@ func (c *HistoricalCommand) Exec(_ io.Reader, out io.Writer) error {
61
64
argparser .DisplayServiceID (serviceID , flag , source , out )
62
65
}
63
66
64
- c .Input .Service = fastly .ToPointer (serviceID )
67
+ input := fastly.GetStatsInput {
68
+ Service : fastly .ToPointer (serviceID ),
69
+ }
70
+ if c .by != "" {
71
+ input .By = & c .by
72
+ }
73
+ if c .from != "" {
74
+ input .From = & c .from
75
+ }
76
+ if c .region != "" {
77
+ input .Region = & c .region
78
+ }
79
+ if c .to != "" {
80
+ input .To = & c .to
81
+ }
65
82
66
83
var envelope statsResponse
67
- err = c .Globals .APIClient .GetStatsJSON (& c . Input , & envelope )
84
+ err = c .Globals .APIClient .GetStatsJSON (& input , & envelope )
68
85
if err != nil {
69
86
c .Globals .ErrLog .AddWithContext (err , map [string ]any {
70
87
"Service ID" : serviceID ,
0 commit comments