mirror of
https://github.com/onyx-and-iris/gobs-cli.git
synced 2025-05-20 16:10:26 +01:00
add env file resolver
This commit is contained in:
parent
8cf969c906
commit
30fabe8cfc
13
.gitignore
vendored
13
.gitignore
vendored
@ -26,6 +26,15 @@ go.work
|
|||||||
|
|
||||||
# End of gignore: github.com/onyx-and-iris/gignore
|
# End of gignore: github.com/onyx-and-iris/gignore
|
||||||
|
|
||||||
|
# Environment
|
||||||
|
.env
|
||||||
.envrc
|
.envrc
|
||||||
*_test.go
|
|
||||||
gobs-cli.1
|
# Man pages
|
||||||
|
gobs-cli.1
|
||||||
|
|
||||||
|
# Config files
|
||||||
|
config.yaml
|
||||||
|
|
||||||
|
# Test files
|
||||||
|
*_test.go
|
20
README.md
20
README.md
@ -22,17 +22,19 @@ gobs-cli --host=localhost --port=4455 --password=<websocket password> --help
|
|||||||
|
|
||||||
#### Environment Variables
|
#### Environment Variables
|
||||||
|
|
||||||
Load connection details from your environment:
|
Store and load environment variables from:
|
||||||
|
|
||||||
```bash
|
- A `.env` file in the cwd
|
||||||
#!/usr/bin/env bash
|
- $XDG_CONFIG_HOME / gobs-cli / config.env (see [os.UserConfigDir][userconfigdir])
|
||||||
|
|
||||||
export OBS_HOST=localhost
|
```env
|
||||||
export OBS_PORT=4455
|
OBS_HOST=localhost
|
||||||
export OBS_PASSWORD=<websocket password>
|
OBS_PORT=4455
|
||||||
export OBS_TIMEOUT=5
|
OBS_PASSWORD=<websocket password>
|
||||||
|
OBS_TIMEOUT=5
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## Commands
|
## Commands
|
||||||
|
|
||||||
### VersionCmd
|
### VersionCmd
|
||||||
@ -433,4 +435,6 @@ gobs-cli virtualcam toggle
|
|||||||
|
|
||||||
```console
|
```console
|
||||||
gobs-cli virtualcam status
|
gobs-cli virtualcam status
|
||||||
```
|
```
|
||||||
|
|
||||||
|
[userconfigdir]: https://pkg.go.dev/os#UserConfigDir
|
2
go.mod
2
go.mod
@ -6,12 +6,14 @@ require (
|
|||||||
github.com/alecthomas/kong v1.10.0
|
github.com/alecthomas/kong v1.10.0
|
||||||
github.com/alecthomas/mango-kong v0.1.0
|
github.com/alecthomas/mango-kong v0.1.0
|
||||||
github.com/andreykaipov/goobs v1.5.6
|
github.com/andreykaipov/goobs v1.5.6
|
||||||
|
github.com/titusjaka/kong-dotenv-go v0.1.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/buger/jsonparser v1.1.1 // indirect
|
github.com/buger/jsonparser v1.1.1 // indirect
|
||||||
github.com/gorilla/websocket v1.5.3 // indirect
|
github.com/gorilla/websocket v1.5.3 // indirect
|
||||||
github.com/hashicorp/logutils v1.0.0 // indirect
|
github.com/hashicorp/logutils v1.0.0 // indirect
|
||||||
|
github.com/joho/godotenv v1.5.1 // indirect
|
||||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||||
github.com/mmcloughlin/profile v0.1.1 // indirect
|
github.com/mmcloughlin/profile v0.1.1 // indirect
|
||||||
github.com/muesli/mango v0.1.1-0.20220205060214-77e2058169ab // indirect
|
github.com/muesli/mango v0.1.1-0.20220205060214-77e2058169ab // indirect
|
||||||
|
4
go.sum
4
go.sum
@ -18,6 +18,8 @@ github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI
|
|||||||
github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
|
github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
|
||||||
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
|
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
|
||||||
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
|
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
|
||||||
|
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||||
|
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||||
github.com/mmcloughlin/profile v0.1.1 h1:jhDmAqPyebOsVDOCICJoINoLb/AnLBaUw58nFzxWS2w=
|
github.com/mmcloughlin/profile v0.1.1 h1:jhDmAqPyebOsVDOCICJoINoLb/AnLBaUw58nFzxWS2w=
|
||||||
@ -32,5 +34,7 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
|
|||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
|
github.com/titusjaka/kong-dotenv-go v0.1.0 h1:TmUjP/sXoNiKLr6oR7n9xrB5XyXi/Ssuebzfz5nxZj4=
|
||||||
|
github.com/titusjaka/kong-dotenv-go v0.1.0/go.mod h1:pBgLjcu82oqUgb7+bngK9+Ch7jg49E0YADP8Wnj2MXU=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
11
main.go
11
main.go
@ -7,11 +7,13 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/alecthomas/kong"
|
"github.com/alecthomas/kong"
|
||||||
mangokong "github.com/alecthomas/mango-kong"
|
mangokong "github.com/alecthomas/mango-kong"
|
||||||
"github.com/andreykaipov/goobs"
|
"github.com/andreykaipov/goobs"
|
||||||
|
kongdotenv "github.com/titusjaka/kong-dotenv-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ObsConfig holds the configuration for connecting to the OBS WebSocket server.
|
// ObsConfig holds the configuration for connecting to the OBS WebSocket server.
|
||||||
@ -49,11 +51,18 @@ type context struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
cli := cli{}
|
userConfigDir, err := os.UserConfigDir()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "Error getting user config directory: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
var cli cli
|
||||||
ctx := kong.Parse(
|
ctx := kong.Parse(
|
||||||
&cli,
|
&cli,
|
||||||
kong.Name("GOBS-CLI"),
|
kong.Name("GOBS-CLI"),
|
||||||
kong.Description("A command line tool to interact with OBS Websocket."),
|
kong.Description("A command line tool to interact with OBS Websocket."),
|
||||||
|
kong.Configuration(kongdotenv.ENVFileReader, ".env", filepath.Join(userConfigDir, "gobs-cli", "config.env")),
|
||||||
)
|
)
|
||||||
|
|
||||||
client, err := connectObs(cli.ObsConfig)
|
client, err := connectObs(cli.ObsConfig)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user