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

feat(cli): enable extended client access #285

Merged
merged 8 commits into from
Aug 25, 2023

Conversation

anpep
Copy link
Collaborator

@anpep anpep commented Aug 21, 2023

This patch gets rid of the clientMixin in command structs in favor of passing a CmdOptions struct to the New (formerly Builder) function in CmdInfo.

Example usage:

Command implementation

type cmdFoo struct {
        /* ... */
	client *MyClient
}

func init() {
	AddCommand(&CmdInfo{
		/* ... */
		New: func(opts *CmdOptions) flags.Commander {
			return &cmdFoo{client: &MyClient{opts.Client}}
		},
	})
}

func (cmd *cmdFoo) Execute(args []string) error {
        return cmd.client.Foo()
}

Client implementation

import "github.com/canonical/pebble/client"

type MyClient struct {
        *client.Client
}

func (c *MyClient) Foo() error {
        /* ... */
}

@anpep anpep requested review from flotter and benhoyt August 21, 2023 22:37
@anpep anpep self-assigned this Aug 21, 2023
Copy link
Contributor

@benhoyt benhoyt left a comment

Choose a reason for hiding this comment

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

Just a comment about the name.

I'd be fine with this. However, are you able to link to the previous discussion where I pushed back on the whole concept of the clientMixin? I can't find that right now, and I'm interesting in going back over my thoughts.

internals/cli/cli.go Outdated Show resolved Hide resolved
@anpep anpep changed the title cli: Export clientSetter as ClientInitializer. feat(cli): allow commands to access extended client instances Aug 23, 2023
@anpep anpep changed the title feat(cli): allow commands to access extended client instances feat(cli): enable commands to access extended client instances Aug 23, 2023
@anpep anpep marked this pull request as ready for review August 23, 2023 10:45
Copy link
Contributor

@paul-rodriguez paul-rodriguez left a comment

Choose a reason for hiding this comment

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

I prefer the new naming.

This will allow commands to get a Pebble client instance through the command struct constructor.
Copy link
Contributor

@flotter flotter left a comment

Choose a reason for hiding this comment

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

Looks great. Few super nitty questions / comments.

internals/cli/cli.go Outdated Show resolved Hide resolved
internals/cli/cli.go Show resolved Hide resolved
internals/cli/cli.go Show resolved Hide resolved
internals/cli/cmd_add.go Outdated Show resolved Hide resolved
internals/cli/cmd_run.go Show resolved Hide resolved
internals/cli/cmd_services.go Outdated Show resolved Hide resolved
@flotter flotter self-requested a review August 24, 2023 12:22
@anpep anpep changed the title feat(cli): enable commands to access extended client instances feat(cli): enable extended client access Aug 24, 2023
Copy link
Contributor

@paul-rodriguez paul-rodriguez left a comment

Choose a reason for hiding this comment

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

Great job !

internals/cli/wait.go Outdated Show resolved Hide resolved
@flotter flotter mentioned this pull request Aug 24, 2023
Copy link
Contributor

@benhoyt benhoyt left a comment

Choose a reason for hiding this comment

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

Yeah, I like this -- it's a tiny bit more verbose, but it seems much more direct and Go-like than the "mixin" concept.

Copy link
Contributor

@niemeyer niemeyer left a comment

Choose a reason for hiding this comment

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

This turned out very well, thank you. Only minor comments below and LGTM with these considered.

internals/cli/cli.go Outdated Show resolved Hide resolved
internals/cli/cli.go Outdated Show resolved Hide resolved
internals/cli/cli.go Outdated Show resolved Hide resolved
internals/cli/cmd_add.go Outdated Show resolved Hide resolved
internals/cli/cmd_autostart.go Show resolved Hide resolved
internals/cli/cmd_run.go Show resolved Hide resolved
internals/cli/cmd_services.go Outdated Show resolved Hide resolved
@flotter
Copy link
Contributor

flotter commented Aug 25, 2023

Discussed final state with Gustavo and got go-ahead to merge.

@flotter flotter merged commit d594346 into canonical:master Aug 25, 2023
13 checks passed
@benhoyt benhoyt mentioned this pull request Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority Look at me first
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants