2026-06-23 23:54:37 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
"""ctxd module entry point — CLI when args given, daemon otherwise."""
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
if len(sys.argv) > 1 and sys.argv[1] in ('init', 'serve', 'project-list', 'project-create',
|
|
|
|
|
'read', 'cat', 'edit', 'search', 'sync', 'audit',
|
2026-06-25 00:20:55 +00:00
|
|
|
'user-list', 'user-create', 'import-vault',
|
|
|
|
|
'user-set-password', 'oauth-client-create',
|
|
|
|
|
'oauth-client-list', 'oauth-client-revoke',
|
|
|
|
|
'file-list', 'file-read'):
|
2026-06-23 23:54:37 +00:00
|
|
|
from ctxd.cli import cli_entry
|
|
|
|
|
cli_entry()
|
|
|
|
|
else:
|
|
|
|
|
from ctxd.config import CtxConfig
|
|
|
|
|
from ctxd.server import serve_sync
|
|
|
|
|
|
|
|
|
|
cfg = CtxConfig.from_home()
|
2026-06-25 00:20:55 +00:00
|
|
|
# When using PostgreSQL, the DB is external — skip the file check.
|
|
|
|
|
# When using SQLite, verify the db file exists.
|
|
|
|
|
if not cfg.use_postgres and not cfg.db_path.exists():
|
2026-06-23 23:54:37 +00:00
|
|
|
print("Not initialized. Run 'ctx init' first.", file=sys.stderr)
|
|
|
|
|
sys.exit(1)
|
|
|
|
|
serve_sync(cfg)
|