aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/query.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/query.go')
-rw-r--r--cmd/query.go44
1 files changed, 41 insertions, 3 deletions
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'
+ "<h1><a href="%p">%T</a></h1>" -> '<h1><a href="/a/path/to/document">A Title</a></h1>\n'
+
+`
+ fmt.Fprint(f, help)
+ fmt.Fprintln(f, "Global Flags:")
+ flag.PrintDefaults()
+ }
fs.Parse(args)
}