@@ -26,10 +26,10 @@ export const analytics: CliSubcommand = {
26
26
}
27
27
const spinner = ora ( 'Fetching analytics data' ) . start ( )
28
28
if ( input . scope === 'org' ) {
29
- await fetchOrgAnalyticsData ( input . time , spinner , apiKey )
29
+ await fetchOrgAnalyticsData ( input . time , spinner , apiKey , input . outputJson )
30
30
} else {
31
31
if ( input . repo ) {
32
- await fetchRepoAnalyticsData ( input . repo , input . time , spinner , apiKey )
32
+ await fetchRepoAnalyticsData ( input . repo , input . time , spinner , apiKey , input . outputJson )
33
33
}
34
34
}
35
35
}
@@ -42,6 +42,7 @@ type CommandContext = {
42
42
scope : string
43
43
time : string
44
44
repo : string | undefined
45
+ outputJson : boolean
45
46
}
46
47
47
48
function setupCommand ( name : string , description : string , argv : readonly string [ ] , importMeta : ImportMeta ) : void | CommandContext {
@@ -67,6 +68,10 @@ function setupCommand (name: string, description: string, argv: readonly string[
67
68
flags
68
69
} )
69
70
71
+ const {
72
+ json : outputJson
73
+ } = cli . flags
74
+
70
75
const scope = cli . input [ 0 ]
71
76
72
77
if ( ! scope ) {
@@ -93,12 +98,12 @@ function setupCommand (name: string, description: string, argv: readonly string[
93
98
throw new InputError ( 'The time filter must either be 7, 30 or 60' )
94
99
}
95
100
96
- return {
97
- scope, time, repo
101
+ return < CommandContext > {
102
+ scope, time, repo, outputJson
98
103
}
99
104
}
100
105
101
- async function fetchOrgAnalyticsData ( time : string , spinner : Ora , apiKey : string ) : Promise < void > {
106
+ async function fetchOrgAnalyticsData ( time : string , spinner : Ora , apiKey : string , outputJson : boolean ) : Promise < void > {
102
107
const socketSdk = await setupSdk ( apiKey )
103
108
const result = await handleApiCall ( socketSdk . getOrgAnalytics ( time ) , 'fetching analytics data' )
104
109
@@ -128,6 +133,10 @@ async function fetchOrgAnalyticsData (time: string, spinner: Ora, apiKey: string
128
133
return acc
129
134
} , { } )
130
135
136
+ if ( outputJson ) {
137
+ return console . log ( data )
138
+ }
139
+
131
140
const screen = blessed . screen ( )
132
141
// eslint-disable-next-line
133
142
const grid = new contrib . grid ( { rows : 4 , cols : 4 , screen} )
@@ -161,7 +170,7 @@ async function fetchOrgAnalyticsData (time: string, spinner: Ora, apiKey: string
161
170
} )
162
171
}
163
172
164
- async function fetchRepoAnalyticsData ( repo : string , time : string , spinner : Ora , apiKey : string ) : Promise < void > {
173
+ async function fetchRepoAnalyticsData ( repo : string , time : string , spinner : Ora , apiKey : string , outputJson : boolean ) : Promise < void > {
165
174
const socketSdk = await setupSdk ( apiKey )
166
175
const result = await handleApiCall ( socketSdk . getRepoAnalytics ( repo , time ) , 'fetching analytics data' )
167
176
@@ -190,6 +199,10 @@ async function fetchRepoAnalyticsData (repo: string, time: string, spinner: Ora,
190
199
return acc
191
200
} , { } )
192
201
202
+ if ( outputJson ) {
203
+ return console . log ( data )
204
+ }
205
+
193
206
const screen = blessed . screen ( )
194
207
// eslint-disable-next-line
195
208
const grid = new contrib . grid ( { rows : 4 , cols : 4 , screen} )
0 commit comments