{"id":"8e8d59a3c24b9bb9","repo":"rust-lang/cargo","slug":"package-spec-requires-a-spec-format-value-r","errorCode":null,"errorMessage":"\"--package <SPEC>\" requires a SPEC format value.\nRun `cargo help pkgid` for more information about SPEC format.","messagePattern":"\"--package <SPEC>\" requires a SPEC format value\\.\nRun `cargo help pkgid` for more information about SPEC format\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/bin/cargo/commands/uninstall.rs","lineNumber":38,"sourceCode":"        .arg_silent_suggestion()\n        .arg_package_spec_simple(\n            \"Package to uninstall\",\n            ArgValueCandidates::new(get_installed_package_candidates),\n        )\n        .arg(\n            multi_opt(\"bin\", \"NAME\", \"Only uninstall the binary NAME\")\n                .help_heading(heading::TARGET_SELECTION),\n        )\n        .after_help(color_print::cstr!(\n            \"Run `<bright-cyan,bold>cargo help uninstall</>` for more detailed information.\\n\"\n        ))\n}\n\npub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {\n    let root = args.get_one::<String>(\"root\").map(String::as_str);\n\n    if args.is_present_with_zero_values(\"package\") {\n        return Err(anyhow::anyhow!(\n            \"\\\"--package <SPEC>\\\" requires a SPEC format value.\\n\\\n            Run `cargo help pkgid` for more information about SPEC format.\"\n        )\n        .into());\n    }\n\n    let specs = args\n        .get_many::<String>(\"spec\")\n        .unwrap_or_else(|| args.get_many::<String>(\"package\").unwrap_or_default())\n        .map(String::as_str)\n        .collect();\n    ops::uninstall(root, specs, &values(args, \"bin\"), gctx)?;\n    Ok(())\n}\n\nfn get_installed_crates() -> Vec<clap_complete::CompletionCandidate> {\n    get_installed_crates_().unwrap_or_default()\n}","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/bin/cargo/commands/uninstall.rs#L20-L56","documentation":"In `cargo uninstall` (uninstall.rs:37-43), `is_present_with_zero_values(\"package\")` is true when the user passes `--package` (or `-p`) with no value. Because `--package <SPEC>` requires a SPEC, Cargo bails and points to `cargo help pkgid` for the accepted spec grammar.","triggerScenarios":"Running `cargo uninstall --package` with no argument, or `cargo uninstall -p` followed by nothing.","commonSituations":"Shell quoting bug that swallowed the package name; copy-pasting a command missing the trailing spec; expecting `-p` to act as a flag rather than an option.","solutions":["Provide a SPEC value: `cargo uninstall -p my-crate`.","Use a full spec if needed: `cargo uninstall -p my-crate@1.2.3` (see `cargo help pkgid`).","Drop `-p` entirely to uninstall by positional name: `cargo uninstall my-crate`."],"exampleFix":"// before\n$ cargo uninstall -p\nerror: \"--package <SPEC>\" requires a SPEC format value.\n\n// after\n$ cargo uninstall -p my-crate","handlingStrategy":"validation","validationCode":"if package_flag_present && package_value.is_none() {\n    return Err(\"--package requires a SPEC; see `cargo help pkgid`\");\n}","typeGuard":"fn has_package_spec(p: Option<&str>) -> bool {\n    p.map(|s| !s.trim().is_empty()).unwrap_or(false)\n}\n","tryCatchPattern":null,"preventionTips":["Always pass a value with -p/--package; never leave it dangling.","In scripts, assert $1 is non-empty before forwarding to `cargo uninstall -p`."],"tags":["cargo","uninstall","cli","argument","package-spec"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}