mirror of
https://github.com/onyx-and-iris/gobs-cli.git
synced 2025-08-07 12:11:53 +00:00
Compare commits
3 Commits
89a5add7ad
...
17b8e53da3
Author | SHA1 | Date | |
---|---|---|---|
17b8e53da3 | |||
92761ab1b3 | |||
4446784709 |
@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
### Added
|
||||
|
||||
- --version/-v option. See [VersionFlag](https://github.com/onyx-and-iris/gobs-cli?tab=readme-ov-file#versionflag)
|
||||
- --version/-v option. See [Flags](https://github.com/onyx-and-iris/gobs-cli?tab=readme-ov-file#flags)
|
||||
|
||||
### Changed
|
||||
|
||||
|
18
README.md
18
README.md
@ -14,10 +14,16 @@ go install github.com/onyx-and-iris/gobs-cli@latest
|
||||
|
||||
#### Flags
|
||||
|
||||
Pass `--host`, `--port` and `--password` as flags to the root command, for example:
|
||||
- --host/-H: Websocket host
|
||||
- --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
|
||||
gobs-cli --host=localhost --port=4455 --password=<websocket password> --help
|
||||
gobs-cli --host localhost --port 4455 --password 'websocket password' --help
|
||||
```
|
||||
|
||||
#### Environment Variables
|
||||
@ -37,14 +43,6 @@ OBS_TIMEOUT=5
|
||||
|
||||
## Commands
|
||||
|
||||
### VersionFlag
|
||||
|
||||
- --version/-v: Print gobs-cli version information and quit
|
||||
|
||||
```console
|
||||
gobs-cli --version
|
||||
```
|
||||
|
||||
### ObsVersionCmd
|
||||
|
||||
- Print OBS client and websocket version.
|
||||
|
@ -7,6 +7,8 @@ vars:
|
||||
PROGRAM: gobs-cli
|
||||
SHELL: '{{if eq .OS "Windows_NT"}}powershell{{end}}'
|
||||
BIN_DIR: bin
|
||||
VERSION:
|
||||
sh: 'git describe --tags $(git rev-list --tags --max-count=1)'
|
||||
|
||||
tasks:
|
||||
default:
|
||||
@ -35,13 +37,13 @@ tasks:
|
||||
build-windows:
|
||||
desc: Build the gobs-cli project for Windows
|
||||
cmds:
|
||||
- GOOS=windows GOARCH=amd64 go build -ldflags "-X 'main.version=debug'" -o {{.BIN_DIR}}/{{.PROGRAM}}_windows_amd64.exe
|
||||
- GOOS=windows GOARCH=amd64 go build -ldflags "-X 'main.version={{.VERSION}}'" -o {{.BIN_DIR}}/{{.PROGRAM}}_windows_amd64.exe
|
||||
internal: true
|
||||
|
||||
build-linux:
|
||||
desc: Build the gobs-cli project for Linux
|
||||
cmds:
|
||||
- GOOS=linux GOARCH=amd64 go build -ldflags "-X 'main.version=debug'" -o {{.BIN_DIR}}/{{.PROGRAM}}_linux_amd64
|
||||
- GOOS=linux GOARCH=amd64 go build -ldflags "-X 'main.version={{.VERSION}}'" -o {{.BIN_DIR}}/{{.PROGRAM}}_linux_amd64
|
||||
internal: true
|
||||
|
||||
test:
|
||||
|
8
main.go
8
main.go
@ -18,10 +18,10 @@ import (
|
||||
|
||||
// ObsConfig holds the configuration for connecting to the OBS WebSocket server.
|
||||
type ObsConfig struct {
|
||||
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"`
|
||||
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"`
|
||||
Host string `flag:"host" help:"Host to connect to." default:"localhost" env:"OBS_HOST" short:"H"`
|
||||
Port int `flag:"port" help:"Port to connect to." default:"4455" env:"OBS_PORT" short:"P"`
|
||||
Password string `flag:"password" help:"Password for authentication." default:"" env:"OBS_PASSWORD" short:"p"`
|
||||
Timeout int `flag:"timeout" help:"Timeout in seconds." default:"5" env:"OBS_TIMEOUT" short:"T"`
|
||||
}
|
||||
|
||||
// CLI is the main command line interface structure.
|
||||
|
16
version.go
16
version.go
@ -2,11 +2,13 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
|
||||
"github.com/alecthomas/kong"
|
||||
)
|
||||
|
||||
var version = "unknown"
|
||||
var version string
|
||||
|
||||
// VersionFlag is a custom flag type for displaying version information.
|
||||
type VersionFlag string
|
||||
@ -18,8 +20,16 @@ func (v VersionFlag) Decode(_ *kong.DecodeContext) error { return nil }
|
||||
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)
|
||||
func (v VersionFlag) BeforeApply(app *kong.Kong, _ kong.Vars) error { // nolint: unparam
|
||||
if 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
|
||||
return nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user