@@ -57,7 +57,6 @@ data class DiscoveredDatabase(
5757 val name : String ,
5858 val size : Long ,
5959 val lastModified : Long ,
60- val isLocal : Boolean = false , // Whether it's in the current working directory
6160)
6261
6362@Command(
@@ -88,7 +87,6 @@ internal class DbStudioCommand : AbstractSubcommand<ToolState, CommandContext>()
8887 name = name,
8988 size = fileSize(),
9089 lastModified = getLastModifiedTime().toMillis(),
91- isLocal = true ,
9290 )
9391 }.getOrNull()
9492
@@ -107,13 +105,13 @@ internal class DbStudioCommand : AbstractSubcommand<ToolState, CommandContext>()
107105 }
108106 }.getOrElse { emptyList() }
109107
110- private fun discoverDatabases (): List <DiscoveredDatabase > {
111- val cwd = Path .of(System .getProperty(" user.dir" ))
108+ private fun discoverDatabases (baseDir : Path ? = null ): List <DiscoveredDatabase > {
109+ val searchDir = baseDir ? : Path .of(System .getProperty(" user.dir" ))
112110
113111 // Search current directory and immediate subdirectories
114- val currentDir = searchDirectory(cwd , depth = 0 , maxDepth = 0 )
112+ val currentDir = searchDirectory(searchDir , depth = 0 , maxDepth = 0 )
115113 val subDirs = runCatching {
116- cwd .listDirectoryEntries()
114+ searchDir .listDirectoryEntries()
117115 .filter { it.isDirectory() }
118116 .flatMap { searchDirectory(it, depth = 1 , maxDepth = 1 ) }
119117 }.getOrElse { emptyList() }
@@ -144,7 +142,7 @@ internal class DbStudioCommand : AbstractSubcommand<ToolState, CommandContext>()
144142
145143 @Parameters(
146144 index = " 0" ,
147- description = [" Path to SQLite database file" ],
145+ description = [" Path to SQLite database file or directory for discovery " ],
148146 arity = " 0..1" ,
149147 paramLabel = " DATABASE_PATH" ,
150148 )
@@ -203,22 +201,38 @@ internal class DbStudioCommand : AbstractSubcommand<ToolState, CommandContext>()
203201
204202 discovered
205203 } else {
206- val dbFile = Path .of(databasePath!! )
204+ val dbPath = Path .of(databasePath!! )
207205
208- if (! dbFile .exists()) {
209- return CommandResult .err(message = " Database file not found: $databasePath " )
206+ if (! dbPath .exists()) {
207+ return CommandResult .err(message = " Path not found: $databasePath " )
210208 }
211209
212- // Create a single-item list with the specified database
213- listOf (
214- DiscoveredDatabase (
215- path = dbFile.toAbsolutePath().toString(),
216- name = dbFile.name,
217- size = dbFile.fileSize(),
218- lastModified = dbFile.getLastModifiedTime().toMillis(),
219- isLocal = true ,
220- )
221- )
210+ when {
211+ // If it's a directory, discover databases within it
212+ dbPath.isDirectory() -> {
213+ val discovered = discoverDatabases(dbPath)
214+
215+ if (discovered.isEmpty()) {
216+ return CommandResult .err(message = " No SQLite databases found in directory: $databasePath " )
217+ }
218+
219+ discovered
220+ }
221+ // If it's a file, use it as a single database
222+ dbPath.isRegularFile() -> {
223+ listOf (
224+ DiscoveredDatabase (
225+ path = dbPath.toAbsolutePath().toString(),
226+ name = dbPath.name,
227+ size = dbPath.fileSize(),
228+ lastModified = dbPath.getLastModifiedTime().toMillis(),
229+ )
230+ )
231+ }
232+ else -> {
233+ return CommandResult .err(message = " Path must be a file or directory: $databasePath " )
234+ }
235+ }
222236 }
223237
224238 // Generate config.ts with port and databases
0 commit comments