nspanti-logilab created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  It is inspired by a similar functionality in pydoc.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D3650

AFFECTED FILES
  mercurial/commands.py
  mercurial/hgweb/__init__.py
  tests/test-completion.t

CHANGE DETAILS

diff --git a/tests/test-completion.t b/tests/test-completion.t
--- a/tests/test-completion.t
+++ b/tests/test-completion.t
@@ -239,7 +239,7 @@
   pull: update, force, rev, bookmark, branch, ssh, remotecmd, insecure
   push: force, rev, bookmark, branch, new-branch, pushvars, ssh, remotecmd, 
insecure
   remove: after, force, subrepos, include, exclude, dry-run
-  serve: accesslog, daemon, daemon-postexec, errorlog, port, address, prefix, 
name, web-conf, webdir-conf, pid-file, stdio, cmdserver, templates, style, 
ipv6, certificate, subrepos
+  serve: accesslog, daemon, daemon-postexec, graphical, errorlog, port, 
address, prefix, name, web-conf, webdir-conf, pid-file, stdio, cmdserver, 
templates, style, ipv6, certificate, subrepos
   status: all, modified, added, removed, deleted, clean, unknown, ignored, 
no-status, terse, copies, print0, rev, change, include, exclude, subrepos, 
template
   summary: remote
   update: clean, check, merge, date, rev, tool
diff --git a/mercurial/hgweb/__init__.py b/mercurial/hgweb/__init__.py
--- a/mercurial/hgweb/__init__.py
+++ b/mercurial/hgweb/__init__.py
@@ -9,6 +9,7 @@
 from __future__ import absolute_import
 
 import os
+import webbrowser
 
 from ..i18n import _
 
@@ -60,6 +61,25 @@
         if self.opts['port'] and not self.ui.verbose:
             return
 
+        bindaddr = self._getbindaddr()
+
+        if self.opts['port']:
+            write = self.ui.status
+        else:
+            write = self.ui.write
+        write(_('listening at %s (bound to %s:%d)\n') %
+              (self._geturl(), pycompat.sysbytes(bindaddr), self.httpd.port))
+        self.ui.flush()  # avoid buffering of status message
+
+    def _getbindaddr(self):
+        bindaddr = self.httpd.addr
+        if bindaddr == r'0.0.0.0':
+            bindaddr = r'*'
+        elif r':' in bindaddr: # IPv6
+            bindaddr = r'[%s]' % bindaddr
+        return bindaddr
+
+    def _geturl(self):
         if self.httpd.prefix:
             prefix = self.httpd.prefix.strip('/') + '/'
         else:
@@ -69,25 +89,18 @@
         if port == r':80':
             port = r''
 
-        bindaddr = self.httpd.addr
-        if bindaddr == r'0.0.0.0':
-            bindaddr = r'*'
-        elif r':' in bindaddr: # IPv6
-            bindaddr = r'[%s]' % bindaddr
+        bindaddr = self._getbindaddr()
 
         fqaddr = self.httpd.fqaddr
         if r':' in fqaddr:
             fqaddr = r'[%s]' % fqaddr
-        if self.opts['port']:
-            write = self.ui.status
-        else:
-            write = self.ui.write
-        write(_('listening at http://%s%s/%s (bound to %s:%d)\n') %
-              (pycompat.sysbytes(fqaddr), pycompat.sysbytes(port),
-               prefix, pycompat.sysbytes(bindaddr), self.httpd.port))
-        self.ui.flush()  # avoid buffering of status message
+
+        return 'http://%s%s/%s' % (
+            pycompat.sysbytes(fqaddr), pycompat.sysbytes(port), prefix)
 
     def run(self):
+        if self.opts.pop('gui', None):
+            webbrowser.open(self._geturl())
         self.httpd.serve_forever()
 
 def createapp(baseui, repo, webconf):
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -4747,6 +4747,7 @@
      _('FILE')),
     ('d', 'daemon', None, _('run server in background')),
     ('', 'daemon-postexec', [], _('used internally by daemon mode')),
+    ('g', 'gui', None, _('open in default web browser')),
     ('E', 'errorlog', '', _('name of error log file to write to'), _('FILE')),
     # use string type, then we can check if something was passed
     ('p', 'port', '', _('port to listen on (default: 8000)'), _('PORT')),



To: nspanti-logilab, #hg-reviewers
Cc: mercurial-devel
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to