Skip to content

Commit 5dd0e4d

Browse files
committed
Import commands now require existing db (use farchive init first)
- import-files and import-manifest no longer auto-create db - Update tests to use farchive init before import commands - Consistent behavior: all write commands require init first
1 parent c4f429e commit 5dd0e4d

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

src/farchive/_cli.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -966,9 +966,7 @@ def _cmd_observe(args: argparse.Namespace) -> None:
966966

967967
def _cmd_import_files(args: argparse.Namespace) -> None:
968968
"""Import files from a directory into the archive."""
969-
new_db = _maybe_create_db(args)
970-
if new_db:
971-
print("Created new archive.", file=sys.stderr)
969+
_ensure_db(args)
972970
root = Path(args.root).resolve()
973971
if not root.is_dir():
974972
print(f"Not a directory: {args.root}", file=sys.stderr)
@@ -1075,9 +1073,7 @@ def _cmd_import_files(args: argparse.Namespace) -> None:
10751073

10761074
def _cmd_import_manifest(args: argparse.Namespace) -> None:
10771075
"""Import from a manifest file (JSONL or TSV)."""
1078-
new_db = _maybe_create_db(args)
1079-
if new_db:
1080-
print("Created new archive.", file=sys.stderr)
1076+
_ensure_db(args)
10811077
manifest_path = Path(args.manifest)
10821078
if not manifest_path.is_file():
10831079
print(f"Manifest not found: {args.manifest}", file=sys.stderr)

tests/test_cli_import.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ class TestImportFiles:
130130

131131
def test_import_files_basic(self, tmp_path):
132132
db = tmp_path / "test.db"
133+
subprocess.run(
134+
[sys.executable, "-m", "farchive._cli", "init", str(db)], check=True
135+
)
133136
root = tmp_path / "files"
134137
root.mkdir()
135138
(root / "a.txt").write_bytes(b"content a")
@@ -152,6 +155,9 @@ def test_import_files_basic(self, tmp_path):
152155

153156
def test_import_files_dry_run(self, tmp_path):
154157
db = tmp_path / "test.db"
158+
subprocess.run(
159+
[sys.executable, "-m", "farchive._cli", "init", str(db)], check=True
160+
)
155161
root = tmp_path / "files"
156162
root.mkdir()
157163
(root / "a.txt").write_bytes(b"content")
@@ -172,6 +178,9 @@ def test_import_files_dry_run(self, tmp_path):
172178

173179
def test_import_files_recursive(self, tmp_path):
174180
db = tmp_path / "test.db"
181+
subprocess.run(
182+
[sys.executable, "-m", "farchive._cli", "init", str(db)], check=True
183+
)
175184
root = tmp_path / "files"
176185
root.mkdir()
177186
(root / "sub").mkdir()
@@ -194,6 +203,9 @@ def test_import_files_recursive(self, tmp_path):
194203

195204
def test_import_files_storage_class_by_ext(self, tmp_path):
196205
db = tmp_path / "test.db"
206+
subprocess.run(
207+
[sys.executable, "-m", "farchive._cli", "init", str(db)], check=True
208+
)
197209
root = tmp_path / "files"
198210
root.mkdir()
199211
(root / "page.html").write_bytes(b"<html></html>")
@@ -230,6 +242,9 @@ class TestImportManifest:
230242

231243
def test_import_manifest_jsonl(self, tmp_path):
232244
db = tmp_path / "test.db"
245+
subprocess.run(
246+
[sys.executable, "-m", "farchive._cli", "init", str(db)], check=True
247+
)
233248
root = tmp_path / "files"
234249
root.mkdir()
235250
(root / "a.txt").write_bytes(b"content a")
@@ -252,6 +267,9 @@ def test_import_manifest_jsonl(self, tmp_path):
252267

253268
def test_import_manifest_dry_run(self, tmp_path):
254269
db = tmp_path / "test.db"
270+
subprocess.run(
271+
[sys.executable, "-m", "farchive._cli", "init", str(db)], check=True
272+
)
255273
root = tmp_path / "files"
256274
root.mkdir()
257275
(root / "a.txt").write_bytes(b"content")

0 commit comments

Comments
 (0)