Skip to content
This repository has been archived by the owner on Nov 18, 2024. It is now read-only.

Commit

Permalink
fix exit codes
Browse files Browse the repository at this point in the history
  • Loading branch information
leordev committed Jun 1, 2024
1 parent dd74281 commit 023aff8
Showing 1 changed file with 35 additions and 29 deletions.
64 changes: 35 additions & 29 deletions metrics-collector/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as dotenv from "dotenv";
dotenv.config();

import yargs from "yargs";
import { hideBin } from 'yargs/helpers';
import { hideBin } from "yargs/helpers";

import { collectGhMetrics } from "./gh-metrics";
import { collectNpmMetrics } from "./npm-metrics";
Expand All @@ -11,38 +11,44 @@ import { collectSonatypeMetrics } from "./sonatype-metrics";
const isLocalPersistence = process.env.PERSIST_LOCAL_FILES === "true";

interface Arguments {
'collect-gh': boolean;
'collect-npm': boolean;
'collect-sonatype': boolean;
"collect-gh": boolean;
"collect-npm": boolean;
"collect-sonatype": boolean;
}

const argv = yargs(hideBin(process.argv))
.options({
'collect-gh': { type: 'boolean', description: 'Collect GitHub metrics', default: false },
'collect-npm': { type: 'boolean', description: 'Collect npm metrics', default: false },
'collect-sonatype': { type: 'boolean', description: 'Collect Sonatype metrics', default: false }
})
.argv as Arguments;
const argv = yargs(hideBin(process.argv)).options({
"collect-gh": {
type: "boolean",
description: "Collect GitHub metrics",
default: false,
},
"collect-npm": {
type: "boolean",
description: "Collect npm metrics",
default: false,
},
"collect-sonatype": {
type: "boolean",
description: "Collect Sonatype metrics",
default: false,
},
}).argv as Arguments;

async function main() {
try {
const collectGh = argv['collect-gh'];
const collectNpm = argv['collect-npm'];
const collectSonatype = argv['collect-sonatype'];

const noArgs = !collectGh && !collectNpm && !collectSonatype;

if (collectGh || noArgs) {
await collectGhMetrics(isLocalPersistence);
}
if (collectNpm || noArgs) {
await collectNpmMetrics(isLocalPersistence);
}
if (collectSonatype || noArgs) {
await collectSonatypeMetrics(isLocalPersistence);
}
} catch (error) {
console.error(error);
const collectGh = argv["collect-gh"];
const collectNpm = argv["collect-npm"];
const collectSonatype = argv["collect-sonatype"];

const noArgs = !collectGh && !collectNpm && !collectSonatype;

if (collectGh || noArgs) {
await collectGhMetrics(isLocalPersistence);
}
if (collectNpm || noArgs) {
await collectNpmMetrics(isLocalPersistence);
}
if (collectSonatype || noArgs) {
await collectSonatypeMetrics(isLocalPersistence);
}
}

Expand Down

0 comments on commit 023aff8

Please sign in to comment.