Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
hubvd committed Sep 17, 2024
1 parent 799bceb commit 68ca9e7
Show file tree
Hide file tree
Showing 33 changed files with 119 additions and 94 deletions.
6 changes: 3 additions & 3 deletions actions/src/Actions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal val ACTION_MODULE by DI.Module {

bind<NotificationService> {
singleton {
instance<Terminal>().takeIf { it.info.outputInteractive }
instance<Terminal>().takeIf { it.terminalInfo.outputInteractive }
?.let { TerminalNotificationService(it) }
?: SystemNotificationService()
}
Expand Down Expand Up @@ -111,8 +111,8 @@ private fun getFormattedHelp(error: CliktError, rootCommand: CliktCommand, symli
.joinToString(" ")
return ctx.helpFormatter(ctx).formatHelp(
error as? UsageError,
command.commandHelp(ctx),
command.commandHelpEpilog(ctx),
command.help(ctx),
command.helpEpilog(ctx),
command.allHelpParams(),
programName,
)
Expand Down
7 changes: 4 additions & 3 deletions actions/src/commands/AttachCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.github.hubvd.odootools.actions.commands
import com.github.ajalt.clikt.core.Abort
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.CliktError
import com.github.ajalt.clikt.core.Context
import com.github.hubvd.odootools.actions.utils.Odooctl
import com.github.hubvd.odootools.actions.utils.selectInstance
import org.http4k.core.HttpHandler
Expand All @@ -12,9 +13,9 @@ import org.http4k.core.Request
class AttachCommand(
private val odooctl: Odooctl,
private val httpHandler: HttpHandler,
) : CliktCommand(
help = "Attach the selected odoo instances to a remote debugger",
) {
) : CliktCommand() {
override fun help(context: Context) = "Attach the selected odoo instances to a remote debugger"

override fun run() {
val instances = odooctl.instances()
if (instances.isEmpty()) throw CliktError("No instances running")
Expand Down
6 changes: 3 additions & 3 deletions actions/src/commands/BisectCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.github.hubvd.odootools.actions.commands

import com.github.ajalt.clikt.core.Abort
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.Context
import com.github.ajalt.clikt.core.terminal
import com.github.ajalt.clikt.parameters.options.default
import com.github.ajalt.clikt.parameters.options.option
Expand Down Expand Up @@ -91,9 +92,8 @@ class BisectCommand(
private val runbot: Runbot,
private val workspaces: Workspaces,
private val git: Git,
) : CliktCommand(
help = "Bisect odoo across multiple repositories",
) {
) : CliktCommand() {
override fun help(context: Context) = "Bisect odoo across multiple repositories"

private lateinit var odooLegacyRepository: LegacyRepository
private lateinit var enterpriseLegacyRepository: LegacyRepository
Expand Down
22 changes: 14 additions & 8 deletions actions/src/commands/CheckoutCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,36 @@ package com.github.hubvd.odootools.actions.commands

import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.CliktError
import com.github.ajalt.clikt.core.Context
import com.github.ajalt.clikt.core.terminal
import com.github.ajalt.clikt.parameters.arguments.argument
import com.github.ajalt.clikt.parameters.arguments.defaultLazy
import com.github.ajalt.mordant.terminal.Terminal
import com.github.hubvd.odootools.actions.kitty.Kitty
import com.github.hubvd.odootools.actions.utils.*
import com.github.hubvd.odootools.actions.utils.BranchLookup
import com.github.hubvd.odootools.actions.utils.BranchRef
import com.github.hubvd.odootools.actions.utils.Clipboard
import com.github.hubvd.odootools.actions.utils.NotificationService
import com.github.hubvd.odootools.workspace.Workspaces
import com.github.pgreze.process.Redirect.CAPTURE
import com.github.pgreze.process.Redirect.SILENT
import com.github.pgreze.process.process
import kotlinx.coroutines.*
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.runBlocking
import java.io.File

class CheckoutCommand(
private val workspaces: Workspaces,
private val terminal: Terminal,
private val notificationService: NotificationService,
private val branchLookup: BranchLookup,
private val kitty: Kitty,
) : CliktCommand(
help = "Checkout a pull request from a github url or a commit ref (remote:branch)",
) {
) : CliktCommand() {
override fun help(context: Context) = "Checkout a pull request from a github url or a commit ref (remote:branch)"

private val branch by argument().defaultLazy { Clipboard.read() }

override fun run() {
val terminal = currentContext.terminal
val ref = branchLookup(branch)
?: throw CliktError("Couldn't extract base branch")

Expand All @@ -47,7 +53,7 @@ class CheckoutCommand(
async { fetchAndCheckout(ref, workspace.path.resolve("odoo").toFile()) },
async { fetchAndCheckout(ref, workspace.path.resolve("enterprise").toFile()) },
)
if (!terminal.info.outputInteractive) {
if (!terminal.terminalInfo.outputInteractive) {
kitty.openGit(workspace, odoo, enterprise)
}
}
Expand Down
3 changes: 1 addition & 2 deletions actions/src/commands/KillCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import com.github.ajalt.clikt.parameters.arguments.argument
import com.github.ajalt.clikt.parameters.arguments.optional
import com.github.ajalt.clikt.parameters.options.flag
import com.github.ajalt.clikt.parameters.options.option
import com.github.ajalt.mordant.terminal.Terminal
import com.github.hubvd.odootools.actions.utils.Odooctl
import com.github.hubvd.odootools.actions.utils.selectInstance

class KillCommand(private val odooctl: Odooctl, private val terminal: Terminal) : CliktCommand() {
class KillCommand(private val odooctl: Odooctl) : CliktCommand() {
private val all by option("-a", "--all").flag()
private val database by argument().optional()

Expand Down
7 changes: 4 additions & 3 deletions actions/src/commands/NewCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.github.hubvd.odootools.actions.commands

import com.github.ajalt.clikt.core.Abort
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.Context
import com.github.ajalt.clikt.parameters.arguments.argument
import com.github.ajalt.clikt.parameters.arguments.defaultLazy
import com.github.ajalt.clikt.parameters.arguments.optional
Expand All @@ -18,9 +19,9 @@ class NewCommand(
private val workspaces: Workspaces,
private val notificationService: NotificationService,
private val config: ActionsConfig,
) : CliktCommand(
help = "Create or switch to a branch with the selected id",
) {
) : CliktCommand() {
override fun help(context: Context) = "Create or switch to a branch with the selected id"

private val isSentry by option("-s", "--sentry").flag()
private val id by argument().int().defaultLazy { Clipboard.read().toInt() }
private val description by argument().optional()
Expand Down
11 changes: 6 additions & 5 deletions actions/src/commands/OdooctlCommand.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package com.github.hubvd.odootools.actions.commands

import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.Context
import com.github.ajalt.clikt.core.terminal
import com.github.ajalt.mordant.rendering.TextColors
import com.github.ajalt.mordant.table.Borders
import com.github.ajalt.mordant.table.table
import com.github.ajalt.mordant.terminal.Terminal
import com.github.hubvd.odootools.actions.utils.Odooctl

class OdooctlCommand(private val odooctl: Odooctl, private val terminal: Terminal) : CliktCommand(
help = "List information about running odoo instances",
invokeWithoutSubcommand = true,
) {
class OdooctlCommand(private val odooctl: Odooctl) : CliktCommand() {
override fun help(context: Context) = "List information about running odoo instances"
override val invokeWithoutSubcommand = true

override fun run() {
if (currentContext.invokedSubcommand != null) return

Expand Down
7 changes: 4 additions & 3 deletions actions/src/commands/OpenCommand.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.hubvd.odootools.actions.commands

import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.Context
import com.github.ajalt.clikt.parameters.groups.mutuallyExclusiveOptions
import com.github.ajalt.clikt.parameters.groups.single
import com.github.ajalt.clikt.parameters.options.convert
Expand All @@ -10,9 +11,9 @@ import com.github.hubvd.odootools.actions.utils.BrowserService
import com.github.hubvd.odootools.actions.utils.Odooctl
import com.github.hubvd.odootools.actions.utils.selectInstance

class OpenCommand(private val odooctl: Odooctl, private val browserService: BrowserService) : CliktCommand(
help = "Open the selected odoo instance in a web browser",
) {
class OpenCommand(private val odooctl: Odooctl, private val browserService: BrowserService) : CliktCommand() {
override fun help(context: Context) = "Open the selected odoo instance in a web browser"

private val type by mutuallyExclusiveOptions(
option("-q", "--qunit").flag().convert { Type.QUnit },
option("-h", "--hoot", "-u", "--unit").flag().convert { Type.Hoot },
Expand Down
5 changes: 4 additions & 1 deletion actions/src/commands/OpenerCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.github.hubvd.odootools.actions.commands

import com.github.ajalt.clikt.core.Abort
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.Context
import com.github.ajalt.clikt.parameters.arguments.argument
import com.github.ajalt.clikt.parameters.arguments.defaultLazy
import com.github.ajalt.clikt.parameters.groups.mutuallyExclusiveOptions
Expand All @@ -12,7 +13,9 @@ import com.github.ajalt.clikt.parameters.options.option
import com.github.hubvd.odootools.actions.utils.BrowserService
import com.github.hubvd.odootools.actions.utils.Clipboard

class OpenerCommand(private val browserService: BrowserService) : CliktCommand(help = "Opens a PR/Task") {
class OpenerCommand(private val browserService: BrowserService) : CliktCommand() {
override fun help(context: Context) = "Opens a PR/Task"

private val input by argument().defaultLazy { Clipboard.read(selection = true) }

private val type by mutuallyExclusiveOptions(
Expand Down
7 changes: 4 additions & 3 deletions actions/src/commands/PycharmCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package com.github.hubvd.odootools.actions.commands

import com.github.ajalt.clikt.core.Abort
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.Context
import com.github.ajalt.clikt.parameters.arguments.argument
import com.github.ajalt.clikt.parameters.arguments.multiple
import com.github.hubvd.odootools.actions.utils.Pycharm
import com.github.hubvd.odootools.actions.utils.menu
import com.github.hubvd.odootools.workspace.Workspaces

class PycharmCommand(private val workspaces: Workspaces) : CliktCommand(
help = "Open selected files in Pycharm",
) {
class PycharmCommand(private val workspaces: Workspaces) : CliktCommand() {
override fun help(context: Context) = "Open selected files in Pycharm"

private val paths by argument().multiple()

private val pathRe = "^(?<path>.*?)(?:#(?<line>\\d+)(?::(?<column>\\d+))?)?\$".toRegex()
Expand Down
9 changes: 5 additions & 4 deletions actions/src/commands/QrCommand.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.github.hubvd.odootools.actions.commands

import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.Context
import com.github.ajalt.clikt.core.terminal
import com.github.ajalt.mordant.rendering.*
import com.github.ajalt.mordant.table.grid
import com.github.ajalt.mordant.terminal.Terminal
Expand All @@ -15,12 +17,11 @@ import kotlin.streams.asSequence

private data class Interface(val name: String, val address: Inet4Address)
class QrCommand(
private val terminal: Terminal,
private val odooctl: Odooctl,
private val workspaces: Workspaces,
) : CliktCommand(
help = "Show a QR code pointing to running odoo instances",
) {
) : CliktCommand() {
override fun help(context: Context) = "Show a QR code pointing to running odoo instances"

override fun run() {
val interfaces = NetworkInterface.networkInterfaces()
.asSequence()
Expand Down
10 changes: 5 additions & 5 deletions actions/src/commands/RestoreCommand.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.github.hubvd.odootools.actions.commands

import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.Context
import com.github.ajalt.clikt.core.terminal
import com.github.ajalt.clikt.parameters.arguments.argument
import com.github.ajalt.clikt.parameters.arguments.defaultLazy
import com.github.ajalt.clikt.parameters.groups.mutuallyExclusiveOptions
Expand All @@ -12,7 +14,6 @@ import com.github.ajalt.clikt.parameters.options.validate
import com.github.ajalt.clikt.parameters.types.file
import com.github.ajalt.mordant.animation.progress.animateOnThread
import com.github.ajalt.mordant.animation.progress.execute
import com.github.ajalt.mordant.terminal.Terminal
import com.github.ajalt.mordant.widgets.progress.completed
import com.github.ajalt.mordant.widgets.progress.progressBar
import com.github.ajalt.mordant.widgets.progress.progressBarLayout
Expand Down Expand Up @@ -52,12 +53,11 @@ sealed class DumpSource {
}

class RestoreCommand(
private val terminal: Terminal,
private val dumpPassword: Secret,
private val httpHandler: HttpHandler,
) : CliktCommand(
help = "Restore an odoo database dump, either from a runbot or a zip",
) {
) : CliktCommand() {
override fun help(context: Context) = "Restore an odoo database dump, either from a runbot or a zip"

private val source by mutuallyExclusiveOptions(
option("-z", "--zip").file(mustExist = true, canBeFile = true, canBeDir = false)
.convert { DumpSource.ZipSource(it) }
Expand Down
2 changes: 1 addition & 1 deletion actions/src/commands/db/BaseCopyCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ abstract class BaseCopyCommand(
if (instance != null && window != null) {
restartOdoo(window, instance)
}
if (!terminal.info.interactive) {
if (!terminal.terminalInfo.interactive) {
notificationService.info(notificationMessage(database))
}
}
Expand Down
8 changes: 5 additions & 3 deletions actions/src/commands/pr/ListCommand.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.github.hubvd.odootools.actions.commands.pr

import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.Context
import com.github.ajalt.clikt.core.MissingOption
import com.github.ajalt.clikt.core.PrintMessage
import com.github.ajalt.clikt.core.terminal
import com.github.ajalt.clikt.parameters.arguments.argument
import com.github.ajalt.clikt.parameters.arguments.optional
import com.github.ajalt.clikt.parameters.options.default
Expand All @@ -23,9 +25,9 @@ import com.github.ajalt.mordant.widgets.Text
import com.github.hubvd.odootools.actions.ActionsConfig
import com.github.hubvd.odootools.actions.utils.*

class ListCommand(private val github: GithubClient, private val config: ActionsConfig) : CliktCommand(
help = "List pull requests involved with the selected username",
) {
class ListCommand(private val github: GithubClient, private val config: ActionsConfig) : CliktCommand() {
override fun help(context: Context) = "List pull requests involved with the selected username"

private val closed by option().flag()
private val githubUsername by option().defaultLazy {
config.githubUsernames[odooUsername] ?: throw MissingOption(
Expand Down
7 changes: 4 additions & 3 deletions actions/src/commands/pr/NewCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package com.github.hubvd.odootools.actions.commands.pr
import com.github.ajalt.clikt.core.Abort
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.CliktError
import com.github.ajalt.clikt.core.Context
import com.github.hubvd.odootools.actions.git.currentRepository
import com.github.hubvd.odootools.actions.utils.BrowserService
import com.github.hubvd.odootools.workspace.Workspaces
import kotlin.io.path.name

class NewCommand(private val workspaces: Workspaces, private val browserService: BrowserService) : CliktCommand(
help = "Create a new pr for the current branch in the working directory",
) {
class NewCommand(private val workspaces: Workspaces, private val browserService: BrowserService) : CliktCommand() {
override fun help(context: Context) = "Create a new pr for the current branch in the working directory"

override fun run() {
val workspace = workspaces.current() ?: throw Abort()
val repo = workspace.currentRepository() ?: throw Abort()
Expand Down
5 changes: 4 additions & 1 deletion actions/src/commands/pr/PrCommand.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.github.hubvd.odootools.actions.commands.pr

import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.Context
import com.github.ajalt.clikt.core.NoOpCliktCommand
import com.github.ajalt.clikt.core.subcommands
import org.kodein.di.*

class PrCommand : NoOpCliktCommand(help = "Work with pull requests")
class PrCommand : NoOpCliktCommand() {
override fun help(context: Context) = "Work with pull requests"
}

val PR_COMMAND_MODULE by DI.Module {
bindSet<CliktCommand>(tag = "pr") {
Expand Down
4 changes: 3 additions & 1 deletion actions/src/commands/pycharm/PycharmActions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import kotlin.io.path.Path
* the following should be put in the Arguments input:
* example "$ProjectFileDir$" "$FilePath$" "$LineNumber$" "$ColumnNumber$" $SelectedText$
*/
abstract class BasePycharmAction(name: String? = null) : CliktCommand(name = name, hidden = true) {
abstract class BasePycharmAction(name: String? = null) : CliktCommand(name = name) {
override val hiddenFromHelp = true

protected abstract val workspaces: Workspaces

protected val workspace by argument().convert { option -> workspaces.list().first { it.path == Path(option) } }
Expand Down
7 changes: 4 additions & 3 deletions actions/src/commands/repo/RepoCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package com.github.hubvd.odootools.actions.commands.repo

import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.obj
import com.github.ajalt.clikt.core.registerCloseable
import com.github.ajalt.clikt.core.subcommands
import com.github.ajalt.clikt.parameters.options.flag
Expand Down Expand Up @@ -38,9 +39,9 @@ class WorkspaceRepositories(val workspace: Workspace) : AutoCloseable {

class RepoCommand(
private val workspaces: Workspaces,
) : CliktCommand(
allowMultipleSubcommands = true,
) {
) : CliktCommand() {
override val allowMultipleSubcommands = true

private val all by option("-a", "--all").flag()

override fun run() = runBlocking {
Expand Down
Loading

0 comments on commit 68ca9e7

Please sign in to comment.