diff --git a/datasette/cli.py b/datasette/cli.py index ebba0244..f57fd2c5 100644 --- a/datasette/cli.py +++ b/datasette/cli.py @@ -100,7 +100,7 @@ def inspect(files, inspect_file, sqlite_extensions): "-n", "--name", default="datasette", - help="Application name to use when deploying to Now (ignored for Heroku)", + help="Application name to use when deploying", ) @click.option( "-m", @@ -259,10 +259,29 @@ def publish( install, extra_metadata, ): - create_output = check_output(["heroku", "apps:create", "--json"]).decode( - "utf8" - ) - app_name = json.loads(create_output)["name"] + + app_name = None + if name: + # Check to see if this app already exists + list_output = check_output(["heroku", "apps:list", "--json"]).decode('utf8') + apps = json.loads(list_output) + + for app in apps: + if app['name'] == name: + app_name = name + break + + if not app_name: + # Create a new app + cmd = ["heroku", "apps:create"] + if name: + cmd.append(name) + cmd.append("--json") + create_output = check_output(cmd).decode( + "utf8" + ) + app_name = json.loads(create_output)["name"] + call(["heroku", "builds:create", "-a", app_name]) diff --git a/docs/publish.rst b/docs/publish.rst index a7222959..1abe8881 100644 --- a/docs/publish.rst +++ b/docs/publish.rst @@ -49,7 +49,7 @@ This will output some details about the new deployment, including a URL like thi https://limitless-reef-88278.herokuapp.com/ deployed to Heroku -You can then set a custom subdomain by navigating to your new app's equivalent of ``https://dashboard.heroku.com/apps/limitless-reef-88278/settings`` and editing the name of your deployment, e.g. to http://datasette-publish-demo.herokuapp.com/ +You can specify a custom app name by passing ``-n my-app-name`` to the publish command. This will also allow you to overwrite an existing app. Custom metadata and plugins ---------------------------