refactor(參數): parseIndex 抽到 lib,四支腳本共用
同一段 /^[1-9]\d*$/ 與 BAD_INDEX 已經抄了四份。lib 本來就放著同性質的 parseRepo, 這一支該待在它旁邊。 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -88,6 +88,19 @@ export function parseFlags(argv, spec = {}) {
|
||||
return flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* 驗證議題編號。四支腳本都要做這件事,錯誤碼也該一致。
|
||||
* @param {string|number} value
|
||||
* @param {string} what 出現在錯誤訊息裡的欄位名,例如 '--index'
|
||||
* @returns {number}
|
||||
*/
|
||||
export function parseIndex(value, what = '--index') {
|
||||
if (!/^[1-9]\d*$/.test(String(value))) {
|
||||
throw new ScriptError('BAD_INDEX', `${what} 需為正整數,收到的是 ${value}`);
|
||||
}
|
||||
return Number(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 驗證並正規化 owner/name 形式的 repo。
|
||||
* @param {string} value
|
||||
|
||||
Reference in New Issue
Block a user