New -l=1
argument to limit loop count
#6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds a new
-l=1
argument to limit the loop count (the number of timesgetStats
is called).Motivation: I'd like to be able to log stats using
cron
orlaunchd
, rather than leavingnode
running.I haven't modified
README.md
yet to document this change, but I'm willing to do so if you'd like.The default behavior is still to continue looping until the process is terminated. Note that line 95 evaluates to
false
becauseloopsRequested
defaults to-1
, which isn't greater than1
.node vscode-marketplace-stats -l=1 eamodio.gitlens
(or-l=0
) will callgetStats
only once, without triggering thesetInterval
on line 49. Note that line 95 evaluates to false becauseloopsRequested
isn't greater than1
.node vscode-marketplace-stats -l=2 eamodio.gitlens
will start with the pre-existing behavior:getStats
is called once initially, thensetInterval
is called to begin looping. But only 1 loop is run (for a total of twogetStats
calls), before line 95 evaluates to true, and line 96 runsclearInterval
.Ditto for
-l=3
and above, just with moregetStats
calls.Argument parsing is pretty basic, currently
-l=2
must be before theextensionName
, so attempting to run:node vscode-marketplace-stats eamodio.gitlens -l=2
... would result in
-l=2
being ignored, resulting in behavior identical to:node vscode-marketplace-stats eamodio.gitlens
... I'm happy to add another commit to support
node vscode-marketplace-stats eamodio.gitlens -l=2
if you'd like.This PR also includes two minor changes:
extensionName
('RandomFractalsInc.vscode-data-preview') was never being used (always overwritten, or "Please specify extension name" would be shown), so I removed it.extensionName
was being explicitly passed into thecreateStatsFile
&createStatsRequestBody
functions, but not into thegetStats
function. I made a small change for consistency, now all 3 functions are receiving it as an argument, rather than relying on it being in scope.