Export ErrNoColumns, name the cure for a shell-split template and an unquoted record, and name the flag a missing data path came from

This commit is contained in:
2026-09-18 20:35:56 +02:00
parent 9db8d35a49
commit c8a4ffa764
5 changed files with 22 additions and 8 deletions
+15 -1
View File
@@ -282,7 +282,7 @@ func (in invocation) check() (argKind, error) {
return argPath, nil
}
if len(in.paths) != 1 {
return argPath, fmt.Errorf("expected one path or template, got %d", len(in.paths))
return argPath, fmt.Errorf("expected one path or template, got %d%s", len(in.paths), templateSplit(in.paths))
}
return classify(in.paths[0])
}
@@ -478,11 +478,25 @@ func run(args []string, stdout, stderr io.Writer) int {
return misuse(stderr, te.error)
}
fmt.Fprintln(stderr, err)
if errors.Is(err, fejkdata.ErrNoColumns) {
fmt.Fprintln(stderr, "wrap that JSON in single quotes, which keep a shell from expanding its braces")
}
return 1
}
return 0
}
// templateSplit names the cure for a template a shell split on its spaces, which is
// what several arguments carrying a token mean.
func templateSplit(paths []string) string {
for _, p := range paths {
if strings.Contains(p, "{") {
return `; a template's spaces split the argument, so wrap the whole argument in "…"`
}
}
return ""
}
func misuse(stderr io.Writer, err error) int {
// A library error already names the program, so the prefix is not doubled.
fmt.Fprintf(stderr, "fejkdata: %s\ntry 'fejkdata --help'\n", strings.TrimPrefix(err.Error(), "fejkdata: "))