{"record":{"id":"5c3606d2cf7a5f35","repo":"joewalnes/websocketd","slug":"ambiguous-provided-command-and-dir-argument-pl","errorCode":null,"errorMessage":"ambiguous: provided COMMAND and --dir argument, please only specify one","messagePattern":"ambiguous: provided COMMAND and --dir argument, please only specify one","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"config.go","lineNumber":201,"sourceCode":"\tfor _, key := range strings.Split(passenv, \",\") {\n\t\tif key == \"HTTPS\" {\n\t\t\tcontinue\n\t\t}\n\t\tif v := os.Getenv(key); v != \"\" {\n\t\t\tif clean := strings.TrimSpace(newlineCleaner.Replace(v)); clean != \"\" {\n\t\t\t\tenv = append(env, fmt.Sprintf(\"%s=%s\", key, clean))\n\t\t\t}\n\t\t}\n\t}\n\treturn env\n}\n\n// resolveCommand validates and resolves the command to execute.\n// Returns the resolved command path and arguments.\nfunc resolveCommand(args []string, scriptDir string) (commandName string, commandArgs []string, err error) {\n\tif len(args) > 0 {\n\t\tif scriptDir != \"\" {\n\t\t\treturn \"\", nil, fmt.Errorf(\"ambiguous: provided COMMAND and --dir argument, please only specify one\")\n\t\t}\n\t\tpath, lookErr := exec.LookPath(args[0])\n\t\tif lookErr != nil {\n\t\t\treturn \"\", nil, fmt.Errorf(\"unable to locate specified COMMAND '%s' in OS path\", args[0])\n\t\t}\n\t\treturn path, args[1:], nil\n\t}\n\treturn \"\", nil, nil\n}\n\n// resolveScriptDir validates and resolves the script directory path.\nfunc resolveScriptDir(dir string) (string, error) {\n\tif dir == \"\" {\n\t\treturn \"\", nil\n\t}\n\tabsDir, err := filepath.Abs(dir)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"could not resolve absolute path to dir '%s'\", dir)","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/joewalnes/websocketd/blob/7a8683dc7f9778dc615945aaed2a8dc77290227b/config.go#L183-L219","documentation":"resolveCommand rejects a command line that specifies both a COMMAND argument and the --dir flag, because the two are mutually exclusive ways to tell websocketd what to run. COMMAND launches a single executable; --dir serves every script in a directory. Specifying both would make the launch target ambiguous, so the CLI fails fast at config-parse time.","triggerScenarios":"Running e.g. `websocketd --dir=./scripts ./scripts/count.sh` — resolveCommand sees len(args)>0 AND scriptDir!=\"\" and returns this error before anything is executed.","commonSituations":"Copy-pasting an example that uses --dir and appending a script path out of habit; migrating from single-script usage to directory mode (or the reverse) and forgetting to drop the other flag; shell wrapper scripts that always pass --dir while also forwarding a command.","solutions":["Remove the --dir flag if you want to run the single COMMAND","Remove the trailing COMMAND arguments and keep --dir to serve all scripts in that directory","If a wrapper always injects --dir, set it conditionally only when no COMMAND is given"],"exampleFix":"// before\nwebsocketd --dir=./scripts ./scripts/count.sh\n// after\nwebsocketd --dir=./scripts   # serve the whole directory\n# or\nwebsocketd ./scripts/count.sh  # run one command","handlingStrategy":"validation","validationCode":"args, err := parseFlags(os.Args)\nif err != nil {\n\tlog.Fatal(err)\n}\nif flags.Dir != \"\" && len(args) > 0 {\n\tlog.Fatal(\"pass either COMMAND or --dir, not both\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Decide the mode up front: single command (positional arg) or directory mode (--dir) — never both","In wrapper scripts, pass --dir only when no positional command is forwarded","Add a shell alias/function that asserts exactly one mode before invoking websocketd"],"tags":["cli","configuration","flag-conflict"],"backgroundTag":"ambiguous-command-and-dir-flag","analyzedSha":"7a8683dc7f9778dc615945aaed2a8dc77290227b","analyzedAt":"2026-09-03T13:52:22.309Z","contentChangedAt":"2026-09-03T13:52:22.309Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}