[Feature] Skip files without markers on --insert: --skip-no-markers

Đang mở
#96 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
55/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
github, go
Lĩnh vực
cli

Hướng nghiên cứu

Start by reading internal/core/usecase/insertmd and the marker rule in replaceBetweenMarkers, then trace how CLI options reach the insert flow and how tests cover --insert and --stdout. Implementing this requires resolving the stated behavior questions about malformed marker pairs and whether the option implies --insert. Done means skipped files avoid API requests and changes, emit the specified warning, and preserve errors and exit codes for other failures.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

enhancement

Is your feature request related to a problem? Please describe.

--insert cannot run on all markdown files of a directory when only some of them have the
<!--ts--> and <!--te--> markers. Every file without the markers is an error, and the
run exits with 1. Here a.md and c.md have the markers, b.md does not:

$ gh-md-toc --insert --no-backup --hide-footer a.md b.md c.md
...
process "b.md": insert TOC into "b.md": no <!--ts--> / <!--te--> markers found
$ echo $?
1

a.md and c.md are updated, but the exit code fails a script or a CI step. The markers
are checked after the GitHub API request, so a request is spent for every such file too.
The same request for the Bash version is ekalinin/github-markdown-toc#110, and it is
implemented there in ekalinin/github-markdown-toc#199.

Describe the solution you'd like

The same option as in the Bash version: --skip-no-markers skips a local file without the
markers, so this works:

find . -name '*.md' -exec gh-md-toc --insert --no-backup --hide-footer --skip-no-markers {} +

Behavior in the Bash version:

  • A skipped file is not changed, no backup is created for it, no request is sent to the
    GitHub API for it, and stdout has no TOC entries of it.
  • stderr gets <input>: Warning: no <!--ts--> or <!--te--> in the file, skipped, where
    <input> is the input as given on the command line, also with one input.
  • The exit code is 0 when files are only skipped. An error of another input, such as a
    GitHub API error, still exits with 1.
  • A local input that does not exist is not skipped: it is an error as before.
  • --skip-no-markers turns on --insert, as --no-backup and --hide-footer do there.
  • --skip-no-markers with --stdout (#95) is an error before any network call.

Additional context

  • The markers are checked in internal/core/usecase/insertmd after inner.DoAs, that is
    after the API request. The check for this option has to run before it, with the same
    marker rule as replaceBetweenMarkers.
  • Differences from the Bash version to decide on:
    • Here --no-backup requires --insert instead of turning it on. --skip-no-markers
      could follow the same rule.
    • Here a file with several marker pairs, or with <!--te--> before <!--ts-->, is an
      error too. Should it be skipped as well, or stay an error?
Ngôn ngữ chính
Go
Star
525
Fork
89
Merge trung bình
6 phút
Pull request đã merge (30 ngày)
1

Chuẩn bị môi trường

  • Có Dockerfile hoặc tệp Docker Compose
  • Không có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của ekalinin/github-markdown-toc.go

Tất cả issue của ekalinin/github-markdown-toc.go

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.