comparison tests/test-basic.t @ 40547:840cd57cde32

ui: add config knob to redirect status messages to stderr (API) This option can be used to isolate structured output from status messages. For now, "stdio" (stdout/err pair) and "stderr" are supported. In future patches, I'll add the "channel" option which will send status messages to a separate command-server channel with some metadata attached, maybe in CBOR encoding. This is a part of the generic templating plan: https://www.mercurial-scm.org/wiki/GenericTemplatingPlan#Sanity_check_output .. api:: Status messages may be sent to a dedicated stream depending on configuration. Don't use ``ui.status()``, etc. as a shorthand for conditional writes. Use ``ui.write()`` for data output.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 03 Nov 2018 19:42:50 +0900
parents d6b6f1b441cf
children 9803323048b6
comparison
equal deleted inserted replaced
40543:7bffbbe03e90 40547:840cd57cde32
100 $TESTTMP/t 100 $TESTTMP/t
101 101
102 At the end... 102 At the end...
103 103
104 $ cd .. 104 $ cd ..
105
106 Status message redirection:
107
108 $ hg init empty
109
110 status messages are sent to stdout by default:
111
112 $ hg outgoing -R t empty -Tjson 2>/dev/null
113 comparing with empty
114 searching for changes
115 [
116 {
117 "bookmarks": [],
118 "branch": "default",
119 "date": [0, 0],
120 "desc": "test",
121 "node": "acb14030fe0a21b60322c440ad2d20cf7685a376",
122 "parents": ["0000000000000000000000000000000000000000"],
123 "phase": "draft",
124 "rev": 0,
125 "tags": ["tip"],
126 "user": "test"
127 }
128 ]
129
130 which can be configured to send to stderr, so the output wouldn't be
131 interleaved:
132
133 $ cat <<'EOF' >> "$HGRCPATH"
134 > [ui]
135 > message-output = stderr
136 > EOF
137 $ hg outgoing -R t empty -Tjson 2>/dev/null
138 [
139 {
140 "bookmarks": [],
141 "branch": "default",
142 "date": [0, 0],
143 "desc": "test",
144 "node": "acb14030fe0a21b60322c440ad2d20cf7685a376",
145 "parents": ["0000000000000000000000000000000000000000"],
146 "phase": "draft",
147 "rev": 0,
148 "tags": ["tip"],
149 "user": "test"
150 }
151 ]
152 $ hg outgoing -R t empty -Tjson >/dev/null
153 comparing with empty
154 searching for changes
155
156 this option should be turned off by HGPLAIN= since it may break scripting use:
157
158 $ HGPLAIN= hg outgoing -R t empty -Tjson 2>/dev/null
159 comparing with empty
160 searching for changes
161 [
162 {
163 "bookmarks": [],
164 "branch": "default",
165 "date": [0, 0],
166 "desc": "test",
167 "node": "acb14030fe0a21b60322c440ad2d20cf7685a376",
168 "parents": ["0000000000000000000000000000000000000000"],
169 "phase": "draft",
170 "rev": 0,
171 "tags": ["tip"],
172 "user": "test"
173 }
174 ]
175
176 but still overridden by --config:
177
178 $ HGPLAIN= hg outgoing -R t empty -Tjson --config ui.message-output=stderr \
179 > 2>/dev/null
180 [
181 {
182 "bookmarks": [],
183 "branch": "default",
184 "date": [0, 0],
185 "desc": "test",
186 "node": "acb14030fe0a21b60322c440ad2d20cf7685a376",
187 "parents": ["0000000000000000000000000000000000000000"],
188 "phase": "draft",
189 "rev": 0,
190 "tags": ["tip"],
191 "user": "test"
192 }
193 ]
194
195 Invalid ui.message-output option:
196
197 $ hg log -R t --config ui.message-output=bad
198 abort: invalid ui.message-output destination: bad
199 [255]
200
201 Underlying message streams should be updated when ui.fout/ferr are set:
202
203 $ cat <<'EOF' > capui.py
204 > from mercurial import pycompat, registrar
205 > cmdtable = {}
206 > command = registrar.command(cmdtable)
207 > @command(b'capui', norepo=True)
208 > def capui(ui):
209 > out = ui.fout
210 > ui.fout = pycompat.bytesio()
211 > ui.status(b'status\n')
212 > ui.ferr = pycompat.bytesio()
213 > ui.warn(b'warn\n')
214 > out.write(b'stdout: %s' % ui.fout.getvalue())
215 > out.write(b'stderr: %s' % ui.ferr.getvalue())
216 > EOF
217 $ hg --config extensions.capui=capui.py --config ui.message-output=stdio capui
218 stdout: status
219 stderr: warn