Answer architecture round 5, stability round 4 and product-owner round 4: an argument that is a lone reference is echoed back, and a hint for a template holding a backslash pipes it through printf

This commit is contained in:
2026-10-07 21:47:27 +02:00
committed by Lillem4n
parent 75184b44cb
commit 3e932d5e5f
2 changed files with 16 additions and 4 deletions
+14 -3
View File
@@ -292,10 +292,12 @@ func operandError(arg string) error {
return fmt.Errorf("%s; read a file from stdin: fejkdata < %s", unexpected, shellQuoted(arg))
}
example := pipeHint
if inline, err := fejkdata.IsTemplate(arg); inline {
example = "echo " + shellQuoted(arg) + " | fejkdata"
if _, lone := loneReference(arg); lone {
example = piped(arg)
} else if inline, err := fejkdata.IsTemplate(arg); inline {
example = piped(arg)
} else if _, lone := loneReference("{/" + arg + "}"); lone && err == nil {
example = "echo " + shellQuoted("{/"+arg+"}") + " | fejkdata"
example = piped("{/" + arg + "}")
}
return fmt.Errorf("%s; the template is read from stdin: %s", unexpected, example)
}
@@ -492,6 +494,15 @@ func spacedReference(template string, err error) error {
return err
}
// piped is the command piping template to fejkdata; some shells' echo reads a backslash
// as an escape, so a template holding one goes through printf.
func piped(template string) string {
if strings.ContainsRune(template, '\\') {
return "printf '%s' " + shellQuoted(template) + " | fejkdata"
}
return "echo " + shellQuoted(template) + " | fejkdata"
}
// shellQuoted is s as a shell reads it back: bare where it holds nothing a shell expands.
func shellQuoted(s string) string {
if s != "" && !strings.ContainsAny(s, " \t\r\n'\"$`\\*?[]{}()<>|&;#~!") {