diff --git a/docs/cli-reference.rst b/docs/cli-reference.rst index 09eb0be..f03348f 100644 --- a/docs/cli-reference.rst +++ b/docs/cli-reference.rst @@ -841,12 +841,12 @@ See :ref:`cli_create_index`. sqlite-utils create-index chickens.db chickens -- -name Options: - --name TEXT Explicit name for the new index - --unique Make this a unique index - --if-not-exists Ignore if index already exists - --analyze Run ANALYZE after creating the index - --load-extension TEXT SQLite extensions to load - -h, --help Show this message and exit. + --name TEXT Explicit name for the new index + --unique Make this a unique index + --if-not-exists, --ignore Ignore if index already exists + --analyze Run ANALYZE after creating the index + --load-extension TEXT SQLite extensions to load + -h, --help Show this message and exit. enable-fts diff --git a/sqlite_utils/cli.py b/sqlite_utils/cli.py index cf00898..999658d 100644 --- a/sqlite_utils/cli.py +++ b/sqlite_utils/cli.py @@ -539,6 +539,7 @@ def index_foreign_keys(path, load_extension): @click.option("--unique", help="Make this a unique index", default=False, is_flag=True) @click.option( "--if-not-exists", + "--ignore", help="Ignore if index already exists", default=False, is_flag=True, diff --git a/tests/test_cli.py b/tests/test_cli.py index 01cc9bb..e98ffc1 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -214,13 +214,12 @@ def test_create_index(db_path): ] == db["Gosh2"].indexes # Trying to create the same index should fail assert 0 != CliRunner().invoke(cli.cli, create_index_unique_args).exit_code - # ... unless we use --if-not-exists - assert ( - 0 - == CliRunner() - .invoke(cli.cli, create_index_unique_args + ["--if-not-exists"]) - .exit_code - ) + # ... unless we use --if-not-exists or --ignore + for option in ("--if-not-exists", "--ignore"): + assert ( + CliRunner().invoke(cli.cli, create_index_unique_args + [option]).exit_code + == 0 + ) def test_create_index_analyze(db_path):