Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New -l=1 argument to limit loop count #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mrienstra
Copy link

This PR adds a new -l=1 argument to limit the loop count (the number of times getStats is called).

Motivation: I'd like to be able to log stats using cron or launchd, rather than leaving node 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 because loopsRequested defaults to -1, which isn't greater than 1.

node vscode-marketplace-stats -l=1 eamodio.gitlens (or -l=0) will call getStats only once, without triggering the setInterval on line 49. Note that line 95 evaluates to false because loopsRequested isn't greater than 1.

node vscode-marketplace-stats -l=2 eamodio.gitlens will start with the pre-existing behavior: getStats is called once initially, then setInterval is called to begin looping. But only 1 loop is run (for a total of two getStats calls), before line 95 evaluates to true, and line 96 runs clearInterval.

Ditto for -l=3 and above, just with more getStats calls.


Argument parsing is pretty basic, currently -l=2 must be before the extensionName, 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:

  1. The default extensionName ('RandomFractalsInc.vscode-data-preview') was never being used (always overwritten, or "Please specify extension name" would be shown), so I removed it.
  2. extensionName was being explicitly passed into the createStatsFile & createStatsRequestBody functions, but not into the getStats 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.

This commit adds a new "-l=1" argument to limit the loop count (the number of times `getStats` is called).

Motivation: I'd like to be able to log stats using `cron` or `launchd`, rather than leaving `node` running.

The default behavior is still to continue looping until the process is terminated. Note that line 95 evaluates to false because `loopsRequested` defaults to -1, which isn't greater than 1.

`node vscode-marketplace-stats -l=1 eamodio.gitlens` (or `-l=0`) will call `getStats` only once, without triggering the `setInterval` on line 49. Note that line 95 evaluates to false because `loopsRequested` isn't greater than 1.

`node vscode-marketplace-stats -l=2 eamodio.gitlens` will start with the pre-existing behavior: `getStats` is called once initially, then `setInterval` is called to begin looping. But only 1 loop is run (for a total of two `getStats` calls), before line 95 evaluates to true, and line 96 runs `clearInterval`.

Ditto for `-l=3` and above, but with the expected number of `getStats` calls.

Argument parsing is pretty basic, currently `-l=2` must be before the `extensionName`, so:
`node vscode-marketplace-stats eamodio.gitlens -l=2`
... would be treated like:
`node vscode-marketplace-stats eamodio.gitlens`

... happy to change it to support `node vscode-marketplace-stats eamodio.gitlens -l=2` if you'd like.

Also two minor changes:

1. The default `extensionName` (`RandomFractalsInc.vscode-data-preview`) was never being used (always overwritten, or "Please specify extension name" would be shown), so I removed it.
2. `extensionName` was being explicitly passed into the `createStatsFile` &, `createStatsRequestBody` functions, but not into the `getStats` 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant