help is a bit nicer looking, fixed a bug caused by moving an API call outside a try/xcept
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -24,11 +24,11 @@ def cli_display_help() -> None:
|
||||
print(
|
||||
"""Usage:
|
||||
pub help
|
||||
pub <rootpath> [<custom_domain>] -------------------------------->deploy a site
|
||||
pub list ------------------------------->list all sites
|
||||
pub custom <custom_domain> <existing_domain> -------------------------->set a custom domain
|
||||
pub remove-custom <custom_domain> ----------------------->remove a custom domain
|
||||
pub delete/remove <domain or custom_domain> -------------------------------->delete a site
|
||||
pub <rootpath> [<custom_domain>] --------------------------------> deploy a site
|
||||
pub list -------------------------------> list all sites
|
||||
pub custom <custom_domain> <existing_domain> --------------------------> set a custom domain
|
||||
pub remove-custom <custom_domain> -----------------------> remove a custom domain
|
||||
pub delete/remove <domain or custom_domain> --------------------------------> delete a site
|
||||
"""
|
||||
)
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user