Fix bd-77gm: bd import silently ignores positional arguments
When users forget the -i flag and run 'bd import file.jsonl', the command would silently read from stdin instead of the file, resulting in '0 created, 0 updated' output that was misleading. Root cause: The import command doesn't validate positional arguments, so 'bd import file.jsonl' would be interpreted as 'bd import' with an ignored argument, reading empty stdin. Fix: Add validation at the start of the import command to detect positional arguments and show a helpful error message with the correct syntax. Closes bd-77gm
This commit is contained in:
@@ -36,6 +36,18 @@ Behavior:
|
||||
NOTE: Import requires direct database access and does not work with daemon mode.
|
||||
The command automatically uses --no-daemon when executed.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
// Check for positional arguments (common mistake: bd import file.jsonl instead of bd import -i file.jsonl)
|
||||
if len(args) > 0 {
|
||||
fmt.Fprintf(os.Stderr, "Error: Unexpected argument(s): %v\n\n", args)
|
||||
fmt.Fprintf(os.Stderr, "Did you mean: bd import -i %s\n\n", args[0])
|
||||
fmt.Fprintf(os.Stderr, "The import command does not accept positional arguments.\n")
|
||||
fmt.Fprintf(os.Stderr, "Use the -i flag to specify an input file:\n")
|
||||
fmt.Fprintf(os.Stderr, " bd import -i .beads/beads.jsonl\n\n")
|
||||
fmt.Fprintf(os.Stderr, "Or pipe data via stdin:\n")
|
||||
fmt.Fprintf(os.Stderr, " cat data.jsonl | bd import\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Ensure database directory exists (auto-create if needed)
|
||||
dbDir := filepath.Dir(dbPath)
|
||||
if err := os.MkdirAll(dbDir, 0750); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user