From 85c9a6b1c8e5d5581f0f5c9f4b78314c1de877cb Mon Sep 17 00:00:00 2001 From: "David (aider)" Date: Wed, 4 Sep 2024 17:09:56 +0200 Subject: [PATCH] feat: add list-sites command --- frappe/commands/utils.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/frappe/commands/utils.py b/frappe/commands/utils.py index 6f783bb7ef..37fbf89492 100644 --- a/frappe/commands/utils.py +++ b/frappe/commands/utils.py @@ -1170,6 +1170,29 @@ def rebuild_global_search(context, static_pages=False): raise SiteNotSpecifiedError +@click.command("list-sites") +@click.option("--json", "output_json", is_flag=True, help="Output in JSON format") +@pass_context +def list_sites(context, output_json=False): + "List all the sites in current bench" + site_dir = os.getcwd() + sites = [ + site + for site in os.listdir(site_dir) + if os.path.isdir(os.path.join(site_dir, site)) + and not site.startswith(".") + and os.path.exists(os.path.join(site_dir, site, "site_config.json")) + ] + if output_json: + click.echo(json.dumps(sites)) + elif sites: + click.echo("Available sites:") + for site in sites: + click.echo(f" {site}") + else: + click.echo("No sites found") + + commands = [ build, clear_cache, @@ -1203,4 +1226,5 @@ commands = [ add_to_email_queue, rebuild_global_search, run_parallel_tests, + list_sites, ]