Skip to content

cheat --init should comment out community cheatpath by default #773

@chrisallenlane

Description

@chrisallenlane

Problem

cheat --init outputs a config template with an active community cheatpath pointing at a directory that doesn't exist:

  - name: community
    path: /home/user/.config/cheat/cheatsheets/community
    tags: [ community ]
    readonly: true

If users follow the documented workflow (mkdir -p ~/.config/cheat && cheat --init > ~/.config/cheat/conf.yml) without also cloning the community cheatsheets, the next run of cheat produces a warning:

WARNING: cheatpath '/home/user/.config/cheat/cheatsheets/community' does not exist, skipping

(Prior to v4.5.0 this was a fatal error, not a warning — see #721, #730, #771.)

The installer path (triggered on first run when no config exists) already handles this correctly: it prompts the user about community cheatsheets and comments out the cheatpath if they decline. But --init doesn't prompt — it always outputs the community cheatpath as active.

Proposed solution

Comment out the community cheatpath in --init output by default, with a YAML comment explaining how to enable it:

  # To use community cheatsheets, clone them and uncomment the path below:
  #   git clone https://github.com/cheat/cheatsheets.git /path/to/community
  #- name: community
  #  path: /home/user/.config/cheat/cheatsheets/community
  #  tags: [ community ]
  #  readonly: true

This makes --init produce a config that works out of the box without warnings, while still documenting how to enable community cheatsheets. It matches the behavior of the installer when the user declines community cheatsheets.

Why not make --init interactive?

--init is designed to output to stdout (cheat --init > conf.yml), so adding interactive prompts would mix prompt text into the config file unless carefully separated via stderr. Commenting out the community path by default is simpler and avoids this issue. Users who want the full interactive experience already have it via the first-run installer.

Affected code

  • cmd/cheat/cmd_init.go — the only file that needs to change
  • cmd/cheat/config.go — the template string (community section needs comment markers)

Acceptance criteria

  • cheat --init > conf.yml produces a config with community cheatpath commented out
  • The commented-out section includes instructions for enabling it (clone URL)
  • cheat --init output, when saved as a config file, loads without warnings on subsequent runs
  • Existing integration test (TestFirstRunIntegration) continues to pass
  • Add a test that verifies --init output doesn't contain active community cheatpath

Related issues

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions