From 5add26e40766ea18159bf06b4a2b0374aa36dc56 Mon Sep 17 00:00:00 2001 From: Suraj Shetty Date: Mon, 12 Nov 2018 10:48:45 +0530 Subject: [PATCH] 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 --- frappe/commands/site.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/frappe/commands/site.py b/frappe/commands/site.py index aa6b51406d..682e9e3664 100755 --- a/frappe/commands/site.py +++ b/frappe/commands/site.py @@ -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 ]