Skip to content

Commit b8cf7fa

Browse files
committed
Order backends alphabetically
1 parent 6a484d0 commit b8cf7fa

2 files changed

Lines changed: 54 additions & 21 deletions

File tree

src/entity_manager/cli.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
from entity_manager.backends.beads import BeadsBackend
1111
from entity_manager.backends.github import GitHubBackend
1212
from entity_manager.backends.markdown import MarkdownBackend
13+
from entity_manager.backends.notion import NotionBackend
14+
from entity_manager.backends.redis import RedisBackend
1315
from entity_manager.backends.sqlite import SQLiteBackend
1416
from entity_manager.config import get_config
1517
from entity_manager.config_commands import config_app, init
@@ -55,12 +57,26 @@ def get_backend() -> Backend:
5557
" em config set github.repository <repo>"
5658
)
5759
return GitHubBackend(owner=owner, repo=repo, token=token)
58-
elif backend_type == "beads":
59-
project_path = config.get("beads.project_path")
60-
return BeadsBackend(project_path=project_path)
6160
elif backend_type == "markdown":
6261
directory_path = config.get("markdown.directory_path", ".")
6362
return MarkdownBackend(directory_path=directory_path)
63+
elif backend_type == "notion":
64+
token = config.get("notion.token")
65+
database_id = config.get("notion.database_id")
66+
67+
if not token or not database_id:
68+
raise ValueError(
69+
"Notion token and database ID not configured. Set them using:\n"
70+
" em config set notion.token <token> --global\n"
71+
" em config set notion.database_id <database_id>"
72+
)
73+
return NotionBackend(token=token, database_id=database_id)
74+
elif backend_type == "redis":
75+
host = config.get("redis.host", "localhost")
76+
port = int(config.get("redis.port", "6379"))
77+
db = int(config.get("redis.db", "0"))
78+
password = config.get("redis.password")
79+
return RedisBackend(host=host, port=port, db=db, password=password)
6480
elif backend_type == "sqlite":
6581
db_path = config.get("sqlite.db_path")
6682
return SQLiteBackend(db_path=db_path)

src/entity_manager/config_commands.py

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ def init(global_: bool = False) -> None:
114114

115115
console.print("\n[bold]Entity Manager Configuration[/bold]")
116116
console.print("Select the backend to use", style="dim")
117-
console.print("Available backends: backlog, beads, github, markdown, notion, sqlite", style="dim")
117+
console.print("Available backends: backlog, beads, github, markdown, notion, redis, sqlite", style="dim")
118118

119-
valid_backends = ["backlog", "beads", "github", "markdown", "notion", "sqlite"]
119+
valid_backends = ["backlog", "beads", "github", "markdown", "notion", "redis", "sqlite"]
120120
backend = None
121121
existing_backend = cfg.get("backend")
122122

@@ -131,7 +131,19 @@ def init(global_: bool = False) -> None:
131131

132132
config.set("backend", backend)
133133

134-
if backend == "github":
134+
if backend == "backlog":
135+
existing_path = cfg.get("backlog.path")
136+
path = Prompt.ask("Backlog.md path", default=existing_path or "")
137+
if path:
138+
config.set("backlog.path", path)
139+
140+
elif backend == "beads":
141+
existing_path = cfg.get("beads.project_path")
142+
project_path = Prompt.ask("Beads project path", default=existing_path or "")
143+
if project_path:
144+
config.set("beads.project_path", project_path)
145+
146+
elif backend == "github":
135147
existing_owner = cfg.get("github.owner")
136148
owner = Prompt.ask("GitHub owner", default=existing_owner or "")
137149
if owner:
@@ -146,11 +158,10 @@ def init(global_: bool = False) -> None:
146158
if token:
147159
config.set("github.token", token)
148160

149-
elif backend == "beads":
150-
existing_path = cfg.get("beads.project_path")
151-
project_path = Prompt.ask("Beads project path", default=existing_path or "")
152-
if project_path:
153-
config.set("beads.project_path", project_path)
161+
elif backend == "markdown":
162+
existing_path = cfg.get("markdown.directory_path")
163+
directory_path = Prompt.ask("Markdown directory path", default=existing_path or ".")
164+
config.set("markdown.directory_path", directory_path)
154165

155166
elif backend == "notion":
156167
token = Prompt.ask("Notion token", password=True, default="")
@@ -162,23 +173,29 @@ def init(global_: bool = False) -> None:
162173
if database_id:
163174
config.set("notion.database_id", database_id)
164175

165-
elif backend == "backlog":
166-
existing_path = cfg.get("backlog.path")
167-
path = Prompt.ask("Backlog.md path", default=existing_path or "")
168-
if path:
169-
config.set("backlog.path", path)
176+
elif backend == "redis":
177+
existing_host = cfg.get("redis.host")
178+
host = Prompt.ask("Redis host", default=existing_host or "localhost")
179+
config.set("redis.host", host)
180+
181+
existing_port = cfg.get("redis.port")
182+
port = Prompt.ask("Redis port", default=existing_port or "6379")
183+
config.set("redis.port", port)
184+
185+
existing_db = cfg.get("redis.db")
186+
db = Prompt.ask("Redis database number", default=existing_db or "0")
187+
config.set("redis.db", db)
188+
189+
password = Prompt.ask("Redis password (leave empty if none)", password=True, default="")
190+
if password:
191+
config.set("redis.password", password)
170192

171193
elif backend == "sqlite":
172194
existing_path = cfg.get("sqlite.db_path")
173195
db_path = Prompt.ask("SQLite database path", default=existing_path or ".em.db")
174196
if db_path:
175197
config.set("sqlite.db_path", db_path)
176198

177-
elif backend == "markdown":
178-
existing_path = cfg.get("markdown.directory_path")
179-
directory_path = Prompt.ask("Markdown directory path", default=existing_path or ".")
180-
config.set("markdown.directory_path", directory_path)
181-
182199
else:
183200
console.print(f"Unknown backend: {backend}", style="red")
184201
return

0 commit comments

Comments
 (0)