Skip to content

Commit a3d979b

Browse files
committed
Added version command and fixed http flag
1 parent 20607cc commit a3d979b

3 files changed

Lines changed: 45 additions & 5 deletions

File tree

cmd/pgmanager/main.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99

1010
// Packages
1111
kong "github.com/alecthomas/kong"
12-
httpclient "github.com/mutablelogic/go-pg/pkg/manager/httpclient"
1312
client "github.com/mutablelogic/go-client"
13+
httpclient "github.com/mutablelogic/go-pg/pkg/manager/httpclient"
1414
)
1515

1616
///////////////////////////////////////////////////////////////////////////////
@@ -23,7 +23,7 @@ type Globals struct {
2323
// HTTP server options
2424
HTTP struct {
2525
Prefix string `name:"prefix" help:"HTTP path prefix" default:"/api/v1"`
26-
Listen string `name:"http" help:"HTTP Listen address" default:":8080"`
26+
Addr string `name:"addr" env:"PG_ADDR" help:"HTTP Listen address" default:":8080"`
2727
} `embed:"" prefix:"http."`
2828

2929
// Private fields
@@ -44,6 +44,7 @@ type CLI struct {
4444
SettingCommands
4545
StatementCommands
4646
TablespaceCommands
47+
VersionCommands
4748
}
4849

4950
///////////////////////////////////////////////////////////////////////////////
@@ -68,7 +69,7 @@ func main() {
6869
// PRIVATE METHODS
6970

7071
func (g *Globals) Client() (*httpclient.Client, error) {
71-
host, port, err := net.SplitHostPort(g.HTTP.Listen)
72+
host, port, err := net.SplitHostPort(g.HTTP.Addr)
7273
if err != nil {
7374
return nil, err
7475
}

cmd/pgmanager/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ func (cmd *RunServer) Run(ctx *Globals) error {
9292
}
9393

9494
// Create a HTTP server
95-
server, err := httpserver.New(ctx.HTTP.Listen, router, tlsconfig)
95+
server, err := httpserver.New(ctx.HTTP.Addr, router, tlsconfig)
9696
if err != nil {
9797
return err
9898
}
9999

100100
// Run the server
101-
fmt.Println("Starting server on", ctx.HTTP.Listen)
101+
fmt.Println("Starting server on", ctx.HTTP.Addr)
102102
return server.Run(ctx.ctx)
103103
}

cmd/pgmanager/version.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
// Packages
7+
"github.com/mutablelogic/go-pg/pkg/version"
8+
)
9+
10+
///////////////////////////////////////////////////////////////////////////////
11+
// TYPES
12+
13+
type VersionCommands struct {
14+
Version VersionCommand `cmd:"version" help:"Print version information"`
15+
}
16+
17+
type VersionCommand struct{}
18+
19+
///////////////////////////////////////////////////////////////////////////////
20+
// PUBLIC METHODS
21+
22+
func (cmd *VersionCommand) Run(g *Globals) error {
23+
if version.GitSource != "" {
24+
fmt.Printf("%s@%s\n\n", version.GitSource, version.Version())
25+
} else {
26+
fmt.Printf("pgmanager %s\n\n", version.Version())
27+
}
28+
if version.GitHash != "" {
29+
fmt.Printf("Commit: %s\n", version.GitHash)
30+
}
31+
if version.GitBranch != "" {
32+
fmt.Printf("Branch: %s\n", version.GitBranch)
33+
}
34+
if version.GoBuildTime != "" {
35+
fmt.Printf("Build Time: %s\n", version.GoBuildTime)
36+
}
37+
fmt.Printf("Compiler: %s\n", version.Compiler())
38+
return nil
39+
}

0 commit comments

Comments
 (0)