Skip to content

Commit c19b809

Browse files
Filip Ristevskiclaude
andcommitted
feat: add :init command and first-run guidance for reviewers
- Add _db_ready() helper to check if vault.db exists and is accessible - On first use (no DB), show a setup-required message guiding users to type cv :init - cv :init keyword creates the database and loads 150+ built-in commands directly from Flow Launcher - If DB already exists, cv :init shows a friendly 'already initialized' message - Removes the need for users to manually run db_init.py outside of Flow Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent cbefa23 commit c19b809

File tree

1 file changed

+76
-1
lines changed

1 file changed

+76
-1
lines changed

main.py

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ def _icon(row) -> str:
5151
return ICON
5252

5353

54+
def _db_ready() -> bool:
55+
"""Return True if the vault database exists and the commands table is accessible."""
56+
if not os.path.exists(DB_PATH):
57+
return False
58+
try:
59+
with _db() as con:
60+
con.execute("SELECT 1 FROM commands LIMIT 1")
61+
return True
62+
except sqlite3.Error:
63+
return False
64+
65+
5466
def _fts_ok(con: sqlite3.Connection) -> bool:
5567
try:
5668
con.execute("SELECT 1 FROM commands_fts LIMIT 1")
@@ -236,8 +248,53 @@ def _toggle_favorite(cmd_id: int) -> None:
236248
class CommandVault(FlowLauncher):
237249

238250
def query(self, query: str) -> list[dict[str, Any]]:
251+
q = query.strip()
252+
253+
# Special command: initialize the database
254+
if q in (":init", ":setup", ":initialize"):
255+
if _db_ready():
256+
return [
257+
{
258+
"Title": "\u2713 Command Vault is already initialized",
259+
"SubTitle": f"Database ready at {DB_PATH} \u00b7 Use :manage to add commands",
260+
"IcoPath": ICON,
261+
"JsonRPCAction": {
262+
"method": "noop",
263+
"parameters": [],
264+
"dontHideAfterAction": True,
265+
},
266+
}
267+
]
268+
return [
269+
{
270+
"Title": "\u2699 Initialize Command Vault",
271+
"SubTitle": "Press Enter to create the database and load 150+ built-in commands (Cisco, Linux, Proxmox, Ansible)",
272+
"IcoPath": ICON,
273+
"JsonRPCAction": {
274+
"method": "run_init",
275+
"parameters": [],
276+
"dontHideAfterAction": False,
277+
},
278+
}
279+
]
280+
281+
# Database not yet initialized — guide the user
282+
if not _db_ready():
283+
return [
284+
{
285+
"Title": "\u2699 Command Vault — First-time setup required",
286+
"SubTitle": "Type cv :init and press Enter to create the database and load built-in commands",
287+
"IcoPath": ICON,
288+
"JsonRPCAction": {
289+
"method": "noop",
290+
"parameters": [],
291+
"dontHideAfterAction": True,
292+
},
293+
}
294+
]
295+
239296
# Special command: open the GUI manager
240-
if query.strip() in (":manage", ":manager", ":edit", ":gui"):
297+
if q in (":manage", ":manager", ":edit", ":gui"):
241298
return [
242299
{
243300
"Title": "Open Command Vault Manager",
@@ -375,6 +432,24 @@ def open_manager(self) -> None:
375432
creationflags=subprocess.DETACHED_PROCESS,
376433
)
377434

435+
def run_init(self) -> None:
436+
import db_init as _db_init
437+
try:
438+
_db_init.init_db(drop_existing=False)
439+
try:
440+
self.show_msg(
441+
"\u2713 Vault ready!",
442+
"Database created with 150+ built-in commands. Start typing to search.",
443+
ICON,
444+
)
445+
except Exception:
446+
pass
447+
except Exception as e:
448+
try:
449+
self.show_msg("\u2717 Init failed", str(e), ICON)
450+
except Exception:
451+
pass
452+
378453
def noop(self) -> None:
379454
pass
380455

0 commit comments

Comments
 (0)