{"record":{"id":"22b4004096c6775b","repo":"sxyazi/yazi","slug":"bin-dir-is-only-valid-for-the-install-task","errorCode":null,"errorMessage":"--bin-dir is only valid for the install task","messagePattern":"--bin-dir is only valid for the install task","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"yazi-build/src/args.rs","lineNumber":30,"sourceCode":"impl Args {\n\tpub(super) fn parse() -> Result<Self> {\n\t\tlet mut args = env::args_os().skip(1);\n\t\tlet task = args.next().unwrap_or_else(|| \"--help\".into());\n\n\t\tlet mut target = String::new();\n\t\tlet mut bin_dir = PathBuf::new();\n\t\twhile let Some(arg) = args.next() {\n\t\t\tmatch arg.to_str() {\n\t\t\t\tSome(\"--target\") => target = Self::target(&mut args)?,\n\t\t\t\tSome(\"--bin-dir\") => bin_dir = Self::value(&mut args, \"--bin-dir\")?.into(),\n\t\t\t\tSome(\"--help\") => return Ok(Self::Help),\n\t\t\t\t_ => bail!(\"unknown option: {}\", arg.display()),\n\t\t\t}\n\t\t}\n\n\t\tmatch task.to_str() {\n\t\t\tSome(\"build\") => {\n\t\t\t\tensure!(bin_dir.as_os_str().is_empty(), \"--bin-dir is only valid for the install task\");\n\t\t\t\tOk(Self::Build(target))\n\t\t\t}\n\t\t\tSome(\"dist\") => {\n\t\t\t\tensure!(!target.is_empty(), \"the dist task requires --target\");\n\t\t\t\tensure!(bin_dir.as_os_str().is_empty(), \"--bin-dir is only valid for the install task\");\n\t\t\t\tOk(Self::Dest(target))\n\t\t\t}\n\t\t\tSome(\"install\") => {\n\t\t\t\tensure!(target.is_empty(), \"--target is not valid for the install task\");\n\t\t\t\tOk(Self::Install(bin_dir))\n\t\t\t}\n\t\t\tSome(\"--help\") => Ok(Self::Help),\n\t\t\t_ => bail!(\"unknown task: {}\", task.display()),\n\t\t}\n\t}\n\n\tfn value(args: &mut impl Iterator<Item = OsString>, option: &str) -> Result<OsString> {\n\t\targs.next().with_context(|| format!(\"missing value for {option}\"))","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/sxyazi/yazi/blob/5f901b886b14de1f17460b6e52e9de5d67f8aba9/yazi-build/src/args.rs#L12-L48","documentation":"yazi-build's argument parser rejects the `--bin-dir` flag whenever the chosen task is not `install` — for the `build` task it's meaningless since no binaries are placed into a bin directory. `ensure!` turns the violation into this anyhow error.","triggerScenarios":"Running `ya-build build --bin-dir <path>` — the parser matches task \"build\" and finds `bin_dir` non-empty.","commonSituations":"Copy-pasting an install command line and changing only the task word to `build`; scripted builds sharing a flag matrix across tasks.","solutions":["Remove `--bin-dir` when invoking the build task","Use the `install` task if you want binaries placed in a bin dir","If you need a custom output location for build, check if `--target` or env vars like CARGO_TARGET_DIR apply"],"exampleFix":"// before\nya-build build --bin-dir ~/.local/bin\n// after\nya-build install --bin-dir ~/.local/bin","handlingStrategy":"validation","validationCode":"if task == \"build\" && args.contains(\"--bin-dir\") {\n    eprintln!(\"--bin-dir requires the install task\");\n    std::process::exit(2);\n}","typeGuard":null,"tryCatchPattern":"match parse_result {\n    Err(e) if e.to_string().contains(\"--bin-dir is only valid for the install task\") => {\n        eprintln!(\"usage: ya-build install --bin-dir <path>\");\n    }\n    other => other,\n}","preventionTips":["Only pass --bin-dir with the install task","Don't share one flag matrix across build/dist/install invocations","Check `ya-build --help` for per-task flags"],"tags":["cli","argument-validation","build"],"backgroundTag":"invalid-cli-argument","analyzedSha":"5f901b886b14de1f17460b6e52e9de5d67f8aba9","analyzedAt":"2026-09-02T18:38:25.566Z","contentChangedAt":"2026-09-02T18:38:25.566Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}