Skip to content

Commit

Permalink
include version info
Browse files Browse the repository at this point in the history
  • Loading branch information
rainu committed Dec 20, 2024
1 parent 9705f71 commit d4cd987
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
5 changes: 4 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ type Config struct {

Printer PrinterConfig

LogLevel int
LogLevel int
PrintVersion bool
}

type UIConfig struct {
Expand Down Expand Up @@ -141,6 +142,8 @@ func Parse(arguments []string) *Config {
flag.StringVar(&c.Printer.Format, "print-format", PrinterFormatJSON, fmt.Sprintf("Response printer format (%s, %s)", PrinterFormatPlain, PrinterFormatJSON))
flag.StringVar(&c.Printer.targets, "print-targets", PrinterTargetOut, fmt.Sprintf("Comma seperated response printer targets (%s, %s, <path/to/file>)", PrinterTargetOut, PrinterTargetErr))

flag.BoolVar(&c.PrintVersion, "v", false, "Show the version")

flag.Usage = func() {
printUsage(flag.CommandLine.Output())
}
Expand Down
2 changes: 2 additions & 0 deletions frontend/wailsjs/go/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ export namespace config {
CallOptions: CallOptionsConfig;
Printer: PrinterConfig;
LogLevel: number;
PrintVersion: boolean;

static createFrom(source: any = {}) {
return new Config(source);
Expand All @@ -300,6 +301,7 @@ export namespace config {
this.CallOptions = this.convertValues(source["CallOptions"], CallOptionsConfig);
this.Printer = this.convertValues(source["Printer"], PrinterConfig);
this.LogLevel = source["LogLevel"];
this.PrintVersion = source["PrintVersion"];
}

convertValues(a: any, classs: any, asMap: boolean = false): any {
Expand Down
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ func main() {
})

cfg := config.Parse(os.Args[1:])
if cfg.PrintVersion {
fmt.Fprintln(os.Stderr, versionLine())
os.Exit(0)
return
}
if !buildMode {
if err := cfg.Validate(); err != nil {
fmt.Fprintln(os.Stderr, err.Error())
Expand Down
32 changes: 32 additions & 0 deletions version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

import (
"fmt"
"strconv"
"time"
)

var (
commitHash = "9295DFD720"
branch = ""
tag = "dev"
built = "629579700000"
)

func versionLine() string {
version := tag
if branch != "" {
version = branch
}
builtTime := time.UnixMilli(0)
if iBuilt, _ := strconv.ParseInt(built, 10, 64); iBuilt > 0 {
builtTime = time.UnixMilli(iBuilt)
}

return fmt.Sprintf("%s (#%s - %s) - https://github.com/rainu/ask-mai/tree/%s",
version,
commitHash[:6],
builtTime.UTC().Format(time.RFC3339),
commitHash[:6],
)
}

0 comments on commit d4cd987

Please sign in to comment.