-
Notifications
You must be signed in to change notification settings - Fork 56
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
Refactor Pebble internals into an exportable package #226
Conversation
The `internal` package name is special in Go: it makes the package non-importable. We rename it to `internals` so that we can import it from other software while conveying the idea of it being of internal use.
The `main` package is special in Go: it is reserved for the package containing a `main()` function that serves as the entry point for the program and it can't be imported. This commit refactors all command-line functionality that will be shared by other software into the `internals/cli` package, which will be imported and used by the `main()` function to invoke the Pebble command-line interface.
@@ -0,0 +1,431 @@ | |||
// Copyright (c) 2014-2020 Canonical Ltd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to other reviewers: This file is a verbatim copy from everything that did not stay in cmd/pebble/main.go
above. The main difference is the deferred recovery()
hook is now moved one level up into Run()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the helpful observation.
LGTM. Two minor corrections I think. |
Can you show how you would actually create a new binary that adds (or removes) commands? Is the intention to rewrite It also seems to me different binaries might want to have different subsets of commands, that is, to remove existing Pebble commands. And currently all the What about having an explicit list in func main() {
cli.AddCommand(cli.Add)
cli.AddCommand(cli.Autostart)
cli.AddCommand(cli.Changes)
/* ... add other commands ... */
cli.AddCommand(cli.CmdInfo{ // add our custom command defined here
Name: "custom",
ShortHelp: "short help",
LongHelp: "long help",
Builder: func() flags.Commander { return &cmdCustom{} },
OptDescs: customDescs,
}
})
cli.Run() // error handling omitted
} We'd also need to rework how to generate the help categories a bit, to make that adjustable. |
A couple of other things:
|
I have a working implementation of this which basically exports
I think you have a valid point here; however, I'm not sure removing "core" functionality from Pebble is a desired feature, actually, the aim is quite the opposite: to move functionality that's not common to all Pebble stakeholders out of the upstream Pebble repository and extend it in other applications (currently with Termus specifically in mind).
I will try to make a proposal tomorrow and gather feedback from Gustavo before going down this rabbit hole (: But this seems like a sensible option we can discuss and evolve over time.
I think this is the way to go, since we might need access to e.g. With this in mind, it makes sense for the
Naming this package has proven to be very tricky, but after some discussion, Gustavo suggested As always, really appreciate your feedback! |
@anpep All fair enough, thanks! Naming is hard. :-) |
Thanks for the nice review, @benhoyt. As Ángel points out, the close proximity with "internal" is intentional here. Idelly we want people to feel exactly the same way about both, as for now there's a single exception that we'll be respecting. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks good, Ángel, thank you. Just one trivial comment for consideration in the future.
This merge will likely break most open PRs, unfortunately, but there's no way around it.
"github.com/canonical/pebble/client" | ||
) | ||
|
||
var RunMain = run | ||
var RunMain = Run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need this?
This PR guides Pebble towards an internal structure that enables us to create Pebble-based applications that implement custom commands and add functionality that is not relevant to the upstream Pebble repository. However, we don't want to create a full-blown fork of Pebble and have the maintenance burden of having to port changes from upstream to every fork; for this reason, this PR does two things:
internal
package tointernals
so that it can be imported by other Pebble-based applications.main
package to theinternals/cli
package, so that other Pebble-based applications can import this package without having to reimplement this functionality.This PR does not intend to be exhaustive and instead aims to serve as the groundwork for achieving the described goal. Thanks for your reviews!