Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ argent init
| `argent enable` | Enable a predefined feature flag (`--scope project` for project-local) |
| `argent disable` | Disable a feature flag (`--scope project` for project-local) |
| `argent flags` | List available feature flags and their state |
| `argent telemetry` | Manage anonymous telemetry: `status` / `enable` / `disable` |

## Supported Editors

Expand Down
103 changes: 103 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/argent-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"typecheck:tests": "tsc --noEmit -p tsconfig.test.json"
},
"dependencies": {
"@argent/telemetry": "file:../telemetry",
"@argent/tools-client": "file:../argent-tools-client",
"@clack/prompts": "^1.1.0",
"picocolors": "^1.1.1"
Expand Down
1 change: 1 addition & 0 deletions packages/argent-cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ export {
type FlagScope,
type FlagDefinition,
} from "./flags.js";
export { telemetry } from "./telemetry.js";
86 changes: 86 additions & 0 deletions packages/argent-cli/src/telemetry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import pc from "picocolors";
import {
init as telemetryInit,
isEnabled as telemetryIsEnabled,
markDisabled,
markEnabled,
shutdown as telemetryShutdown,
status as telemetryStatus,
} from "@argent/telemetry";

// Consent-management subcommands for anonymous telemetry.
export async function telemetry(args: string[]): Promise<void> {
const sub = args[0];
telemetryInit("cli");

switch (sub) {
case undefined:
printUsage();
await telemetryShutdown();
return;
case "status":
printStatus();
await telemetryShutdown();
return;
case "enable":
await cmdEnable();
return;
case "disable":
await cmdDisable();
return;
case "--help":
case "-h":
printUsage();
await telemetryShutdown();
return;
default:
console.error(`Unknown subcommand: telemetry ${sub}`);
await telemetryShutdown();
process.exit(1);
}
}

function printUsage(): void {
console.log(`Usage:
argent telemetry status Show telemetry state and anonymous id
argent telemetry enable Enable telemetry
argent telemetry disable Disable telemetry
`);
}

function printStatus(): void {
const s = telemetryStatus();

const anonLabel = s.anonIdPrefix
? `${s.anonIdPrefix}...`
: s.hasAnonIdOnDisk
? "present"
: "not created";

console.log("telemetry:");
console.log(` state: ${s.enabled ? "enabled" : "disabled"}`);
console.log(` anon id: ${anonLabel}`);
}

async function cmdEnable(): Promise<void> {
const wasEnabled = telemetryIsEnabled();
markEnabled();
if (wasEnabled) {
console.log(pc.dim("Telemetry was already enabled."));
} else {
console.log(pc.green("Telemetry enabled."));
}
await telemetryShutdown();
}

async function cmdDisable(): Promise<void> {
const wasEnabled = telemetryIsEnabled();
if (!wasEnabled) {
console.log(pc.dim("Telemetry was already disabled."));
await telemetryShutdown();
return;
}
await markDisabled();
console.log(pc.red("Telemetry disabled."));
await telemetryShutdown();
}
1 change: 1 addition & 0 deletions packages/argent-installer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"typecheck:tests": "tsc --noEmit -p tsconfig.test.json"
},
"dependencies": {
"@argent/telemetry": "file:../telemetry",
"@argent/tools-client": "file:../argent-tools-client",
"@argent/update-core": "file:../update-core",
"@clack/prompts": "^1.4.0",
Expand Down
Loading