Skip to content

--mode replace_all is named like "replace entire document" but actually replaces all matches of a selector #809

Description

@Maples7

--mode replace_all is named like "replace entire document" but actually replaces all matches of a selector

Summary

lark-cli docs +update --mode replace_all reads like "replace the whole document". The actual semantics are "replace all occurrences of a --selection-* match, anywhere in the document". The mode that does in fact replace the whole document is overwrite.

The current naming traps almost every first-time user (and especially every AI agent) into picking replace_all for a full-document rewrite, then either:

  • hitting a confusing validation error because --selection-with-ellipsis / --selection-by-title is missing, or
  • if a selector is supplied, having replace_all execute against an unrelated pattern.

This is compounded by #184, which is still open and reports that replace_all against documents containing protected tokens (sheet/image/mention) duplicates the entire document body — meaning a user who reaches for replace_all expecting "overwrite" semantics has a non-trivial chance of corrupting a wiki page. The naming is essentially a footgun.

Repro

A user / agent wanting to overwrite a wiki page tries:

cat new-content.md | lark-cli docs +update \
  --doc "https://my.feishu.cn/wiki/<token>" \
  --mode replace_all \
  --markdown -

Returns a validation error:

--mode replace_all requires --selection-with-ellipsis or --selection-by-title

The user must discover that the correct mode for full-document rewrite is --mode overwrite. There is currently no error hint pointing at overwrite.

Proposal

Two complementary changes:

  1. Rename replace_allreplace_matches (or replace_each / replace_occurrences). Keep replace_all as a deprecated alias for one release with a [deprecated] use replace_matches instead warning. The new name makes it obvious the mode iterates over selector matches and does not act on the whole document.

  2. Improve the validation error so it suggests --mode overwrite for users who likely intended a full rewrite:

    --mode replace_matches requires --selection-with-ellipsis or --selection-by-title.
    If you intended to replace the entire document body, use --mode overwrite instead.
    

Either change alone would help. Both together would close the trap.

Environment

  • lark-cli 1.0.27
  • macOS, Node.js, user mode

Related

  • #184replace_all duplicates documents with protected tokens (compounds the naming hazard).
  • #93--selection-by-title matching, now closed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdomain/docDocs domain

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions