diff --git a/sno/init.py b/sno/init.py index a7622e2f5..a24cced94 100644 --- a/sno/init.py +++ b/sno/init.py @@ -195,9 +195,7 @@ def prompt_for_table(self, prompt): else: self.print_table_list() if get_input_mode() == InputMode.NO_INPUT: - raise NotFound( - "No table specified", exit_code=NO_TABLE, param_hint="--table" - ) + raise NotFound("No table specified", exit_code=NO_TABLE) t_choices = click.Choice(choices=table_list) t_default = table_list[0] if len(table_list) == 1 else None return click.prompt( @@ -213,9 +211,7 @@ def __str__(self): def check_table(self, table_name): if table_name not in self.get_tables(): raise NotFound( - f"Table '{table_name}' not found", - exit_code=NO_TABLE, - param_hint="--table", + f"Table '{table_name}' not found", exit_code=NO_TABLE, ) def __enter__(self): @@ -541,17 +537,8 @@ def get_table_names_map(tables): @click.command("import") @click.pass_context @click.argument("source") -@click.option( - "tables", - "--table", - "-t", - multiple=True, - help=( - "Which table to import (can specify more than one). " - "If not specified, this will be selected interactively" - ), - cls=MutexOption, - exclusive_with=["do_list", "all_tables"], +@click.argument( + "tables", nargs=-1, ) @click.option( "--all-tables", @@ -587,7 +574,7 @@ def get_table_names_map(tables): "--output-format", "-o", type=click.Choice(["text", "json"]), default="text", ) def import_table( - ctx, source, tables, all_tables, message, do_list, output_format, version + ctx, all_tables, message, do_list, output_format, version, source, tables, ): """ Import data into a repository. @@ -639,23 +626,14 @@ def import_table( @click.command() @click.pass_context +@click.argument( + "tables", nargs=-1, +) @click.option( "--import", "import_from", help='Import from data: "FORMAT:PATH" eg. "GPKG:my.gpkg"', ) -@click.option( - "tables", - "--table", - "-t", - multiple=True, - help=( - "Which table to import (can specify more than one). " - "If not specified, this will be selected interactively" - ), - cls=MutexOption, - exclusive_with=["do_list", "all_tables"], -) @click.option( "--all-tables", "-a", @@ -689,7 +667,7 @@ def import_table( hidden=True, ) def init( - ctx, import_from, tables, all_tables, do_checkout, message, directory, version + ctx, all_tables, do_checkout, message, directory, version, import_from, tables ): """ Initialise a new repository and optionally import data @@ -699,6 +677,11 @@ def init( To show available tables in the import data, use $ sno init --import=GPKG:my.gpkg """ + if tables and not import_from: + raise click.UsageError( + f"Table names cannot be specified without --import. Did you mean `--path PATH`?" + ) + if import_from: check_git_user(repo=None) source_loader = OgrImporter.open(import_from, None) diff --git a/tests/conftest.py b/tests/conftest.py index a7d0bb6ff..72ef67b52 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -305,8 +305,7 @@ def _data_imported( "import", f"GPKG:{data / source_gpkg}", f"--version={version}", - f"--table={table}", - "mytable", + f"{table}:mytable", ] ) assert r.exit_code == 0, r diff --git a/tests/scripts/e2e-1.ps1 b/tests/scripts/e2e-1.ps1 index da15d1170..8c87c4241 100644 --- a/tests/scripts/e2e-1.ps1 +++ b/tests/scripts/e2e-1.ps1 @@ -50,11 +50,11 @@ $SQLITE=(Join-Path $SNO_PREFIX 'sqlite3.exe') New-Item -ItemType Directory -Path "${TMP_PATH}\test" Push-Location "${TMP_PATH}\test" try { - Exec { sno init . } + Exec { sno init --path . } Exec { sno -v config --local 'user.name' 'Sno E2E Test 1' } Exec { sno -v config --local 'user.email' 'sno-e2e-test-1@email.invalid' } Exec { sno -v config --local 'core.pager' false } - Exec { sno import "GPKG:${TEST_GPKG}" "--table=mylayer" } + Exec { sno import "GPKG:${TEST_GPKG}" "mylayer" } Exec { sno log } Exec { sno checkout } diff --git a/tests/scripts/e2e-1.sh b/tests/scripts/e2e-1.sh index e00878b1b..c98a6b317 100755 --- a/tests/scripts/e2e-1.sh +++ b/tests/scripts/e2e-1.sh @@ -32,10 +32,10 @@ mkdir "${TMP_PATH}/test" cd "${TMP_PATH}/test" set -x -sno init . +sno init --path . sno config user.name "Sno E2E Test 1" sno config user.email "sno-e2e-test-1@email.invalid" -sno import "GPKG:${TEST_GPKG}" --table=mylayer +sno import "GPKG:${TEST_GPKG}" mylayer sno log sno checkout diff --git a/tests/test_e2e.py b/tests/test_e2e.py index c3b2cde5f..94ba53ee4 100644 --- a/tests/test_e2e.py +++ b/tests/test_e2e.py @@ -54,7 +54,7 @@ def test_e2e( assert r.exit_code == 0 # import data - r = cli_runner.invoke(["import", f"GPKG:{data / gpkg}", "--table", table]) + r = cli_runner.invoke(["import", f"GPKG:{data / gpkg}", table]) assert r.exit_code == 0 # check there's a commit diff --git a/tests/test_init.py b/tests/test_init.py index fbc7aa8b7..136f132c0 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -120,7 +120,7 @@ def test_init_import_table_with_prompt_with_no_input( " census2016_sdhca_ot_ced_short - census2016_sdhca_ot_ced_short" in r.stdout ) - assert "Invalid value for --table: No table specified" in r.stderr + assert "No table specified" in r.stderr def test_init_import_table_ogr_types(data_archive_readonly, tmp_path, cli_runner): @@ -250,9 +250,7 @@ def test_init_import( repo_path.mkdir() with chdir(repo_path): - r = cli_runner.invoke( - ["init", "--import", f"gpkg:{data / gpkg}", f"--table={table}"] - ) + r = cli_runner.invoke(["init", "--import", f"gpkg:{data / gpkg}", table]) assert r.exit_code == 0, r assert (repo_path / "HEAD").exists() @@ -293,13 +291,7 @@ def test_init_import_name_clash(data_archive, cli_runner, geopackage): """ Import the GeoPackage into a Sno repository of the same name, and checkout a working copy of the same name. """ with data_archive("gpkg-editing") as data: r = cli_runner.invoke( - [ - "init", - "--import", - f"GPKG:editing.gpkg", - "--table=editing", - "--path=editing", - ] + ["init", "--import", f"GPKG:editing.gpkg", "editing", "--path=editing",] ) repo_path = data / "editing" @@ -355,21 +347,15 @@ def test_init_import_errors(data_archive, tmp_path, chdir, cli_runner): assert "Couldn't find 'thingz.gpkg'" in r.stderr r = cli_runner.invoke( - ["init", "--import", f"gpkg:{data/gpkg}", f"--table=no-existey"] + ["init", "--import", f"gpkg:{data/gpkg}", "no-existey"] ) assert r.exit_code == NO_TABLE, r - assert "Invalid value for --table: Table 'no-existey' not found" in r.stderr + assert "Table 'no-existey' not found" in r.stderr # not empty (repo_path / "a.file").touch() r = cli_runner.invoke( - [ - "init", - "--import", - f"gpkg:{data/gpkg}", - f"--table={table}", - f'--path={repo_path}', - ] + ["init", "--import", f"gpkg:{data/gpkg}", table, f'--path={repo_path}',] ) assert r.exit_code == INVALID_OPERATION, r assert "isn't empty" in r.stderr @@ -451,7 +437,7 @@ def test_init_import_alt_names(data_archive, tmp_path, cli_runner, chdir, geopac [ "import", f"GPKG:{source_path / source_gpkg}", - f"--table={source_table}:{import_path}", + f"{source_table}:{import_path}", ] ) assert r.exit_code == 0, r @@ -506,7 +492,7 @@ def test_init_import_home_resolve( [ "import", "GPKG:~/nz-pa-points-topo-150k.gpkg", - "--table=nz_pa_points_topo_150k", + "nz_pa_points_topo_150k", ] ) assert r.exit_code == 0, r @@ -530,7 +516,7 @@ def test_import_existing_wc( [ "import", f"GPKG:{source_path / 'nz-waca-adjustments.gpkg'}", - f"--table={H.POLYGONS.LAYER}", + H.POLYGONS.LAYER, ] ) assert r.exit_code == 0, r @@ -568,7 +554,7 @@ def test_import_existing_wc( [ "import", f"GPKG:{source_path / 'nz-waca-adjustments.gpkg'}", - f"--table={H.POLYGONS.LAYER}:waca2", + f"{H.POLYGONS.LAYER}:waca2", ] ) assert r.exit_code == 0, r diff --git a/tests/test_structure.py b/tests/test_structure.py index ee6361aad..cb25a5ffc 100644 --- a/tests/test_structure.py +++ b/tests/test_structure.py @@ -162,7 +162,7 @@ def _benchmark_import(*args, **kwargs): "import", str(data / source_gpkg), f"--version={import_version}", - f'--table={table}', + table, ] ) assert r.exit_code == 0, r @@ -394,13 +394,7 @@ def test_import_from_non_gpkg( gpkg_repo_path = tmp_path / "gpkg" gpkg_repo_path.mkdir() r = cli_runner.invoke( - [ - "init", - "--import", - data / source_gpkg, - f"--table={table}", - f"--path={gpkg_repo_path}", - ] + ["init", "--import", data / source_gpkg, table, f"--path={gpkg_repo_path}",] ) assert r.exit_code == 0, r @@ -432,7 +426,7 @@ def test_import_from_non_gpkg( "import", str(source_filename), f"--version={import_version}", - f"--table=data:{table}", + f"data:{table}", ] ) assert r.exit_code == 0, r @@ -666,7 +660,7 @@ def test_import_multiple( "import", f"GPKG:{data / source_gpkg}", f"--version={import_version}", - f"--table={table}", + table, ] ) assert r.exit_code == 0, r @@ -685,7 +679,7 @@ def test_import_multiple( "import", f"GPKG:{data / source_gpkg}", f"--version={import_version}", - f"--table={table}", + table, ] )