Skip to content

Commit 8ac0303

Browse files
[commands][list] Add support for space-separated output in search, grep and list.
1 parent d5fe932 commit 8ac0303

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

sources/lib/main.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,15 @@ type ListFlags struct {
8181
Library *string `long:"library" short:"l" value-name:"{identifier}"`
8282
Type *string `long:"type" short:"t" choice:"library" choice:"document"`
8383
What *string `long:"what" short:"w" choice:"identifier" choice:"title" choice:"name" choice:"path" choice:"commonmark-link"`
84-
Format *string `long:"format" short:"f" choice:"text" choice:"text-0" choice:"json"`
84+
Format *string `long:"format" short:"f" choice:"text" choice:"text-sp" choice:"text-0" choice:"json"`
8585
}
8686

8787
type SearchFlags struct {
8888
Library *string `long:"library" short:"l" value-name:"{identifier}"`
8989
Type *string `long:"type" short:"t" choice:"library" choice:"document"`
9090
What *string `long:"what" short:"w" choice:"identifier" choice:"title" choice:"name" choice:"path" choice:"commonmark-link"`
9191
How *string `long:"how" short:"W" choice:"identifier" choice:"title" choice:"name" choice:"path" choice:"body"`
92-
Format *string `long:"format" short:"f" choice:"text" choice:"text-0" choice:"json"`
92+
Format *string `long:"format" short:"f" choice:"text" choice:"text-sp" choice:"text-0" choice:"json"`
9393
Action *string `long:"action" short:"a" choice:"output" choice:"edit" choice:"export" choice:"browse"`
9494
MultipleAllowed *bool `long:"multiple" short:"m"`
9595
}
@@ -98,7 +98,7 @@ type GrepFlags struct {
9898
Library *string `long:"library" short:"l" value-name:"{identifier}"`
9999
What *string `long:"what" short:"w" choice:"identifier" choice:"title" choice:"name" choice:"path" choice:"commonmark-link"`
100100
Where *string `long:"where" short:"W" choice:"identifier" choice:"title" choice:"name" choice:"path" choice:"body"`
101-
Format *string `long:"format" short:"f" choice:"text" choice:"text-0" choice:"json" choice:"context"`
101+
Format *string `long:"format" short:"f" choice:"text" choice:"text-sp" choice:"text-0" choice:"json" choice:"context"`
102102
Terms []string `long:"term" short:"t" value-name:"{term}"`
103103
Action *string `long:"action" short:"a" choice:"output" choice:"edit" choice:"export" choice:"browse"`
104104
MultipleAllowed *bool `long:"multiple" short:"m"`
@@ -1473,13 +1473,24 @@ func mainListOutput (_options [][2]string, _format string, _globals *Globals) (*
14731473

14741474
switch _format {
14751475

1476-
case "text", "text-0" :
1476+
case "text", "text-sp", "text-0" :
14771477
_separator := byte ('\n')
1478+
_always := true
14781479
if _format == "text-0" {
14791480
_separator = 0
1481+
} else if _format == "text-sp" {
1482+
_separator = byte (' ')
1483+
_always = false
14801484
}
1485+
_first := true
14811486
for _, _value := range _list {
1487+
if !_first {
1488+
_buffer.WriteByte (_separator)
1489+
}
14821490
_buffer.WriteString (_value)
1491+
_first = false
1492+
}
1493+
if _always {
14831494
_buffer.WriteByte (_separator)
14841495
}
14851496

0 commit comments

Comments
 (0)