Commits

Marian Sigler committed fd56f1b

Make --web command line options configurable (closes #66).

  • Participants
  • Parent commits e62677e

Comments (0)

Files changed (4)

 ---------------
 
 To start the web interface for a local repository that you want to review you
-can run ``hg review --web``. Visit http://localhost:8080/ to use it.
+can run ``hg review --web`` (or ``-w``). Visit \http://localhost:8080/ to use it.
 
 When you add comments or signoffs hg-review will use your normal Mercurial
 username as the author.
 
     Default: ``false``
 
+``--no-allow-anon``, ``--no-read-only``
+    Turn off anonymous comments or read-only mode, respectively.
+    These options can be used to override the configuration values.
+
+All options can also be configured in your mercurial configuration file. For example::
+
+    [review]
+    address = 0.0.0.0
+    read-only = true
+
 
 .. _deployment:
 
 from rutil import fromlocal, tolocal
 from mercurial import help, templatefilters, util
 from mercurial.node import short
+from mercurial.util import Abort
 
 def _get_datastore(ui, repo):
     try:
 def _web_command(ui, repo, **opts):
     ui.note(messages.WEB_START)
     read_only = opts.pop('read_only')
+    no_read_only = opts.pop('no_read_only')
     allow_anon = opts.pop('allow_anon')
+    no_allow_anon = opts.pop('no_allow_anon')
     address = opts.pop('address')
-    port = int(opts.pop('port'))
+    port = opts.pop('port')
+
+    if not address:
+        address = ui.config('review', 'address', None)
+    if not port:
+        port = ui.config('review', 'port', None)
+
+    if port is not None:
+        port = int(port)
+
+    # abort if both --x and --no-x given:
+    if read_only and no_read_only:
+        raise Abort('Conflicting options: --read-only and --no-read-only')
+    if allow_anon and no_allow_anon:
+        raise Abort('Conflicting options: --allow-anon and --no-allow-anon')
+
+    # use the config value if neither --x nor --no-x are specified:
+    if not read_only and not no_read_only:
+        read_only = ui.configbool('review', 'read-only', False)
+    if not allow_anon and not no_allow_anon:
+        allow_anon = ui.configbool('review', 'allow-anon', False)
 
     if api.review_initialized(repo) and not api.local_datastore_exists(repo):
         _init_command(ui, repo, remote_path=None)
 
         ('w', 'web',         False,       'launch the web interface'),
         ('',  'read-only',   False,       'make the web interface read-only'),
+        ('',  'no-read-only', False,      'don\'t make the web interface read-only'),
         ('',  'allow-anon',  False,       'allow anonymous comments on the web interface'),
-        ('',  'address',     '127.0.0.1', 'run the web interface on the specified address'),
-        ('',  'port',        '8080',      'run the web interface on the specified port'),
+        ('',  'no-allow-anon', False,     'don\'t allow anonymous comments on the web interface'),
+        ('',  'address',     '',          'run the web interface on the specified address'),
+        ('',  'port',        '',          'run the web interface on the specified port'),
     ],
     'hg review')
 }
 
 If ``--port`` is given the web interface will listen on the given port.
 
+All options can be preconfigured in your mercurial configuration file in the
+``review`` section. The options ``--no-read-only`` and ``-no-allow-anon`` can
+be used to override that configuration.
 """
 
 EDIT = r"""
 
 
 def load_interface(ui, repo, read_only=False, allow_anon=False,
-        open=False, address='127.0.0.1', port=8080):
+        open=False, address=None, port=None):
+    if address is None:
+        address = '127.0.0.1'
+    if port is None:
+        port = 8080
+
     if open:
         import webbrowser
         webbrowser.open('http://localhost:%d/' % port)