Skip to content

Commit

Permalink
feat: add version flag to display build information
Browse files Browse the repository at this point in the history
- Introduced variables for version, commit, and date.
- Added a version flag to show version information.
- Implemented logic to display version details and exit if the flag is set.

Signed-off-by: Ricardo Melo <ricardo@cropa.ca>
  • Loading branch information
cropalato committed Oct 31, 2024
1 parent 4b3ea97 commit f25a88f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ type Config struct {
}

var osExit = os.Exit
var (
version = "dev"
commit = "none"
date = "unknown"
)

func main() {
// Initialize logging
Expand Down Expand Up @@ -52,6 +57,9 @@ func main() {
func parseFlags() Config {
config := Config{}

// Add version flag
showVersion := flag.Bool("version", false, "Show version information")

flag.StringVar(&config.host, "host", "localhost", "OBS WebSocket host")
flag.IntVar(&config.port, "port", 4444, "OBS WebSocket port")
flag.DurationVar(&config.timeout, "timeout", 5*time.Second, "Connection timeout")
Expand All @@ -65,6 +73,11 @@ func parseFlags() Config {

flag.Parse()

// Check if version flag was set
if *showVersion {
fmt.Printf("obs_switchscene %s (commit: %s, built at: %s)\n", version, commit, date)
osExit(0)
}
// Validate positional arguments
args := flag.Args()
if len(args) != 2 {
Expand Down

0 comments on commit f25a88f

Please sign in to comment.