canonical / pebble

Pebble is a lightweight Linux service manager with layered configuration and an HTTP API.
https://canonical-pebble.readthedocs-hosted.com/
GNU General Public License v3.0
146 stars 54 forks source link

feat(cli): add RunOptions to cli.Run, remove global variable #383

Closed thp-canonical closed 6 months ago

thp-canonical commented 6 months ago

The goal of this PR is to allow full customization of the client.Config (including its Socket, BaseURL and UserAgent members) for callers of cli.Run(). This is achieved by adding a RunOptions struct as argument to cli.Run().

The clientConfig global variable isn't accessed by any non-test code, so it can be removed.


Additional information about test-related changes:

The global variable WAS used in tests (as ClientConfig, in internals/cli/cli_test.go: cli.ClientConfig.BaseURL = server.URL), but since all tests use cli.RunMain() (which is defined in cli/export_test.go) instead of cli.Run(), we can just define the global variable for the tests only, and make RunMain use that config object by calling Run with the test ClientConfig.

benhoyt commented 6 months ago

Let's get @flotter's second eye on this final version, but I'm happy for this to go in -- thanks.