Skip to content

Commit 0083354

Browse files
committed
Mention fallback output in help/readme
1 parent 22977ca commit 0083354

File tree

4 files changed

+70
-14
lines changed

4 files changed

+70
-14
lines changed

README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ FLAGS:
5353
5454
OPTIONS:
5555
-f, --fields <bounds> Fields to keep, 1-indexed, comma separated.
56-
Use colon to include everything in a range.
56+
Use colon (:) to match a range (inclusive).
57+
Use equal (=) to apply out of bound fallback.
5758
Fields can be negative (-1 is the last field).
5859
[default 1:]
5960
@@ -64,6 +65,7 @@ OPTIONS:
6465
-f 3,2 => cb
6566
-f 3,1:2 => ca-b
6667
-f -3:-2 => b-c
68+
-f 1,8=fallback => afallback
6769
6870
To re-apply the delimiter add -j, to replace
6971
it add -r (followed by the new delimiter).
@@ -84,6 +86,10 @@ OPTIONS:
8486
-r, --replace-delimiter <new> Replace the delimiter with the provided text
8587
-t, --trim <type> Trim the delimiter (greedy). Valid values are
8688
(l|L)eft, (r|R)ight, (b|B)oth
89+
--fallback-oob <fallback> Generic fallback output for any field that
90+
cannot be found (oob stands for out of bound).
91+
It's overridden by any fallback assigned to a
92+
specific field (see -f for help)
8793
8894
Options precedence:
8995
--trim and --compress-delimiter are applied before --fields or similar

doc/tuc.1

+41-5
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ Print fields as a JSON array of strings
6767
.PD 0
6868
.P
6969
.PD
70-
\ \ \ \ \ \ \ Use colon to include everything in a range.
70+
\ \ \ \ \ \ \ Use colon (:) to match a range (inclusive).
71+
.PD 0
72+
.P
73+
.PD
74+
\ \ \ \ \ \ \ Use equal (=) to apply out of bound fallback.
7175
.PD 0
7276
.P
7377
.PD
@@ -100,6 +104,10 @@ Print fields as a JSON array of strings
100104
.P
101105
.PD
102106
\ \ \ \ \ \ \ \ \ \f[V]-f -3:-2 => b-c\f[R]
107+
.PD 0
108+
.P
109+
.PD
110+
\ \ \ \ \ \ \ \ \ \f[V]-f 1,8=fallback => afallback\f[R]
103111
.PP
104112
\ \ \ \ \ \ \ To re-apply the delimiter add -j, to replace
105113
.PD 0
@@ -173,6 +181,24 @@ To merge lines, use --no-join
173181
.P
174182
.PD
175183
\ \ \ \ \ \ \ Valid values are (l|L)eft, (r|R)ight, (b|B)oth
184+
.PP
185+
\ \ \ \ \f[B]--fallback-oob\f[R] [fallback]
186+
.PD 0
187+
.P
188+
.PD
189+
\ \ \ \ \ \ \ Generic fallback output for any field that
190+
.PD 0
191+
.P
192+
.PD
193+
\ \ \ \ \ \ \ cannot be found (oob stands for out of bound).
194+
.PD 0
195+
.P
196+
.PD
197+
\ \ \ \ \ \ \ It\[cq]s overridden by any fallback assigned to a
198+
.PD 0
199+
.P
200+
.PD
201+
\ \ \ \ \ \ \ specific field (see -f for help)
176202
.SH OPTIONS PRECEDENCE
177203
.PP
178204
--trim and --compress-delimiter are applied before --fields or similar
@@ -181,15 +207,25 @@ To merge lines, use --no-join
181207
--characters and --fields read and allocate memory one line at a time
182208
.PP
183209
--lines allocate memory one line at a time as long as the requested
184-
fields are ordered and non-negative (e.g.\ -l 1,3:4,4,7), otherwise it
185-
allocates the whole input in memory (it also happens when -p or -m are
186-
being used)
210+
fields are
211+
.PD 0
212+
.P
213+
.PD
214+
ordered and non-negative (e.g.\ -l 1,3:4,4,7), otherwise it allocates
215+
.PD 0
216+
.P
217+
.PD
218+
the whole input in memory (it also happens when -p or -m are being used)
187219
.PP
188220
--bytes allocate the whole input in memory
189221
.SH COLORS
190222
.PP
191223
Help is displayed using colors.
192-
Colors will be suppressed in the following circumstances:
224+
Colors will be suppressed in the
225+
.PD 0
226+
.P
227+
.PD
228+
following circumstances:
193229
.IP \[bu] 2
194230
when the TERM environment variable is not set or set to \[lq]dumb\[rq]
195231
.IP \[bu] 2

doc/tuc.1.md

+14-6
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ OPTIONS
5454

5555
| **-f**, **\--fields** [bounds]
5656
| Fields to keep, 1-indexed, comma separated.
57-
| Use colon to include everything in a range.
57+
| Use colon (:) to match a range (inclusive).
58+
| Use equal (=) to apply out of bound fallback.
5859
| Fields can be negative (-1 is the last field).
5960

6061
| [default 1:]
@@ -66,6 +67,7 @@ OPTIONS
6667
| `-f 3,2 => cb`
6768
| `-f 3,1:2 => ca-b`
6869
| `-f -3:-2 => b-c`
70+
| `-f 1,8=fallback => afallback`
6971

7072
| To re-apply the delimiter add -j, to replace
7173
| it add -r (followed by the new delimiter)
@@ -100,6 +102,12 @@ OPTIONS
100102
| Trim the delimiter (greedy).
101103
| Valid values are (l|L)eft, (r|R)ight, (b|B)oth
102104

105+
| **\--fallback-oob** [fallback]
106+
| Generic fallback output for any field that
107+
| cannot be found (oob stands for out of bound).
108+
| It's overridden by any fallback assigned to a
109+
| specific field (see -f for help)
110+
103111
OPTIONS PRECEDENCE
104112
==================
105113

@@ -110,17 +118,17 @@ MEMORY CONSUMPTION
110118

111119
\--characters and \--fields read and allocate memory one line at a time
112120

113-
\--lines allocate memory one line at a time as long as the requested fields are
114-
ordered and non-negative (e.g. -l 1,3:4,4,7), otherwise it allocates
115-
the whole input in memory (it also happens when -p or -m are being used)
121+
| \--lines allocate memory one line at a time as long as the requested fields are
122+
| ordered and non-negative (e.g. -l 1,3:4,4,7), otherwise it allocates
123+
| the whole input in memory (it also happens when -p or -m are being used)
116124

117125
\--bytes allocate the whole input in memory
118126

119127
COLORS
120128
======
121129

122-
Help is displayed using colors. Colors will be suppressed in the
123-
following circumstances:
130+
| Help is displayed using colors. Colors will be suppressed in the
131+
| following circumstances:
124132

125133
- when the TERM environment variable is not set or set to "dumb"
126134
- when the NO_COLOR environment variable is set (regardless of value)

src/help.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ FLAGS:
2929
3030
OPTIONS:
3131
-f, --fields <bounds> Fields to keep, 1-indexed, comma separated.
32-
Use colon to include everything in a range.
32+
Use colon (:) to match a range (inclusive).
33+
Use equal (=) to apply out of bound fallback.
3334
Fields can be negative (-1 is the last field).
3435
[default: 1:]
3536
@@ -40,6 +41,7 @@ OPTIONS:
4041
-f 3,2 => cb
4142
-f 3,1:2 => ca-b
4243
-f -3:-2 => b-c
44+
-f 1,8=fallback => afallback
4345
4446
To re-apply the delimiter add -j, to replace
4547
it add -r (followed by the new delimiter).
@@ -61,6 +63,10 @@ OPTIONS:
6163
Implies --join
6264
-t, --trim <type> Trim the delimiter (greedy). Valid values are
6365
(l|L)eft, (r|R)ight, (b|B)oth
66+
--fallback-oob <fallback> Generic fallback output for any field that
67+
cannot be found (oob stands for out of bound).
68+
It's overridden by any fallback assigned to a
69+
specific field (see -f for help)
6470
6571
Options precedence:
6672
--trim and --compress-delimiter are applied before --fields or similar
@@ -126,7 +132,7 @@ fn get_colored_help(text: &str) -> String {
126132
.replace_all(text, "\x1b[33m$0\x1b[0m");
127133

128134
// any example using "-f something"
129-
let text = Regex::new(r#"-(f|l) ('.+'|[0-9,:-]+)"#)
135+
let text = Regex::new(r#"-(f|l) ('.+'|[0-9,:-]+(=[^\s]+)?)"#)
130136
.unwrap()
131137
.replace_all(&text, "-$1 \x1b[33m$2\x1b[0m");
132138

0 commit comments

Comments
 (0)