Compare commits

..

4 Commits

Author SHA1 Message Date
89a5add7ad upd VersionCmd test 2025-06-02 18:12:43 +01:00
878ecbd33e add 0.9.0 to CHANGELOG 2025-06-02 18:12:06 +01:00
18a90e727f define main.version in local builds 2025-06-02 18:11:56 +01:00
95ebb2afb6 add VersionFlag to CLI struct
upd VersionCmd struct
2025-06-02 18:11:37 +01:00
5 changed files with 53 additions and 22 deletions

View File

@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
# [0.9.0]
### Added
- --version/-v option. See [VersionFlag](https://github.com/onyx-and-iris/gobs-cli?tab=readme-ov-file#versionflag)
### Changed
- version command renamed to obs-version
# [0.8.2] # [0.8.2]
### Added ### Added

View File

@ -35,13 +35,13 @@ tasks:
build-windows: build-windows:
desc: Build the gobs-cli project for Windows desc: Build the gobs-cli project for Windows
cmds: cmds:
- GOOS=windows GOARCH=amd64 go build -o {{.BIN_DIR}}/{{.PROGRAM}}_windows_amd64.exe - GOOS=windows GOARCH=amd64 go build -ldflags "-X 'main.version=debug'" -o {{.BIN_DIR}}/{{.PROGRAM}}_windows_amd64.exe
internal: true internal: true
build-linux: build-linux:
desc: Build the gobs-cli project for Linux desc: Build the gobs-cli project for Linux
cmds: cmds:
- GOOS=linux GOARCH=amd64 go build -o {{.BIN_DIR}}/{{.PROGRAM}}_linux_amd64 - GOOS=linux GOARCH=amd64 go build -ldflags "-X 'main.version=debug'" -o {{.BIN_DIR}}/{{.PROGRAM}}_linux_amd64
internal: true internal: true
test: test:

33
main.go
View File

@ -29,23 +29,24 @@ type ObsConfig struct {
type CLI struct { type CLI struct {
ObsConfig `embed:"" help:"OBS WebSocket configuration."` 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"` ObsVersion ObsVersionCmd `help:"Print OBS client and websocket version." cmd:"" aliases:"v"`
Scene SceneCmd `help:"Manage scenes." cmd:"" aliases:"sc"` Scene SceneCmd `help:"Manage scenes." cmd:"" aliases:"sc"`
Sceneitem SceneItemCmd `help:"Manage scene items." cmd:"" aliases:"si"` Sceneitem SceneItemCmd `help:"Manage scene items." cmd:"" aliases:"si"`
Group GroupCmd `help:"Manage groups." cmd:"" aliases:"g"` Group GroupCmd `help:"Manage groups." cmd:"" aliases:"g"`
Input InputCmd `help:"Manage inputs." cmd:"" aliases:"i"` Input InputCmd `help:"Manage inputs." cmd:"" aliases:"i"`
Record RecordCmd `help:"Manage recording." cmd:"" aliases:"rec"` Record RecordCmd `help:"Manage recording." cmd:"" aliases:"rec"`
Stream StreamCmd `help:"Manage streaming." cmd:"" aliases:"st"` Stream StreamCmd `help:"Manage streaming." cmd:"" aliases:"st"`
Scenecollection SceneCollectionCmd `help:"Manage scene collections." cmd:"" aliases:"scn"` Scenecollection SceneCollectionCmd `help:"Manage scene collections." cmd:"" aliases:"scn"`
Profile ProfileCmd `help:"Manage profiles." cmd:"" aliases:"p"` Profile ProfileCmd `help:"Manage profiles." cmd:"" aliases:"p"`
Replaybuffer ReplayBufferCmd `help:"Manage replay buffer." cmd:"" aliases:"rb"` Replaybuffer ReplayBufferCmd `help:"Manage replay buffer." cmd:"" aliases:"rb"`
Studiomode StudioModeCmd `help:"Manage studio mode." cmd:"" aliases:"sm"` Studiomode StudioModeCmd `help:"Manage studio mode." cmd:"" aliases:"sm"`
Virtualcam VirtualCamCmd `help:"Manage virtual camera." cmd:"" aliases:"vc"` Virtualcam VirtualCamCmd `help:"Manage virtual camera." cmd:"" aliases:"vc"`
Hotkey HotkeyCmd `help:"Manage hotkeys." cmd:"" aliases:"hk"` Hotkey HotkeyCmd `help:"Manage hotkeys." cmd:"" aliases:"hk"`
Filter FilterCmd `help:"Manage filters." cmd:"" aliases:"f"` Filter FilterCmd `help:"Manage filters." cmd:"" aliases:"f"`
Projector ProjectorCmd `help:"Manage projectors." cmd:"" aliases:"prj"` Projector ProjectorCmd `help:"Manage projectors." cmd:"" aliases:"prj"`
} }
type context struct { type context struct {

View File

@ -2,13 +2,33 @@ package main
import ( import (
"fmt" "fmt"
"github.com/alecthomas/kong"
) )
// VersionCmd handles the version command. var version = "unknown"
type VersionCmd struct{} // size = 0x0
// 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. // 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() version, err := ctx.Client.General.GetVersion()
if err != nil { if err != nil {
return err return err

View File

@ -16,7 +16,7 @@ func TestVersion(t *testing.T) {
Out: &out, Out: &out,
} }
cmd := &VersionCmd{} cmd := &ObsVersionCmd{}
err := cmd.Run(context) err := cmd.Run(context)
if err != nil { if err != nil {
t.Fatalf("Failed to get version: %v", err) t.Fatalf("Failed to get version: %v", err)