From 7d8573d6724a13d5003e48d75682323ee1e55692 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sun, 19 May 2019 11:06:51 -0700 Subject: [PATCH] Rename "datasette publish now" to "datasette publish nowv1" Also added an alias so "datasette publish now" continues to work. Closes #472 --- .travis.yml | 2 +- datasette/cli.py | 11 ++++++++++- datasette/publish/now.py | 2 +- ...-help.txt => datasette-publish-nowv1-help.txt} | 4 ++-- docs/publish.rst | 10 +++++----- tests/test_docs.py | 2 +- tests/test_publish_now.py | 15 +++++++++++---- update-docs-help.py | 2 +- 8 files changed, 32 insertions(+), 16 deletions(-) rename docs/{datasette-publish-now-help.txt => datasette-publish-nowv1-help.txt} (93%) diff --git a/.travis.yml b/.travis.yml index 626046c6..1553ef1e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,7 +27,7 @@ jobs: - npm install -g now - python tests/fixtures.py fixtures.db fixtures.json - export ALIAS=`echo $TRAVIS_COMMIT | cut -c 1-7` - - datasette publish now fixtures.db -m fixtures.json --token=$NOW_TOKEN --branch=$TRAVIS_COMMIT --version-note=$TRAVIS_COMMIT --name=datasette-latest-$ALIAS --alias=latest.datasette.io --alias=$ALIAS.datasette.io + - datasette publish nowv1 fixtures.db -m fixtures.json --token=$NOW_TOKEN --branch=$TRAVIS_COMMIT --version-note=$TRAVIS_COMMIT --name=datasette-latest-$ALIAS --alias=latest.datasette.io --alias=$ALIAS.datasette.io - stage: release tagged version if: tag IS present python: 3.6 diff --git a/datasette/cli.py b/datasette/cli.py index c9d7d6d8..1d7457b2 100644 --- a/datasette/cli.py +++ b/datasette/cli.py @@ -98,7 +98,16 @@ async def inspect_(files, sqlite_extensions): return data -@cli.group() +class PublishAliases(click.Group): + aliases = {"now": "nowv1"} + + def get_command(self, ctx, cmd_name): + if cmd_name in self.aliases: + return click.Group.get_command(self, ctx, self.aliases[cmd_name]) + return click.Group.get_command(self, ctx, cmd_name) + + +@cli.group(cls=PublishAliases) def publish(): "Publish specified SQLite database files to the internet along with a Datasette-powered interface and API" pass diff --git a/datasette/publish/now.py b/datasette/publish/now.py index f2e3b9c2..38add86e 100644 --- a/datasette/publish/now.py +++ b/datasette/publish/now.py @@ -24,7 +24,7 @@ def publish_subcommand(publish): @click.option("--token", help="Auth token to use for deploy") @click.option("--alias", multiple=True, help="Desired alias e.g. yoursite.now.sh") @click.option("--spatialite", is_flag=True, help="Enable SpatialLite extension") - def now( + def nowv1( files, metadata, extra_options, diff --git a/docs/datasette-publish-now-help.txt b/docs/datasette-publish-nowv1-help.txt similarity index 93% rename from docs/datasette-publish-now-help.txt rename to docs/datasette-publish-nowv1-help.txt index 445c1bc7..a5417d71 100644 --- a/docs/datasette-publish-now-help.txt +++ b/docs/datasette-publish-nowv1-help.txt @@ -1,6 +1,6 @@ -$ datasette publish now --help +$ datasette publish nowv1 --help -Usage: datasette publish now [OPTIONS] [FILES]... +Usage: datasette publish nowv1 [OPTIONS] [FILES]... Options: -m, --metadata FILENAME Path to JSON file containing metadata to publish diff --git a/docs/publish.rst b/docs/publish.rst index a3df96fa..c343a2d3 100644 --- a/docs/publish.rst +++ b/docs/publish.rst @@ -57,7 +57,7 @@ Datasette can be deployed to Zeit Now's older v1 hosting platform. They no longe To publish your database(s) to a new instance hosted by Zeit Now v1, install the `now cli tool `__ and then run the following command:: - datasette publish now mydatabase.db + datasette publish nowv1 mydatabase.db This will upload your database to Zeit Now, assign you a new URL and install and start a new instance of Datasette to serve your database. @@ -75,7 +75,7 @@ You can use ``anything-you-like.now.sh``, provided no one else has already regis You can also use custom domains, if you `first register them with Zeit Now `_. -.. literalinclude:: datasette-publish-now-help.txt +.. literalinclude:: datasette-publish-nowv1-help.txt Custom metadata and plugins --------------------------- @@ -84,18 +84,18 @@ Custom metadata and plugins You can define your own :ref:`metadata` and deploy that with your instance like so:: - datasette publish now mydatabase.db -m metadata.json + datasette publish nowv1 mydatabase.db -m metadata.json If you just want to set the title, license or source information you can do that directly using extra options to ``datasette publish``:: - datasette publish now mydatabase.db \ + datasette publish nowv1 mydatabase.db \ --title="Title of my database" \ --source="Where the data originated" \ --source_url="http://www.example.com/" You can also specify plugins you would like to install. For example, if you want to include the `datasette-vega `_ visualization plugin you can use the following:: - datasette publish now mydatabase.db --install=datasette-vega + datasette publish nowv1 mydatabase.db --install=datasette-vega datasette package diff --git a/tests/test_docs.py b/tests/test_docs.py index dad61943..d481a633 100644 --- a/tests/test_docs.py +++ b/tests/test_docs.py @@ -34,7 +34,7 @@ def test_config_options_are_documented(config): ( ("serve", "datasette-serve-help.txt"), ("package", "datasette-package-help.txt"), - ("publish now", "datasette-publish-now-help.txt"), + ("publish nowv1", "datasette-publish-nowv1-help.txt"), ("publish heroku", "datasette-publish-heroku-help.txt"), ("publish cloudrun", "datasette-publish-cloudrun-help.txt"), ), diff --git a/tests/test_publish_now.py b/tests/test_publish_now.py index 1894d990..fa1ab30a 100644 --- a/tests/test_publish_now.py +++ b/tests/test_publish_now.py @@ -10,7 +10,7 @@ def test_publish_now_requires_now(mock_which): runner = CliRunner() with runner.isolated_filesystem(): open("test.db", "w").write("data") - result = runner.invoke(cli.cli, ["publish", "now", "test.db"]) + result = runner.invoke(cli.cli, ["publish", "nowv1", "test.db"]) assert result.exit_code == 1 assert "Publishing to Zeit Now requires now" in result.output @@ -19,11 +19,18 @@ def test_publish_now_requires_now(mock_which): def test_publish_now_invalid_database(mock_which): mock_which.return_value = True runner = CliRunner() - result = runner.invoke(cli.cli, ["publish", "now", "woop.db"]) + result = runner.invoke(cli.cli, ["publish", "nowv1", "woop.db"]) assert result.exit_code == 2 assert 'Path "woop.db" does not exist' in result.output +@mock.patch("shutil.which") +def test_publish_now_using_now_alias(mock_which): + mock_which.return_value = True + result = CliRunner().invoke(cli.cli, ["publish", "now", "woop.db"]) + assert result.exit_code == 2 + + @mock.patch("shutil.which") @mock.patch("datasette.publish.now.run") def test_publish_now(mock_run, mock_which): @@ -31,7 +38,7 @@ def test_publish_now(mock_run, mock_which): runner = CliRunner() with runner.isolated_filesystem(): open("test.db", "w").write("data") - result = runner.invoke(cli.cli, ["publish", "now", "test.db"]) + result = runner.invoke(cli.cli, ["publish", "nowv1", "test.db"]) assert 0 == result.exit_code mock_run.assert_called_once_with("now", stdout=subprocess.PIPE) @@ -44,7 +51,7 @@ def test_publish_now_force_token(mock_run, mock_which): with runner.isolated_filesystem(): open("test.db", "w").write("data") result = runner.invoke( - cli.cli, ["publish", "now", "test.db", "--force", "--token=X"] + cli.cli, ["publish", "nowv1", "test.db", "--force", "--token=X"] ) assert 0 == result.exit_code mock_run.assert_called_once_with( diff --git a/update-docs-help.py b/update-docs-help.py index 88ab6adf..3a1eb860 100644 --- a/update-docs-help.py +++ b/update-docs-help.py @@ -7,7 +7,7 @@ docs_path = Path(__file__).parent / "docs" includes = ( ("serve", "datasette-serve-help.txt"), ("package", "datasette-package-help.txt"), - ("publish now", "datasette-publish-now-help.txt"), + ("publish nowv1", "datasette-publish-nowv1-help.txt"), ("publish heroku", "datasette-publish-heroku-help.txt"), ("publish cloudrun", "datasette-publish-cloudrun-help.txt"), )