|
| 1 | +package elide.tool.cli.cmd.db |
| 2 | + |
| 3 | +import io.micronaut.core.annotation.Introspected |
| 4 | +import io.micronaut.core.annotation.ReflectiveAccess |
| 5 | +import picocli.CommandLine.Command |
| 6 | +import picocli.CommandLine.Option |
| 7 | +import elide.tool.cli.CommandContext |
| 8 | +import elide.tool.cli.CommandResult |
| 9 | +import elide.tool.cli.ProjectAwareSubcommand |
| 10 | +import elide.tool.cli.ToolState |
| 11 | + |
| 12 | +@Command( |
| 13 | + name = "db", |
| 14 | + description = ["Database tools for Elide projects."], |
| 15 | + mixinStandardHelpOptions = true, |
| 16 | + subcommands = [DbStudioCommand::class], |
| 17 | +) |
| 18 | +@Introspected |
| 19 | +@ReflectiveAccess |
| 20 | +internal class DbCommand : ProjectAwareSubcommand<ToolState, CommandContext>() { |
| 21 | + override suspend fun CommandContext.invoke(state: ToolContext<ToolState>): CommandResult { |
| 22 | + return err("`elide db` requires a subcommand (try: studio)") |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +@Command( |
| 27 | + name = "studio", |
| 28 | + description = ["Launch database UI for SQLite databases"], |
| 29 | + mixinStandardHelpOptions = true, |
| 30 | +) |
| 31 | +@Introspected |
| 32 | +@ReflectiveAccess |
| 33 | +internal class DbStudioCommand : ProjectAwareSubcommand<ToolState, CommandContext>() { |
| 34 | + |
| 35 | + @Option( |
| 36 | + names = ["--port", "-p"], |
| 37 | + description = ["Port to run the database UI on"], |
| 38 | + defaultValue = "4983", |
| 39 | + ) |
| 40 | + internal var port: Int = 4983 |
| 41 | + |
| 42 | + @Option( |
| 43 | + names = ["--host"], |
| 44 | + description = ["Host to bind the database UI to"], |
| 45 | + defaultValue = "localhost", |
| 46 | + ) |
| 47 | + internal var host: String = "localhost" |
| 48 | + |
| 49 | + override suspend fun CommandContext.invoke(state: ToolContext<ToolState>): CommandResult { |
| 50 | + output { |
| 51 | + append("Starting database UI on http://$host:$port") |
| 52 | + } |
| 53 | + |
| 54 | + // TODO |
| 55 | + |
| 56 | + return success() |
| 57 | + } |
| 58 | +} |
0 commit comments