1
0
mirror of https://github.com/joshuarubin/go-sway synced 2024-11-22 21:11:59 +01:00

add ability to set sway socket explicitly

This commit is contained in:
Joshua Rubin 2019-04-15 09:57:48 -06:00
parent b11e8903a3
commit 06cea6451d
No known key found for this signature in database
GPG Key ID: 673103A1CC175722

@ -62,11 +62,30 @@ type Client interface {
GetSeats(context.Context) ([]Seat, error) GetSeats(context.Context) ([]Seat, error)
} }
// Option can be passed to New to specify runtime configuration settings
type Option func(*client)
// WithSocketPath explicitly sets the sway socket path so it isn't read from
// $SWAYSOCK
func WithSocketPath(socketPath string) Option {
return func(c *client) {
c.path = socketPath
}
}
// New returns a Client configured to connect to $SWAYSOCK // New returns a Client configured to connect to $SWAYSOCK
func New(ctx context.Context) (_ Client, err error) { func New(ctx context.Context, opts ...Option) (_ Client, err error) {
c := &client{} c := &client{}
if c.path = strings.TrimSpace(os.Getenv("SWAYSOCK")); c.path == "" { for _, opt := range opts {
opt(c)
}
if c.path == "" {
c.path = strings.TrimSpace(os.Getenv("SWAYSOCK"))
}
if c.path == "" {
return nil, fmt.Errorf("$SWAYSOCK is empty") return nil, fmt.Errorf("$SWAYSOCK is empty")
} }