help is a bit nicer looking, fixed a bug caused by moving an API call outside a try/xcept

This commit is contained in:
2023-03-31 23:02:58 +02:00
parent a5eb43d65c
commit b2fb3afd42
4 changed files with 16 additions and 19 deletions

View File

@@ -14,7 +14,7 @@
the site is published: http://6426ed336771f2380224fb84--scintillating-mochi-760bd3.netlify.app
```
## Publish Sites to Netlify With Custom Domains Too!
## Publish Sites to Netlify With Custom Subdomains Too!
```bash
> pub --root-dir mysite --custom-domain dude.helpers.fun
@@ -30,7 +30,7 @@ the site is published: http://642718842cb34f02bc6b0137--cheery-daifuku-f3417f.ne
the site is published at dudette.helpers.fun.
```
## Add A Custom Domain To An Already Published Site!
## Add A Custom Subdomain To An Already Published Site!
```bash
> pub --custom-domain hey.helpers.fun --domain startling-gingersnap-425138.netlify.app

View File

@@ -50,7 +50,7 @@ def deploy_page_to_netlify(dirpath: pl.Path, custom_domain: str | None = None) -
print("the site is published: " + rj["url"])
if custom_domain is not None:
check_that_custom_domain_is_not_in_use(custom_domain)
set_to_custom_domain(rj["id"], custom_domain)
set_to_custom_domain(rj["id"], custom_domain, rj["url"])
def remove_custom_domain(site_id: str) -> None:
@@ -80,7 +80,7 @@ def delete_site(site_id: str) -> None:
raise Exception("something went wrong")
def set_to_custom_domain(site_id: str, custom_domain: str) -> None:
def set_to_custom_domain(site_id: str, custom_domain: str, orig_url: str) -> None:
URL = f"https://app.netlify.com/access-control/bb-api/api/v1/sites/{site_id}"
response = requests.put(
URL,
@@ -90,12 +90,12 @@ def set_to_custom_domain(site_id: str, custom_domain: str) -> None:
if not response.ok:
print(response.reason)
raise Exception("something went wrong with setting the custom domain")
print(f"the site is published at {custom_domain}.")
print(f"the site is published at {custom_domain}. (originally '{orig_url}')")
def get_site_id_from_netlify_domain(domain: str) -> tuple[str, str]:
orig_domain = domain
if not domain.startswith("http://"):
if not domain.startswith("http://") and not domain.startswith("https://"):
domain = f"http://{domain}"
candidate = None
for site in get_all_sites():
@@ -106,6 +106,8 @@ def get_site_id_from_netlify_domain(domain: str) -> tuple[str, str]:
)
candidate = site["id"], site["url"]
if candidate is None:
if domain.startswith("http://"):
return get_site_id_from_netlify_domain(domain.replace("http", "https"))
raise NoResult(f"no result for partial domain '{orig_domain}'")
return candidate

View File

@@ -74,7 +74,7 @@ def cli_set_custom_domain(custom_domain: str, domain: str) -> None:
return
if len(NETLIFY_DOMAINS) == 1 and custom_domain.count(".") == 0:
custom_domain = f"{custom_domain}.{NETLIFY_DOMAINS[0]}"
set_to_custom_domain(site_id, custom_domain)
set_to_custom_domain(site_id, custom_domain, domain)
def cli_remove_custom_domain() -> None:
@@ -111,13 +111,8 @@ def cli_delete_site() -> None:
except IndexError:
print("Please provide a domain")
return
got = get_site_id_from_netlify_domain(domain)
try:
site_id, full_domain = got
except ValueError:
print(got)
raise
site_id, full_domain = get_site_id_from_netlify_domain(domain)
except NoResult:
if len(NETLIFY_DOMAINS) == 0:
raise NoCustomDomains(

View File

@@ -3,7 +3,7 @@ from setuptools import setup
setup(
name="publify",
version="0.1.7",
version="0.1.8",
description="A CLI for publishing sites to Netlify and assigning custom domains to them.",
author="Zev Averbach",
author_email="zev@averba.ch",