Skip to content

Refactor CLI out of main.go into app module#208

Merged
liam-lowe merged 1 commit intomainfrom
liam-lowe/cli-refactor
Apr 2, 2026
Merged

Refactor CLI out of main.go into app module#208
liam-lowe merged 1 commit intomainfrom
liam-lowe/cli-refactor

Conversation

@liam-lowe
Copy link
Copy Markdown
Contributor

@liam-lowe liam-lowe commented Apr 2, 2026

What was changed

Refactors cli out of main.go into its own module - and adds tests.

Why?

Configurability & testability.

Comment on lines +21 to +24
type proxyRunner interface {
Start() error
Stop()
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't a fan of the: func interruptCh() <-chan interface{} {

I've opted for a lifecycle interface + context prop in an attempt to be more graceful and idiomatic.

type CLI struct {
name string
version string
extraOpts []fx.Option
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

supports DI configuration if needed.


const (
DefaultName = "s2s-proxy"
DefaultVersion = "0.0.1" // TODO: configure build-time injection of version.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will follow-up this PR with proper release tagging & version gha improvements.

Comment on lines 12 to 20
func main() {
if err := run(os.Args); err != nil {
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()

// TODO: configure build-time injection of version.
if err := cli.New(cli.DefaultName, cli.DefaultVersion).Run(ctx, os.Args); err != nil {
panic(err)
}
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simplified main.go!

@liam-lowe liam-lowe marked this pull request as ready for review April 2, 2026 00:29
@liam-lowe liam-lowe requested a review from a team as a code owner April 2, 2026 00:29
defer stop()

// TODO: configure build-time injection of version.
if err := cli.New(cli.DefaultName, cli.DefaultVersion).Run(ctx, os.Args); err != nil {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would app be a better module name instead of cli because this package is doing more than argument parsing. It wires the app, builds the Fx graph, etc.

cli/cli.go Outdated
Stop()
}

type CLI struct {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably name it as App to for the same reason of renaming the module to app.

@liam-lowe liam-lowe force-pushed the liam-lowe/cli-refactor branch from 9b55879 to 91776ee Compare April 2, 2026 19:08
@liam-lowe liam-lowe changed the title Refactor CLI into module Refactor CLI out of main.go into app module Apr 2, 2026
@liam-lowe liam-lowe merged commit 807895a into main Apr 2, 2026
5 checks passed
@liam-lowe liam-lowe deleted the liam-lowe/cli-refactor branch April 2, 2026 19:19
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