Compare commits

..

No commits in common. "17b8e53da3cac591a528c838849511e2498459f9" and "89a5add7ad8bb984f6c364bf3c9583d1733bb39f" have entirely different histories.

5 changed files with 20 additions and 30 deletions

View File

@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ### Added
- --version/-v option. See [Flags](https://github.com/onyx-and-iris/gobs-cli?tab=readme-ov-file#flags) - --version/-v option. See [VersionFlag](https://github.com/onyx-and-iris/gobs-cli?tab=readme-ov-file#versionflag)
### Changed ### Changed

View File

@ -14,16 +14,10 @@ go install github.com/onyx-and-iris/gobs-cli@latest
#### Flags #### Flags
- --host/-H: Websocket host Pass `--host`, `--port` and `--password` as flags to the root command, for example:
- --port/-P Websocket port
- --password/-p: Websocket password
- --timeout/-T: Websocket timeout
- --version/-v: Print the gobs-cli version
Pass `--host`, `--port` and `--password` as flags on the root command, for example:
```console ```console
gobs-cli --host localhost --port 4455 --password 'websocket password' --help gobs-cli --host=localhost --port=4455 --password=<websocket password> --help
``` ```
#### Environment Variables #### Environment Variables
@ -43,6 +37,14 @@ OBS_TIMEOUT=5
## Commands ## Commands
### VersionFlag
- --version/-v: Print gobs-cli version information and quit
```console
gobs-cli --version
```
### ObsVersionCmd ### ObsVersionCmd
- Print OBS client and websocket version. - Print OBS client and websocket version.

View File

@ -7,8 +7,6 @@ vars:
PROGRAM: gobs-cli PROGRAM: gobs-cli
SHELL: '{{if eq .OS "Windows_NT"}}powershell{{end}}' SHELL: '{{if eq .OS "Windows_NT"}}powershell{{end}}'
BIN_DIR: bin BIN_DIR: bin
VERSION:
sh: 'git describe --tags $(git rev-list --tags --max-count=1)'
tasks: tasks:
default: default:
@ -37,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 -ldflags "-X 'main.version={{.VERSION}}'" -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 -ldflags "-X 'main.version={{.VERSION}}'" -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:

View File

@ -18,10 +18,10 @@ import (
// ObsConfig holds the configuration for connecting to the OBS WebSocket server. // ObsConfig holds the configuration for connecting to the OBS WebSocket server.
type ObsConfig struct { type ObsConfig struct {
Host string `flag:"host" help:"Host to connect to." default:"localhost" env:"OBS_HOST" short:"H"` Host string `flag:"host" help:"Host to connect to." default:"localhost" env:"OBS_HOST"`
Port int `flag:"port" help:"Port to connect to." default:"4455" env:"OBS_PORT" short:"P"` Port int `flag:"port" help:"Port to connect to." default:"4455" env:"OBS_PORT"`
Password string `flag:"password" help:"Password for authentication." default:"" env:"OBS_PASSWORD" short:"p"` Password string `flag:"password" help:"Password for authentication." default:"" env:"OBS_PASSWORD"`
Timeout int `flag:"timeout" help:"Timeout in seconds." default:"5" env:"OBS_TIMEOUT" short:"T"` Timeout int `flag:"timeout" help:"Timeout in seconds." default:"5" env:"OBS_TIMEOUT"`
} }
// CLI is the main command line interface structure. // CLI is the main command line interface structure.

View File

@ -2,13 +2,11 @@ package main
import ( import (
"fmt" "fmt"
"runtime/debug"
"strings"
"github.com/alecthomas/kong" "github.com/alecthomas/kong"
) )
var version string var version = "unknown"
// VersionFlag is a custom flag type for displaying version information. // VersionFlag is a custom flag type for displaying version information.
type VersionFlag string type VersionFlag string
@ -20,16 +18,8 @@ func (v VersionFlag) Decode(_ *kong.DecodeContext) error { return nil }
func (v VersionFlag) IsBool() bool { return true } func (v VersionFlag) IsBool() bool { return true }
// BeforeApply implements the kong.Flag interface for VersionFlag. // BeforeApply implements the kong.Flag interface for VersionFlag.
func (v VersionFlag) BeforeApply(app *kong.Kong, _ kong.Vars) error { // nolint: unparam func (v VersionFlag) BeforeApply(app *kong.Kong, _ kong.Vars) error {
if version == "" { fmt.Println(version)
info, ok := debug.ReadBuildInfo()
if !ok {
return fmt.Errorf("failed to read build info")
}
version = strings.Split(info.Main.Version, "-")[0]
}
fmt.Printf("gobs-cli version: %s\n", version)
app.Exit(0) // Exit the application after printing the version app.Exit(0) // Exit the application after printing the version
return nil return nil
} }