Make great documentation goal 1.2, and plan the README's reorganisation and the nested-template gaps #33

Open
lilleman wants to merge 966 commits from worktree-todo-relative-dates-exact-counts into main
2 changed files with 16 additions and 4 deletions
Showing only changes of commit 3e932d5e5f - Show all commits
+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)) return fmt.Errorf("%s; read a file from stdin: fejkdata < %s", unexpected, shellQuoted(arg))
} }
example := pipeHint example := pipeHint
if inline, err := fejkdata.IsTemplate(arg); inline { if _, lone := loneReference(arg); lone {
example = "echo " + shellQuoted(arg) + " | fejkdata" example = piped(arg)
} else if inline, err := fejkdata.IsTemplate(arg); inline {
example = piped(arg)
} else if _, lone := loneReference("{/" + arg + "}"); lone && err == nil { } 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) 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 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. // shellQuoted is s as a shell reads it back: bare where it holds nothing a shell expands.
func shellQuoted(s string) string { func shellQuoted(s string) string {
if s != "" && !strings.ContainsAny(s, " \t\r\n'\"$`\\*?[]{}()<>|&;#~!") { if s != "" && !strings.ContainsAny(s, " \t\r\n'\"$`\\*?[]{}()<>|&;#~!") {
+2 -1
View File
@@ -249,10 +249,11 @@ func TestRunTakesNoOperand(t *testing.T) {
want string want string
}{ }{
{[]string{"sv_SE.person"}, "echo '{/sv_SE.person}' | fejkdata"}, {[]string{"sv_SE.person"}, "echo '{/sv_SE.person}' | fejkdata"},
{[]string{"{/sv_SE.person}"}, "echo '{/sv_SE.person}' | fejkdata"}, {[]string{"{/en_US.person}"}, "echo '{/en_US.person}' | fejkdata"},
{[]string{"name: {/sv_SE.person.last}"}, "echo 'name: {/sv_SE.person.last}' | fejkdata"}, {[]string{"name: {/sv_SE.person.last}"}, "echo 'name: {/sv_SE.person.last}' | fejkdata"},
{[]string{"geo.US.locality[O'Fallon].name"}, `echo '{/geo.US.locality[O'\''Fallon].name}' | fejkdata`}, {[]string{"geo.US.locality[O'Fallon].name"}, `echo '{/geo.US.locality[O'\''Fallon].name}' | fejkdata`},
{[]string{"en_US.address"}, "echo '{/en_US.address}' | fejkdata"}, {[]string{"en_US.address"}, "echo '{/en_US.address}' | fejkdata"},
{[]string{`C:\temp {/sv_SE.person}`}, `printf '%s' 'C:\temp {/sv_SE.person}' | fejkdata`},
{[]string{"-"}, "drop it"}, {[]string{"-"}, "drop it"},
{[]string{file}, "fejkdata < " + file}, {[]string{file}, "fejkdata < " + file},
} { } {