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

オープン
#96 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
55/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
github, go
領域
cli

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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?
主要言語
Go
スター
525
フォーク
89
平均マージ
6分
マージ済み PR(30日)
1

環境構築

  • Dockerfile または Docker Compose ファイルあり
  • プルリクエストのテンプレートなし
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

ekalinin/github-markdown-toc.go のほかの issue

ekalinin/github-markdown-toc.go の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。