mirror of
https://github.com/onyx-and-iris/gobs-cli.git
synced 2026-01-26 15:47:54 +00:00
move obs connection logic into run() so we can exit early when running completion
This commit is contained in:
parent
cbd518ca0f
commit
6e94157c15
23
main.go
23
main.go
@ -123,12 +123,7 @@ func main() {
|
|||||||
}(),
|
}(),
|
||||||
})
|
})
|
||||||
|
|
||||||
client, err := connectObs(cli.ObsConfig)
|
ctx.FatalIfErrorf(run(ctx, cli.ObsConfig, cli.StyleConfig))
|
||||||
ctx.FatalIfErrorf(err)
|
|
||||||
|
|
||||||
ctx.Bind(newContext(client, os.Stdout, cli.StyleConfig))
|
|
||||||
|
|
||||||
ctx.FatalIfErrorf(run(ctx, client))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// connectObs creates a new OBS client and connects to the OBS WebSocket server.
|
// connectObs creates a new OBS client and connects to the OBS WebSocket server.
|
||||||
@ -145,8 +140,18 @@ func connectObs(cfg ObsConfig) (*goobs.Client, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// run executes the command line interface.
|
// run executes the command line interface.
|
||||||
// It disconnects the OBS client after the command is executed.
|
// It connects to the OBS WebSocket server and binds the context to the selected command.
|
||||||
func run(ctx *kong.Context, client *goobs.Client) error {
|
// It also handles the "completion" command separately to avoid unnecessary connections.
|
||||||
|
func run(ctx *kong.Context, obsCfg ObsConfig, styleCfg StyleConfig) error {
|
||||||
|
if ctx.Selected().Name == "completion" {
|
||||||
|
return ctx.Run()
|
||||||
|
}
|
||||||
|
|
||||||
|
client, err := connectObs(obsCfg)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
defer func() error {
|
defer func() error {
|
||||||
if err := client.Disconnect(); err != nil {
|
if err := client.Disconnect(); err != nil {
|
||||||
return fmt.Errorf("failed to disconnect from OBS: %w", err)
|
return fmt.Errorf("failed to disconnect from OBS: %w", err)
|
||||||
@ -154,5 +159,7 @@ func run(ctx *kong.Context, client *goobs.Client) error {
|
|||||||
return nil
|
return nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
ctx.Bind(newContext(client, os.Stdout, styleCfg))
|
||||||
|
|
||||||
return ctx.Run()
|
return ctx.Run()
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user