Per-flag behaviour is spread over seven name-keyed maps with one guard test

オープン 初心者向け
#402 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

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

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
75/100
issue の種類
リファクタリング
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
go

調査の方向性

internal/cli/config.go、internal/cli/resume.go、internal/cli/completion.go のフラグマップを読み、既存のガードである internal/cli/config_test.go:318-328 を確認してください。各指定フラグが登録されていることと、pacingFlags が IsBoolFlag と一致することを確認するチェックを追加し、go test ./internal/cli/ を実行してください。完了条件は、ガードが列挙されたすべてのマップを対象とし、bool の重複定義が削除されていることです。

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

説明

area: cli severity: medium tech-debt

Summary

What each CLI flag does in config files, env vars, resume and shell completion is spread over seven maps keyed by flag name, in three files. Only one of the maps has a test that its keys are real flags, so a misspelled or stale name in any of the others silently does nothing.

Where

  • internal/cli/config.go:39, 43, 49 (noDefaultFlags, listFlags, repeatFlags)
  • internal/cli/resume.go:219, 225-228 (unsavedSettings, pacingFlags)
  • internal/cli/completion.go:23-26, 34-37 (fileFlags, valueChoices)
  • internal/cli/config_test.go:318-328 (the only name-validity guard, for fileFlags)

Details

Each of these is a map[string]bool (or similar) keyed by the flag's name. The bool value in pacingFlags restates whether the flag is boolean, which completion.go:52 already derives from IsBoolFlag.

Impact

Each new flag means deciding from memory whether it belongs in up to seven maps:

  • missing from pacingFlags: -resume refuses the flag
  • missing from unsavedSettings: resume refuses a harmless difference
  • a mode flag missing from noDefaultFlags: it becomes settable from SUBENUM_* env

Renaming a flag leaves dead keys behind, with no test failure.

Suggested fix

Each step leaves the code working:

  1. Add a test that every key of noDefaultFlags, listFlags, repeatFlags, unsavedSettings, pacingFlags and valueChoices is a registered flag (copy the second loop of config_test.go:326), and that pacingFlags' bool equals the flag's IsBoolFlag. This alone catches renames and can ship on its own.
  2. Make pacingFlags a set and read IsBoolFlag from the FlagSet at resume.go:337.
  3. Optional: one flagTraits table in one file, with the seven maps as thin accessors, migrating one map per commit.

Tests to have in place first: the resume tests for pacing flags, the config-file list/repeat tests, the completion output tests, and the new test from step 1.

Acceptance criteria

  • A test fails when any trait map names a flag that is not registered
  • pacingFlags no longer duplicates IsBoolFlag

Getting started

  • Relevant files: internal/cli/config.go, internal/cli/resume.go, internal/cli/completion.go, internal/cli/config_test.go
  • How to run tests: go test ./internal/cli/

Filed by repo-audit/full-audit at dd5b156. Severity: medium. Effort: S (steps 1-2), M (step 3). audit-key: tech-debt|internal/cli/config.go|noDefaultFlags

主要言語
Go
スター
1
フォーク
1
平均マージ
7時間 18分
マージ済み PR(30日)
23

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

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

TMHSDigital/subenum のほかの issue

TMHSDigital/subenum の issue をすべて見る

似ている issue

Go の issue をもっと見る

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

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