add short names for root options

fix flag example in readme
This commit is contained in:
onyx-and-iris 2025-06-03 12:33:37 +01:00
parent 89a5add7ad
commit 4446784709
3 changed files with 14 additions and 16 deletions

View File

@ -14,10 +14,16 @@ go install github.com/onyx-and-iris/gobs-cli@latest
#### Flags #### 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 ```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
@ -37,14 +43,6 @@ 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

@ -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"` 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"` 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"` 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"` Timeout int `flag:"timeout" help:"Timeout in seconds." default:"5" env:"OBS_TIMEOUT" short:"T"`
} }
// CLI is the main command line interface structure. // CLI is the main command line interface structure.

View File

@ -18,8 +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 { func (v VersionFlag) BeforeApply(app *kong.Kong, _ kong.Vars) error { // nolint: unparam
fmt.Println(version) 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
} }