From 95ebb2afb620d310dbbb831eb94cfc3bca316f37 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Mon, 2 Jun 2025 18:11:37 +0100 Subject: [PATCH] add VersionFlag to CLI struct upd VersionCmd struct --- main.go | 33 +++++++++++++++++---------------- version.go | 26 +++++++++++++++++++++++--- 2 files changed, 40 insertions(+), 19 deletions(-) diff --git a/main.go b/main.go index 8d488bb..298e794 100644 --- a/main.go +++ b/main.go @@ -29,23 +29,24 @@ type ObsConfig struct { type CLI struct { ObsConfig `embed:"" help:"OBS WebSocket configuration."` - Man mangokong.ManFlag `help:"Print man page."` + Man mangokong.ManFlag `help:"Print man page."` + Version VersionFlag `help:"Print gobs-cli version information and quit" name:"version" short:"v"` - Version VersionCmd `help:"Show version." cmd:"" aliases:"v"` - Scene SceneCmd `help:"Manage scenes." cmd:"" aliases:"sc"` - Sceneitem SceneItemCmd `help:"Manage scene items." cmd:"" aliases:"si"` - Group GroupCmd `help:"Manage groups." cmd:"" aliases:"g"` - Input InputCmd `help:"Manage inputs." cmd:"" aliases:"i"` - Record RecordCmd `help:"Manage recording." cmd:"" aliases:"rec"` - Stream StreamCmd `help:"Manage streaming." cmd:"" aliases:"st"` - Scenecollection SceneCollectionCmd `help:"Manage scene collections." cmd:"" aliases:"scn"` - Profile ProfileCmd `help:"Manage profiles." cmd:"" aliases:"p"` - Replaybuffer ReplayBufferCmd `help:"Manage replay buffer." cmd:"" aliases:"rb"` - Studiomode StudioModeCmd `help:"Manage studio mode." cmd:"" aliases:"sm"` - Virtualcam VirtualCamCmd `help:"Manage virtual camera." cmd:"" aliases:"vc"` - Hotkey HotkeyCmd `help:"Manage hotkeys." cmd:"" aliases:"hk"` - Filter FilterCmd `help:"Manage filters." cmd:"" aliases:"f"` - Projector ProjectorCmd `help:"Manage projectors." cmd:"" aliases:"prj"` + ObsVersion ObsVersionCmd `help:"Print OBS client and websocket version." cmd:"" aliases:"v"` + Scene SceneCmd `help:"Manage scenes." cmd:"" aliases:"sc"` + Sceneitem SceneItemCmd `help:"Manage scene items." cmd:"" aliases:"si"` + Group GroupCmd `help:"Manage groups." cmd:"" aliases:"g"` + Input InputCmd `help:"Manage inputs." cmd:"" aliases:"i"` + Record RecordCmd `help:"Manage recording." cmd:"" aliases:"rec"` + Stream StreamCmd `help:"Manage streaming." cmd:"" aliases:"st"` + Scenecollection SceneCollectionCmd `help:"Manage scene collections." cmd:"" aliases:"scn"` + Profile ProfileCmd `help:"Manage profiles." cmd:"" aliases:"p"` + Replaybuffer ReplayBufferCmd `help:"Manage replay buffer." cmd:"" aliases:"rb"` + Studiomode StudioModeCmd `help:"Manage studio mode." cmd:"" aliases:"sm"` + Virtualcam VirtualCamCmd `help:"Manage virtual camera." cmd:"" aliases:"vc"` + Hotkey HotkeyCmd `help:"Manage hotkeys." cmd:"" aliases:"hk"` + Filter FilterCmd `help:"Manage filters." cmd:"" aliases:"f"` + Projector ProjectorCmd `help:"Manage projectors." cmd:"" aliases:"prj"` } type context struct { diff --git a/version.go b/version.go index c9ac075..23deeb0 100644 --- a/version.go +++ b/version.go @@ -2,13 +2,33 @@ package main import ( "fmt" + + "github.com/alecthomas/kong" ) -// VersionCmd handles the version command. -type VersionCmd struct{} // size = 0x0 +var version = "unknown" + +// VersionFlag is a custom flag type for displaying version information. +type VersionFlag string + +// Decode implements the kong.Flag interface for VersionFlag. +func (v VersionFlag) Decode(_ *kong.DecodeContext) error { return nil } + +// IsBool implements the kong.Flag interface for VersionFlag. +func (v VersionFlag) IsBool() bool { return true } + +// BeforeApply implements the kong.Flag interface for VersionFlag. +func (v VersionFlag) BeforeApply(app *kong.Kong, _ kong.Vars) error { + fmt.Println(version) + app.Exit(0) // Exit the application after printing the version + return nil +} + +// ObsVersionCmd handles the version command. +type ObsVersionCmd struct{} // size = 0x0 // Run executes the command to get the OBS client version. -func (cmd *VersionCmd) Run(ctx *context) error { +func (cmd *ObsVersionCmd) Run(ctx *context) error { version, err := ctx.Client.General.GetVersion() if err != nil { return err