jackwener/OpenCLI · warning · ArgumentError
--period is only valid with --view top
Error message
--period is only valid with --view top
What it means
resolveFeedRequest converts CLI flags into a linux.do feed URL. The --period flag is only meaningful for the 'top' view, which selects a time window (e.g. daily/weekly/monthly); for other views (latest, new, etc.) period makes no sense, so the library rejects the combination up front with an ArgumentError rather than silently ignoring the flag.
Source
Thrown at clis/linux-do/feed.js:264
throw new ArgumentError(`Unknown tag: ${value}`, 'Use "opencli linux-do tags" to list available tags');
}
/**
* 解析分类,并补齐父分类信息。
*/
async function resolveCategory(page, value) {
const liveCategory = findMatchingCategory(await fetchLiveCategories(page), value);
if (liveCategory)
return liveCategory;
throw new ArgumentError(`Unknown category: ${value}`, 'Use "opencli linux-do categories" to list available categories');
}
/**
* 将命令参数转换为最终请求地址
*/
async function resolveFeedRequest(page, kwargs) {
const view = (kwargs.view || 'latest');
const period = (kwargs.period || 'weekly');
if (kwargs.period && view !== 'top') {
throw new ArgumentError('--period is only valid with --view top');
}
const params = new URLSearchParams();
if (kwargs.order && kwargs.order !== 'default')
params.set('order', kwargs.order);
if (kwargs.ascending)
params.set('ascending', 'true');
if (kwargs.limit)
params.set('per_page', String(kwargs.limit));
const tagValue = typeof kwargs.tag === 'string' ? kwargs.tag.trim() : '';
const categoryValue = typeof kwargs.category === 'string' ? kwargs.category.trim() : '';
if (!tagValue && !categoryValue) {
const query = new URLSearchParams(params);
if (view === 'top')
query.set('period', period);
const jsonSuffix = query.toString() ? `?${query.toString()}` : '';
return {
url: `${view === 'latest' ? '/latest.json' : view === 'hot' ? '/hot.json' : '/top.json'}${jsonSuffix}`,
};View on GitHub (pinned to 49907e53dc)
Solutions
- Add `--view top` alongside `--period <value>`.
- Drop the `--period` flag if a non-top view is intended.
- Validate in the caller that view === 'top' whenever period is provided.
Example fix
// before cli --site linux-do --name feed --period monthly // after cli --site linux-do --name feed --view top --period monthly
Defensive patterns
Strategy: validation
Validate before calling
if (args.period && (args.view ?? 'latest') !== 'top') {
throw new Error('--period is only valid with --view top');
} Type guard
const isTopView = (v) => v === 'top';
Try / catch
try {
await request(page, kwargs);
} catch (e) {
if (e.name === 'ArgumentError' && /--period/.test(e.message)) {
console.error('Add --view top when using --period.');
} else throw e;
} Prevention
- Pair --period only with --view top
- Add pre-flight flag validation in wrapper scripts
- Read `--help` for view/period coupling
When it happens
Trigger: Calling the feed command (or request() which calls resolveFeedRequest) with kwargs.period set while kwargs.view is absent or anything other than 'top' — e.g. `--period monthly` alone, or `--view latest --period daily`.
Common situations: Users copying a 'top period' example but forgetting `--view top`; scripts defaulting view to 'latest'; help text that does not make the coupling obvious.
Related errors
- At least one of --json or --text must be enabled
- <train-no> "${trainNo}" does not look like a 12306 internal
- --from station must not be empty
- --to station must not be empty
- --seat-types must contain only 12306 seat letters/digits (A-
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/e36a774983e8da8d.
Report an issue: GitHub.