11const http = require ( 'http' ) ;
22const https = require ( 'https' ) ;
3- const commander = require ( 'commander' ) ;
3+ const { program } = require ( 'commander' ) ;
44const { auth } = require ( 'arsenal' ) ;
55const { UtapiClient, utapiVersion } = require ( 'utapi' ) ;
66const logger = require ( '../utilities/logger' ) ;
@@ -123,7 +123,7 @@ function _listMetrics(host,
123123 * @return {undefined }
124124 */
125125function listMetrics ( metricType ) {
126- commander
126+ program
127127 . version ( '0.0.1' )
128128 . option ( '-a, --access-key <accessKey>' , 'Access key id' )
129129 . option ( '-k, --secret-key <secretKey>' , 'Secret access key' ) ;
@@ -132,11 +132,11 @@ function listMetrics(metricType) {
132132 // bin/list_bucket_metrics.js when prior method of listing bucket metrics is
133133 // no longer supported.
134134 if ( metricType === 'buckets' ) {
135- commander
135+ program
136136 . option ( '-b, --buckets <buckets>' , 'Name of bucket(s) with ' +
137137 'a comma separator if more than one' ) ;
138138 } else {
139- commander
139+ program
140140 . option ( '-m, --metric <metric>' , 'Metric type' )
141141 . option ( '--buckets <buckets>' , 'Name of bucket(s) with a comma ' +
142142 'separator if more than one' )
@@ -146,7 +146,7 @@ function listMetrics(metricType) {
146146 'more than one' )
147147 . option ( '--service <service>' , 'Name of service' ) ;
148148 }
149- commander
149+ program
150150 . option ( '-s, --start <start>' , 'Start of time range' )
151151 . option ( '-r, --recent' , 'List metrics including the previous and ' +
152152 'current 15 minute interval' )
@@ -157,41 +157,39 @@ function listMetrics(metricType) {
157157 . option ( '-v, --verbose' )
158158 . parse ( process . argv ) ;
159159
160- const { host , port , accessKey , secretKey , start , end , verbose , recent ,
161- ssl } =
162- commander ;
160+
161+ const providedOptions = program . opts ( ) ;
162+ const { host , port , accessKey , secretKey , start , end , verbose , recent , ssl , metric : metricLvl } = providedOptions ;
163163 const requiredOptions = { host, port, accessKey, secretKey } ;
164164 // If not old style bucket metrics, we require usage of the metric option
165165 if ( metricType !== 'buckets' ) {
166- requiredOptions . metric = commander . metric ;
167166 const validMetrics = [ 'buckets' , 'accounts' , 'users' , 'service' ] ;
168- if ( validMetrics . indexOf ( commander . metric ) < 0 ) {
169- logger . error ( 'metric must be \'buckets\', \'accounts\', ' +
170- '\'users\', or \'service\'' ) ;
171- commander . outputHelp ( ) ;
167+ if ( validMetrics . indexOf ( metricLvl ) < 0 ) {
168+ logger . error ( "metric must be one of 'buckets', 'accounts', 'users', or 'service'" ) ;
169+ program . outputHelp ( ) ;
172170 process . exit ( 1 ) ;
173171 return ;
174172 }
175173 }
176174 // If old style bucket metrics, `metricType` will be 'buckets'. Otherwise,
177- // `commander.metric ` should be defined.
178- const metric = metricType === 'buckets' ? 'buckets' : commander . metric ;
179- requiredOptions [ metric ] = commander [ metric ] ;
175+ // `metricLvl ` should be defined.
176+ const metric = metricType === 'buckets' ? 'buckets' : metricLvl ;
177+ requiredOptions [ metric ] = providedOptions [ metric ] ;
180178 // If not recent listing, the start option must be provided
181179 if ( ! recent ) {
182- requiredOptions . start = commander . start ;
180+ requiredOptions . start = providedOptions . start ;
183181 }
184182 Object . keys ( requiredOptions ) . forEach ( option => {
185183 if ( ! requiredOptions [ option ] ) {
186184 logger . error ( `missing required option: ${ option } ` ) ;
187- commander . outputHelp ( ) ;
185+ program . outputHelp ( ) ;
188186 process . exit ( 1 ) ;
189187 }
190188 } ) ;
191189
192- // The string `commander [metric]` is a comma-separated list of resources
190+ // The string `providedOptions [metric]` is a comma-separated list of resources
193191 // given by the user.
194- const resources = commander [ metric ] . split ( ',' ) ;
192+ const resources = providedOptions [ metric ] . split ( ',' ) ;
195193
196194 // Validate passed accounts to remove any canonicalIDs
197195 if ( metric === 'accounts' ) {
@@ -208,7 +206,7 @@ function listMetrics(metricType) {
208206 const numStart = Number . parseInt ( start , 10 ) ;
209207 if ( ! numStart ) {
210208 logger . error ( 'start must be a number' ) ;
211- commander . outputHelp ( ) ;
209+ program . outputHelp ( ) ;
212210 process . exit ( 1 ) ;
213211 return ;
214212 }
@@ -217,7 +215,7 @@ function listMetrics(metricType) {
217215 const numEnd = Number . parseInt ( end , 10 ) ;
218216 if ( ! numEnd ) {
219217 logger . error ( 'end must be a number' ) ;
220- commander . outputHelp ( ) ;
218+ program . outputHelp ( ) ;
221219 process . exit ( 1 ) ;
222220 return ;
223221 }
@@ -331,6 +329,11 @@ function pushMetric(action, log, metricObj) {
331329 oldByteLength,
332330 numberOfObjects,
333331 } ;
332+
333+ if ( removedDeleteMarkers ) {
334+ utapiObj . numberOfObjects = numberOfObjects + removedDeleteMarkers ;
335+ }
336+
334337 // If `authInfo` is included by the API, get the account's canonical ID for
335338 // account-level metrics and the shortId for user-level metrics. Otherwise
336339 // check if the canonical ID is already provided for account-level metrics.
0 commit comments