Mercurial > hg
diff mercurial/hgweb/__init__.py @ 38199:aea29e81753a
serve: add option print-url
It can be used to open hgweb in a web browser. Example :
xdg-open "`hg serve --print-url`".
Differential Revision: https://phab.mercurial-scm.org/D3649
author | Nicola Spanti <nicola.spanti@logilab.fr> |
---|---|
date | Thu, 24 May 2018 09:56:28 +0000 |
parents | 42567ffa10a2 |
children | 91104f10ff65 |
line wrap: on
line diff
--- a/mercurial/hgweb/__init__.py Sat May 26 11:33:02 2018 +0900 +++ b/mercurial/hgweb/__init__.py Thu May 24 09:56:28 2018 +0000 @@ -57,7 +57,9 @@ procutil.setsignalhandler() self.httpd = server.create_server(self.ui, self.app) - if self.opts['port'] and not self.ui.verbose: + if (self.opts['port'] and + not self.ui.verbose and + not self.opts['print_url']): return if self.httpd.prefix: @@ -78,13 +80,18 @@ fqaddr = self.httpd.fqaddr if r':' in fqaddr: fqaddr = r'[%s]' % fqaddr - if self.opts['port']: - write = self.ui.status + + url = 'http://%s%s/%s' % ( + pycompat.sysbytes(fqaddr), pycompat.sysbytes(port), prefix) + if self.opts['print_url']: + self.ui.write('%s\n' % url) 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)) + if self.opts['port']: + write = self.ui.status + else: + write = self.ui.write + write(_('listening at %s (bound to %s:%d)\n') % + (url, pycompat.sysbytes(bindaddr), self.httpd.port)) self.ui.flush() # avoid buffering of status message def run(self):