From c9d6073ec34311e5066bf4d4642fae38ee765e84 Mon Sep 17 00:00:00 2001 From: Zev Averbach Date: Fri, 31 Mar 2023 21:08:19 +0200 Subject: [PATCH] small bugfix where existence of custom domain wasn't checked before trying to set it --- .gitignore | 1 + publify/publify.py | 21 +++++++++------------ setup.py | 2 +- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index be0f4b2..c2ccd9e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ __pycache__/ *egg-info/ dist/ TODO.md +.pypirc diff --git a/publify/publify.py b/publify/publify.py index 255d800..0b63eec 100644 --- a/publify/publify.py +++ b/publify/publify.py @@ -78,7 +78,7 @@ def deploy_page_to_netlify(dirpath: pl.Path, custom_domain: str | None = None) - rj = response.json() print("the site is published: " + rj["url"]) if custom_domain is not None: - sleep(2) + check_that_custom_domain_is_not_in_use(custom_domain) set_to_custom_domain(rj["id"], custom_domain) @@ -134,7 +134,6 @@ def check_that_custom_domain_is_not_in_use(custom_domain: str) -> None: def set_to_custom_domain(site_id: str, custom_domain: str) -> None: URL = f"https://app.netlify.com/access-control/bb-api/api/v1/sites/{site_id}" - check_that_custom_domain_is_not_in_use(custom_domain) response = requests.put( URL, json={"custom_domain": custom_domain}, @@ -174,6 +173,7 @@ def cli_set_custom_domain() -> None: except IndexError: print("Please provide a --custom-domain") return + check_that_custom_domain_is_not_in_use(custom_domain) try: domain = sys.argv[sys.argv.index("--domain") + 1] except IndexError: @@ -309,11 +309,9 @@ def cli_list_sites() -> None: def main() -> None: if "--help" in sys.argv or len(sys.argv) == 1: - display_help() - sys.exit() + return display_help() elif "--list-sites" in sys.argv: - cli_list_sites() - sys.exit() + return cli_list_sites() elif "--remove-custom-domain" in sys.argv: try: cli_remove_custom_domain() @@ -321,26 +319,25 @@ def main() -> None: print("No site found with that custom domain") except NoCustomDomains: print("No custom domains configured in NETLIFY_DOMAINS") - sys.exit() + return elif "--delete-site" in sys.argv or "--remove-site" in sys.argv: try: cli_delete_site() except NoCustomDomains as e: print(str(e)) - sys.exit() + return elif "--custom-domain" in sys.argv and "--root-dir" not in sys.argv: if len(NETLIFY_DOMAINS) == 0: print("No custom domains configured in NETLIFY_DOMAINS") - sys.exit() + return if "--domain" not in sys.argv: print("Please supply a --domain") - sys.exit() + return try: cli_set_custom_domain() except DomainInUse: print("That domain is already in use") - sys.exit() - sys.exit() + return else: try: deploy_site() diff --git a/setup.py b/setup.py index c8ad8bc..776f538 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from setuptools import setup setup( name="publify", - version="0.1.6", + version="0.1.7", description="A CLI for publishing sites to Netlify and assigning custom domains to them.", author="Zev Averbach", author_email="zev@averba.ch",