hgkw/keyword.py
branchkwmap-templates
changeset 187 a01a0392f648
parent 186 c1b7b1d052de
child 188 c5e1a361d009
equal deleted inserted replaced
186:c1b7b1d052de 187:a01a0392f648
   296 
   296 
   297     run after (re)enabling keyword expansion
   297     run after (re)enabling keyword expansion
   298     '''
   298     '''
   299     overwrite(ui, repo, files=args)
   299     overwrite(ui, repo, files=args)
   300 
   300 
   301 def demo(ui, repo, **opts):
   301 def demo(ui, repo, *args, **opts):
   302     '''print [keywordmaps] configuration and an expansion example
   302     '''print [keywordmaps] configuration and an expansion example
   303 
   303 
   304     Show current or default keyword template maps and their expansion
   304     show current, custom, or default keyword template maps and their expansion
   305     '''
   305     '''
   306     msg = 'hg keyword config and expansion example'
   306     msg = 'hg keyword config and expansion example'
       
   307     kwstatus = 'current'
   307     fn = 'demo.txt'
   308     fn = 'demo.txt'
   308     tmpdir = tempfile.mkdtemp('', 'kwdemo.')
   309     tmpdir = tempfile.mkdtemp('', 'kwdemo.')
   309     ui.note(_('creating temporary repo at %s\n') % tmpdir)
   310     ui.note(_('creating temporary repo at %s\n') % tmpdir)
   310     _repo = localrepo.localrepository(ui, path=tmpdir, create=True)
   311     _repo = localrepo.localrepository(ui, path=tmpdir, create=True)
   311     # for backwards compatibility
   312     # for backwards compatibility
   313     ui.setconfig('keyword', fn, '')
   314     ui.setconfig('keyword', fn, '')
   314     if opts['default']:
   315     if opts['default']:
   315         kwstatus = 'default'
   316         kwstatus = 'default'
   316         kwmaps = deftemplates
   317         kwmaps = deftemplates
   317     else:
   318     else:
   318         kwstatus = 'current'
   319         if args or opts['rcfile']:
       
   320             kwstatus = 'custom'
       
   321         for tmap in args:
       
   322             k, v = tmap.split('=', 1)
       
   323             ui.setconfig('keywordmaps', k.strip(), v.strip())
       
   324         if opts['rcfile']:
       
   325             ui.readconfig(opts['rcfile'])
   319         kwmaps = dict(ui.configitems('keywordmaps')) or deftemplates
   326         kwmaps = dict(ui.configitems('keywordmaps')) or deftemplates
   320     if ui.configitems('keywordmaps'):
   327     if ui.configitems('keywordmaps'):
   321         for k, v in kwmaps.items():
   328         for k, v in kwmaps.items():
   322             ui.setconfig('keywordmaps', k, v)
   329             ui.setconfig('keywordmaps', k, v)
   323     reposetup(ui, _repo)
   330     reposetup(ui, _repo)
   406 
   413 
   407 
   414 
   408 cmdtable = {
   415 cmdtable = {
   409     'kwdemo':
   416     'kwdemo':
   410         (demo,
   417         (demo,
   411          [('d', 'default', None, _('show default keyword template maps'))],
   418          [('d', 'default', None, _('show default keyword template maps')),
   412          _('hg kwdemo [-d]')),
   419           ('f', 'rcfile', [], _('read maps from RCFILE'))],
       
   420          _('hg kwdemo [-d || [-f RCFILE] TEMPLATEMAP ...]')),
   413     'kwshrink': (shrink, [], _('hg kwshrink [NAME] ...')),
   421     'kwshrink': (shrink, [], _('hg kwshrink [NAME] ...')),
   414     'kwexpand': (expand, [], _('hg kwexpand [NAME] ...')),
   422     'kwexpand': (expand, [], _('hg kwexpand [NAME] ...')),
   415 }
   423 }