comparison mercurial/commands.py @ 32584:746e12a767b3

cat: add formatter support This is an example showing how formatter can handle the --output option. git subrepo isn't supported for now.
author Yuya Nishihara <yuya@tcha.org>
date Thu, 25 May 2017 21:53:44 +0900
parents 1b90036f42f0
children d3d262ff42c0
comparison
equal deleted inserted replaced
32583:7bfa1b199972 32584:746e12a767b3
33 discovery, 33 discovery,
34 encoding, 34 encoding,
35 error, 35 error,
36 exchange, 36 exchange,
37 extensions, 37 extensions,
38 formatter,
38 graphmod, 39 graphmod,
39 hbisect, 40 hbisect,
40 help, 41 help,
41 hg, 42 hg,
42 lock as lockmod, 43 lock as lockmod,
1336 @command('cat', 1337 @command('cat',
1337 [('o', 'output', '', 1338 [('o', 'output', '',
1338 _('print output to file with formatted name'), _('FORMAT')), 1339 _('print output to file with formatted name'), _('FORMAT')),
1339 ('r', 'rev', '', _('print the given revision'), _('REV')), 1340 ('r', 'rev', '', _('print the given revision'), _('REV')),
1340 ('', 'decode', None, _('apply any matching decode filter')), 1341 ('', 'decode', None, _('apply any matching decode filter')),
1341 ] + walkopts, 1342 ] + walkopts + formatteropts,
1342 _('[OPTION]... FILE...'), 1343 _('[OPTION]... FILE...'),
1343 inferrepo=True) 1344 inferrepo=True)
1344 def cat(ui, repo, file1, *pats, **opts): 1345 def cat(ui, repo, file1, *pats, **opts):
1345 """output the current or given revision of files 1346 """output the current or given revision of files
1346 1347
1366 m = scmutil.match(ctx, (file1,) + pats, opts) 1367 m = scmutil.match(ctx, (file1,) + pats, opts)
1367 fntemplate = opts.pop('output', '') 1368 fntemplate = opts.pop('output', '')
1368 if cmdutil.isstdiofilename(fntemplate): 1369 if cmdutil.isstdiofilename(fntemplate):
1369 fntemplate = '' 1370 fntemplate = ''
1370 1371
1371 if not fntemplate: 1372 if fntemplate:
1373 fm = formatter.nullformatter(ui, 'cat')
1374 else:
1372 ui.pager('cat') 1375 ui.pager('cat')
1373 return cmdutil.cat(ui, repo, ctx, m, fntemplate, '', **opts) 1376 fm = ui.formatter('cat', opts)
1377 with fm:
1378 return cmdutil.cat(ui, repo, ctx, m, fm, fntemplate, '', **opts)
1374 1379
1375 @command('^clone', 1380 @command('^clone',
1376 [('U', 'noupdate', None, _('the clone will include an empty working ' 1381 [('U', 'noupdate', None, _('the clone will include an empty working '
1377 'directory (only a repository)')), 1382 'directory (only a repository)')),
1378 ('u', 'updaterev', '', _('revision, tag, or branch to check out'), 1383 ('u', 'updaterev', '', _('revision, tag, or branch to check out'),