Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Break out CLI functionality to make it modular + --line flag #454

Merged
merged 1 commit into from
Jul 17, 2024

Conversation

brandur
Copy link
Contributor

@brandur brandur commented Jul 14, 2024

Here, break out the CLI so that most of its implementation no longer
lives in a main.go, and rather in a subpackage that can be imported
from somewhere else. This lets the majority of it to be reused in
another executable and augmented in various ways.

An addition is a new DriverProcurer interface that can provide a
driver for various databases:

type DriverProcurer interface {
    ProcurePgxV5(pool *pgxpool.Pool) riverdriver.Driver[pgx.Tx]
}

For the main CLI, this gets a trivial implementation using riverpgxv5,
but could potentially be reimplemented elsewhere to swap in something
else;

type DriverProcurer struct{}

func (p *DriverProcurer) ProcurePgxV5(pool *pgxpool.Pool) riverdriver.Driver[pgx.Tx] {
        return riverpgxv5.New(pool)
}

To make this more workable, I end up going through and refactoring quite
a lot of code, making it into a bit of a mini framework, and one that
could potentially support additional databases in the future without
having to refactor the world again.

We also add a --line flag to support the feature from #435 to the CLI.

@brandur brandur force-pushed the brandur-cli-breakout branch 2 times, most recently from d571742 to 3b4154b Compare July 14, 2024 17:25
@brandur brandur requested a review from bgentry July 14, 2024 17:28
@brandur brandur force-pushed the brandur-cli-breakout branch 2 times, most recently from 6816524 to 3f6ed01 Compare July 14, 2024 17:44
Here, break out the CLI so that most of its implementation no longer
lives in a `main.go`, and rather in a subpackage that can be imported
from somewhere else. This lets the majority of it to be reused in
another executable and augmented in various ways.

An addition is a new `DriverProcurer` interface that can provide a
driver for various databases:

    type DriverProcurer interface {
        ProcurePgxV5(pool *pgxpool.Pool) riverdriver.Driver[pgx.Tx]
    }

For the main CLI, this gets a trivial implementation using `riverpgxv5`,
but could potentially be reimplemented elsewhere to swap in something
else;

    type DriverProcurer struct{}

    func (p *DriverProcurer) ProcurePgxV5(pool *pgxpool.Pool) riverdriver.Driver[pgx.Tx] {
            return riverpgxv5.New(pool)
    }

To make this more workable, I end up going through and refactoring quite
a lot of code, making it into a bit of a mini framework, and one that
could potentially support additional databases in the future without
having to refactor the world again.

We also add a `--line` flag to support the feature from #435 to the CLI.
@brandur brandur force-pushed the brandur-cli-breakout branch from 3f6ed01 to 007f941 Compare July 14, 2024 17:44
@brandur
Copy link
Contributor Author

brandur commented Jul 17, 2024

Awesome. Ty.

@brandur brandur merged commit f81dcd7 into master Jul 17, 2024
10 checks passed
@brandur brandur deleted the brandur-cli-breakout branch July 17, 2024 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants