From ce7bb43b8e0910c812c8ab9299969679082507b9 Mon Sep 17 00:00:00 2001 From: JP Appel Date: Sat, 19 Jul 2025 00:54:11 -0400 Subject: Improve command documentation and query output Add flags to change document and list separator in query output. Simplified cutom output format handling. --- cmd/query.go | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) (limited to 'cmd/query.go') diff --git a/cmd/query.go b/cmd/query.go index a2ac5a4..649b9ea 100644 --- a/cmd/query.go +++ b/cmd/query.go @@ -12,6 +12,8 @@ import ( type QueryFlags struct { Outputer query.Outputer + DocumentSeparator string + ListSeparator string CustomFormat string OptimizationLevel int } @@ -28,17 +30,53 @@ func setupQueryFlags(args []string, fs *flag.FlagSet, flags *QueryFlags, dateFor flags.Outputer = query.JsonOutput{} return nil case "pathonly": - flags.Outputer, _ = query.NewCustomOutput("%p", dateFormat) + flags.Outputer, _ = query.NewCustomOutput("%p", dateFormat, "\n", "") return nil case "custom": var err error - flags.Outputer, err = query.NewCustomOutput(flags.CustomFormat, dateFormat) + flags.Outputer, err = query.NewCustomOutput(flags.CustomFormat, dateFormat, flags.DocumentSeparator, flags.ListSeparator) return err } return fmt.Errorf("Unrecognized output format: %s", arg) }) - fs.StringVar(&flags.CustomFormat, "outCustomFormat", query.DefaultOutputFormat, "format string for --outFormat custom, see EXAMPLES for more details") + fs.StringVar(&flags.CustomFormat, "outCustomFormat", query.DefaultOutputFormat, "format string for --outFormat custom, see Output Format for more details") fs.IntVar(&flags.OptimizationLevel, "optLevel", 0, "optimization `level` for queries, 0 is automatic, <0 to disable") + fs.StringVar(&flags.DocumentSeparator, "docSeparator", "\n", "separator for custom output format") + fs.StringVar(&flags.ListSeparator, "listSeparator", ", ", "separator for list fields") + + fs.Usage = func() { + f := fs.Output() + fmt.Fprintf(f, "Usage of %s %s\n", os.Args[0], fs.Name()) + fmt.Fprintf(f, " %s [global-flags] %s [query-flags]\n\n", + os.Args[0], fs.Name()) + fmt.Fprintln(f, "Query Flags:") + fs.PrintDefaults() + fmt.Fprintln(f, "\nOutput Format:") + help := `The output format of query results can be customized by setting -outCustomFormat. + + The output of each document has the value of -docSeparator appended to it. + Dates are formated using -dateFormat + Lists use -listSeparator to delimit elements + + Placeholder - Type - Value + %p - Str - path + %T - Str - title + %d - Date - date + %f - Date - filetime + %a - List - authors + %t - List - tags + %l - List - links + %m - Str - meta + + Examples: + "%p %T %d tags:%t" -> '/a/path/to/document A Title 2006-01-02T15:04:05Z07:00 tags:tag1, tag2\n' + "

%T

" -> '

A Title

\n' + +` + fmt.Fprint(f, help) + fmt.Fprintln(f, "Global Flags:") + flag.PrintDefaults() + } fs.Parse(args) } -- cgit v1.2.3