(global: boolean, value: string | boolean)
| 43 | * @param value Either a user ID, true to generate a new User ID, or false to disable analytics. |
| 44 | */ |
| 45 | export async function setAnalyticsConfig(global: boolean, value: string | boolean): Promise<void> { |
| 46 | const level = global ? 'global' : 'local'; |
| 47 | const workspace = await getWorkspace(level); |
| 48 | if (!workspace) { |
| 49 | throw new Error(`Could not find ${level} workspace.`); |
| 50 | } |
| 51 | |
| 52 | const cli = (workspace.extensions['cli'] ??= {}); |
| 53 | if (!workspace || !json.isJsonObject(cli)) { |
| 54 | throw new Error(`Invalid config found at ${workspace.filePath}. CLI should be an object.`); |
| 55 | } |
| 56 | |
| 57 | cli.analytics = value === true ? randomUUID() : value; |
| 58 | await workspace.save(); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Prompt the user for usage gathering permission. |
no test coverage detected