fix: unknown --option is not treated as a package (install/remove)

/  previously fell through to treat the
flag as a package name (looking it up in the registry / ). Now a
bare leading dash is rejected as an unknown command:
- install: when no package token was collected and argv[2] starts with '-',
  report unknown command instead of pushing the flag onto the package list.
- remove: a leading '-' arg is rejected before pdm_remove.

Verified: install/remove --gits report unknown command; --gitea/<known git
dispatches and usage errors are unaffected.
这个提交包含在:
JGZYES
2026-09-05 10:07:14 +08:00
父节点 8d934d73c9
当前提交 80f5b86396
+9 -1
查看文件
@@ -1079,6 +1079,7 @@ int main(int argc, char **argv) {
/* pmm remove <pkg> (also used by the Windows "Uninstall" registration) */ /* pmm remove <pkg> (also used by the Windows "Uninstall" registration) */
if (strcmp(argv[1], "remove") == 0) { if (strcmp(argv[1], "remove") == 0) {
if (argc < 3) { pmm_error("%s", pmm_tr("msg.err.usage")); return 1; } if (argc < 3) { pmm_error("%s", pmm_tr("msg.err.usage")); return 1; }
if (argv[2][0] == '-') { pmm_error("%s", pmm_tr_fmt("msg.err.unknown-cmd", argv[2])); return 1; }
return pdm_remove(argv[2]) == 0 ? 0 : 1; return pdm_remove(argv[2]) == 0 ? 0 : 1;
} }
/* pmm self-update: install the latest 'pmm' tool package (auto os+arch) */ /* pmm self-update: install the latest 'pmm' tool package (auto os+arch) */
@@ -1134,7 +1135,14 @@ int main(int argc, char **argv) {
if (strncmp(a, "--version=", 10) == 0) { version = a + 10; continue; } if (strncmp(a, "--version=", 10) == 0) { version = a + 10; continue; }
if (a[0] != '-' && ni < 64) items[ni++] = a; if (a[0] != '-' && ni < 64) items[ni++] = a;
} }
if (ni == 0) items[ni++] = argv[2]; if (ni == 0) {
/* A bare leading option (e.g. `install --gits`) is not a package; report
* an unknown command instead of treating the flag as a name. */
if (argv[2][0] == '-')
pmm_error("%s", pmm_tr_fmt("msg.err.unknown-cmd", argv[2]));
else items[ni++] = argv[2];
if (ni == 0) return 1;
}
PmmConfig cfg; MirrorSel mirror; PmmConfig cfg; MirrorSel mirror;
load_config(&cfg); load_config(&cfg);