Telemetry

A simple pre-configured --telemetry/--no-telemetry option flag, that is respecting the proposed DO_NOT_TRACK environment variable as a unified standard to opt-out of telemetry for TUI/console apps.

It does nothing else.

from click_extra import command, context, echo, pass_context, telemetry_option

@command
@telemetry_option
@pass_context
def orchard(ctx):
    """Count the apple trees."""
    echo(f"Telemetry: {context.get(ctx, context.TELEMETRY)}")

DO_NOT_TRACK precedence

A truthy DO_NOT_TRACK turns telemetry off. Most specific first:

  1. --telemetry or --no-telemetry on the command line;

  2. DO_NOT_TRACK in the environment;

  3. <CLI>_TELEMETRY in the environment;

  4. telemetry in the CLI’s configuration file;

  5. the built-in default, off.

This ranks DO_NOT_TRACK above the variable of the option and above the configuration file, where the other machine-wide variables, like CLICK_EXTRA_THEME, rank below both. DO_NOT_TRACK is a consumer-protection opt-out: a user exports it once to refuse tracking from every tool, and a configuration file a project ships, or a variable a wrapper sets, must not opt that user back in. Only the command line, which the user types, outranks it:

$ orchard
Telemetry: False
$ orchard --telemetry
Telemetry: True