This is an archive of the discontinued Mercurial Phabricator instance.

serve: add option print-url
ClosedPublic

Authored by nspanti-logilab on May 24 2018, 9:28 AM.
Tags
  • Restricted Project
Subscribers

Details

Summary

It can be used to open hgweb in a web browser. Example :
xdg-open "hg serve --print-url".

Diff Detail

Repository
rHG Mercurial
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

nspanti-logilab added a project: Restricted Project.May 24 2018, 9:40 AM
durin42 accepted this revision.May 31 2018, 3:14 PM
This revision is now accepted and ready to land.May 31 2018, 3:14 PM
This revision was automatically updated to reflect the committed changes.
yuja added a subscriber: yuja.Jun 1 2018, 10:47 PM
('t', 'templates', '', _('web templates to use'), _('TEMPLATE')),
('', 'style', '', _('template style to use'), _('STYLE')),
('6', 'ipv6', None, _('use IPv6 in addition to IPv4')),
  • ('', 'certificate', '', _('SSL certificate file'), _('FILE'))]

+ ('', 'certificate', '', _('SSL certificate file'), _('FILE')),
+ ('', 'print-url', None, _('start and print only the URL'))]

 + subrepoopts,
_('[OPTION]...'),
optionalrepo=True)

@@ -4798,6 +4799,10 @@

opts = pycompat.byteskwargs(opts)
if opts["stdio"] and opts["cmdserver"]:
    raise error.Abort(_("cannot use --stdio with --cmdserver"))

+ if opts["print_url"] and ui.verbose:
+ raise error.Abort(_("cannot use --print-url with --verbose"))
+ if opts["print_url"]:
+ opts['daemon'] = True

It's surprising that hg serve --print-url spawns a daemon process!

av6 added a subscriber: av6.Jun 2 2018, 8:42 AM

Merits another patch with some simple tests.

This comment was removed by admin.
In D3649#57835, @yuja wrote:

It's surprising that hg serve --print-url spawns a daemon process!

If it does not launch a daemon process, the procress caller (xdg-open, midori, firefox, etc.) waits the end of the stream to launch, so it waits that the hg serve procress ends!

In D3649#57838, @av6 wrote:

Merits another patch with some simple tests.

Could you describe tests that you would like?

@KelvinTot : Could you write in English or French, please?

yuja added a comment.Jun 4 2018, 8:19 AM

(resend because I forgot to remove the Phab shit, sorry for the noise.)

> It's surprising that `hg serve --print-url` spawns a daemon process!
If it does not launch a daemon process, the procress caller (`xdg-open`, `midori`, `firefox`, etc.) waits the end of the stream to launch, so it waits that the `hg serve` procress ends!

You can just run hg serve -d --print-url.

The option could be named as --daemon-print-url if we needed such big
red switch, but I don't think that makes sense.

av6 added a comment.Jun 4 2018, 8:43 AM

Could you describe tests that you would like?

For example, some that check that url is correct and is printed on stdout and not stderr, maybe also that it is printed when --port is specified (unlike "listening at" line). Doesn't have to be a lot, just some usage of this new command line switch in the tests. For inspiration, there are examples in test-hgwebdir.t, lines 1414 and 1431.

admin added a subscriber: admin.Jun 4 2018, 9:05 AM
In D3649#57906, @yuja wrote:

(resend because I forgot to remove the Phab shit, sorry for the noise.)

> It's surprising that `hg serve --print-url` spawns a daemon process!
If it does not launch a daemon process, the procress caller (`xdg-open`, `midori`, `firefox`, etc.) waits the end of the stream to launch, so it waits that the `hg serve` procress ends!

You can just run hg serve -d --print-url.
The option could be named as --daemon-print-url if we needed such big
red switch, but I don't think that makes sense.

On reflection I agree, it's a little too magical that --print-url daemonizes. Let's get a follow-up that doesn't do that, especially since -d is so easy to type.

(I'd probably often use --print-url without --daemon, FWIW)