{"record":{"id":"050f45c60679baf8","repo":"jdx/mise","slug":"source-can-only-be-used-with-one-target","errorCode":null,"errorMessage":"--source can only be used with one target","messagePattern":"--source can only be used with one target","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cli/dotfiles/add.rs","lineNumber":104,"sourceCode":"    pub(super) prompt_secrets: bool,\n}\n\nimpl DotfilesAdd {\n    /// Validate and capture the requested targets as one transactional update.\n    pub(crate) async fn run(self) -> Result<()> {\n        let mode = self.validate()?;\n        OperationScope::wrap(\"bootstrap dotfiles add\", self.dry_run, self.run_inner(mode)).await\n    }\n\n    fn validate(&self) -> Result<FileMode> {\n        if self.changed && !self.targets.is_empty() {\n            bail!(\"--changed does not accept target arguments\");\n        }\n        if !self.changed && self.targets.is_empty() {\n            bail!(\"at least one target or --changed is required\");\n        }\n        if self.source.is_some() && self.targets.len() != 1 {\n            bail!(\"--source can only be used with one target\");\n        }\n        match self.mode.as_deref() {\n            Some(\"track\") => bail!(\n                \"`--mode track` tracks a file where it is and takes no source; use `mise dot track <path>`\"\n            ),\n            Some(mode) => {\n                FileMode::parse(mode).ok_or_else(|| eyre::eyre!(\"unknown dotfile mode: {mode}\"))\n            }\n            None => Ok(system::files::default_mode()),\n        }\n    }\n\n    async fn run_inner(mut self, mode: FileMode) -> Result<()> {\n        let config = Config::get().await?;\n        let secrets = system::secrets::resolve(&config, self.prompt_secrets)?;\n        let managed = system::files::files_from_config(&config)?;\n        if self.changed {\n            for req in &managed {","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/cli/dotfiles/add.rs#L86-L122","documentation":"The `--source` flag for `mise dotfiles add` specifies where to link a target from, and only makes sense for exactly one target. validate() bails when `--source` is given together with zero or multiple targets, since the single source cannot be applied unambiguously to several targets.","triggerScenarios":"Running `mise dotfiles add --source <path> <t1> <t2>` (multiple targets) or `mise dotfiles add --source <path> --changed` (no targets) — source.is_some() && targets.len() != 1 in validate().","commonSituations":"Trying to batch-link several dotfiles from one source path in a single command; scripting a loop that accumulates multiple targets while keeping a single --source flag.","solutions":["Run one `mise dotfiles add --source <path> <single-target>` per file.","If linking multiple files from a directory, add each target separately with its own --source.","Omit --source if you intended to track files in place (track mode infers no source)."],"exampleFix":"// before\n$ mise dotfiles add --source ~/dotfiles/zshrc ~/.zshrc ~/.bashrc\n\n// after\n$ mise dotfiles add --source ~/dotfiles/zshrc ~/.zshrc\n$ mise dotfiles add --source ~/dotfiles/bashrc ~/.bashrc","handlingStrategy":"validation","validationCode":"# guard: --source requires exactly one target\nif [ -n \"$SOURCE\" ] && [ $# -ne 1 ]; then\n  echo \"--source works with exactly one target\" >&2; exit 2\nfi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Loop over targets in scripts, calling add with --source once per file.","Treat --source as a single-target option.","Omit --source for in-place tracking use cases."],"tags":["dotfiles","cli","validation","flags"],"backgroundTag":"mutually-exclusive-options","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}