bench browse command to open site from terminal (#6438)

* Add new bench browse command to open site from terminal

* Fix typo

* Support different variation of command
- Added support for 'bench --site site-name browse'
since we use --site option for site related commands

* Use click.echo instead of print
This commit is contained in:
Suraj Shetty 2018-11-12 10:48:45 +05:30 committed by Rushabh Mehta
parent 488f62bcb8
commit 5add26e407

View file

@ -542,6 +542,28 @@ def publish_realtime(context, event, message, room, user, doctype, docname, afte
finally:
frappe.destroy()
@click.command('browse')
@click.argument('site', required=False)
@pass_context
def browse(context, site):
'''Opens the site on web browser'''
import webbrowser
site = context.sites[0] if context.sites else site
if not site:
click.echo('''Please provide site name\n\nUsage:\n\tbench browse [site-name]\nor\n\tbench --site [site-name] browse''')
return
site = site.lower()
if site in frappe.utils.get_sites():
webbrowser.open('http://{site}:{port}'.format(
site=site,
port=frappe.get_conf(site).webserver_port
), new=2)
else:
click.echo("\nSite named \033[1m{}\033[0m doesn't exist\n".format(site))
commands = [
add_system_manager,
backup,
@ -565,4 +587,5 @@ commands = [
_use,
set_last_active_for_user,
publish_realtime,
browse
]