Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
djthorpe committed Dec 28, 2020
1 parent 4b80c12 commit d2f4774
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 39 deletions.
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ builddir:
install -d $(BUILDDIR)

# Make debian packages
debian: clean builddir argonone dnsregister douglas httpserver nfpm
debian: clean builddir argonone dnsregister douglas httpserver rpcping nfpm
$(eval VERSION = $(shell git describe --tags))
$(eval ARCH = $(shell $(GO) env GOARCH))
$(eval PLATFORM = $(shell $(GO) env GOOS))
Expand Down Expand Up @@ -130,6 +130,13 @@ debian: clean builddir argonone dnsregister douglas httpserver nfpm
etc/nfpm/httpserver.yaml > $(BUILDDIR)/httpserver.yaml
@nfpm pkg -f $(BUILDDIR)/httpserver.yaml --packager deb --target $(BUILDDIR)

@sed \
-e 's/^version:.*$$/version: $(VERSION)/' \
-e 's/^arch:.*$$/arch: $(ARCH)/' \
-e 's/^platform:.*$$/platform: $(PLATFORM)/' \
etc/nfpm/rpcping.yaml > $(BUILDDIR)/rpcping.yaml
@nfpm pkg -f $(BUILDDIR)/rpcping.yaml --packager deb --target $(BUILDDIR)

@echo
@ls -1 $(BUILDDIR)/*.deb
@echo
Expand Down
2 changes: 2 additions & 0 deletions cmd/rpcping/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ func (this *app) Define(cfg gopi.Config) error {
func (this *app) New(cfg gopi.Config) error {
if cmd, err := cfg.GetCommand(cfg.Args()); err != nil {
return gopi.ErrHelp
} else if cmd == nil {
return gopi.ErrHelp
} else {
this.Command = cmd
}
Expand Down
45 changes: 15 additions & 30 deletions cmd/rpcping/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"time"

"github.com/djthorpe/gopi/v3"
"github.com/olekukonko/tablewriter"
"github.com/djthorpe/gopi/v3/pkg/table"
)

func (this *app) RunVersion(ctx context.Context, stub gopi.PingStub) error {
Expand All @@ -17,48 +17,33 @@ func (this *app) RunVersion(ctx context.Context, stub gopi.PingStub) error {
}

// Display platform information
table := tablewriter.NewWriter(os.Stdout)
table.SetAlignment(tablewriter.ALIGN_LEFT)
table.SetAutoMergeCells(true)
table.Append([]string{
"Name", version.Name(),
})
table := table.New(table.WithHeader(false), table.WithMergeCells())

table.Append(header{"Name"}, version.Name())

tag, branch, hash := version.Version()
if tag != "" {
table.Append([]string{
"Tag", tag,
})
table.Append(header{"Tag"}, tag)
}
if branch != "" {
table.Append([]string{
"Branch", branch,
})
table.Append(header{"Branch"}, branch)
}
if hash != "" {
table.Append([]string{
"Hash", hash,
})
table.Append(header{"Hash"}, hash)
}
table.Append([]string{
"Go version", version.GoVersion(),
})

table.Append(header{"GoVersion"}, version.GoVersion())

if t := version.BuildTime(); t.IsZero() == false {
table.Append([]string{
"Build time", t.Format(time.RFC3339),
})
table.Append(header{"BuildTime"}, t.Format(time.RFC3339))
}

if services, err := stub.ListServices(ctx); err != nil {
return err
} else if len(services) > 0 {
if services, err := stub.ListServices(ctx); err == nil {
for _, service := range services {
table.Append([]string{
"Services", service,
})
table.Append(header{"Services"}, service)
}
}

table.Render()
table.Render(os.Stdout)

// Return success
return nil
Expand Down
13 changes: 13 additions & 0 deletions cmd/rpcping/format.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

import (
"github.com/djthorpe/gopi/v3/pkg/table"
)

type header struct {
string
}

func (h header) Format() (string, table.Alignment, table.Color) {
return h.string, table.Auto, table.Bold
}
22 changes: 22 additions & 0 deletions etc/nfpm/rpcping.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

# nfpm file to create debian package for rpcping
name: "rpcping"

# arch, platform and version are replaced with GOARCH, GOOS and git tag
arch: "arm"
platform: "linux"
version: "v0.0.0"

replaces:
- rpcping
provides:
- rpcping
maintainer: "David Thorpe <djt@mutablelogic.com>"
description: |
Demonstration of client/server communication using RPC
vendor: "mutablelogic.com"
homepage: "http://github.com/djthorpe/gopi/cmd/rpcping"
license: "Apache 2.0"

files:
build/rpcping: /opt/gopi/bin/rpcping
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ require (
github.com/hashicorp/go-multierror v1.1.0
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/miekg/dns v1.1.35
github.com/mlafeldt/pkgcloud v0.0.0-20200630152107-54067fd37496 // indirect
github.com/olekukonko/tablewriter v0.0.4
github.com/peterhellberg/link v1.1.0 // indirect
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad // indirect
golang.org/x/image v0.0.0-20201208152932-35266b937fa6
golang.org/x/net v0.0.0-20201224014010-6772e930b67b
Expand All @@ -22,4 +24,5 @@ require (
google.golang.org/grpc v1.34.0
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.0.1 // indirect
google.golang.org/protobuf v1.25.0
gopkg.in/cheggaaa/pb.v1 v1.0.28 // indirect
)
8 changes: 6 additions & 2 deletions pkg/config/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,15 @@ func (this *command) Name() string {
}

func (this *command) Usage() (string, string) {
return this.syntax, this.usage
return this.Syntax(), this.usage
}

func (this *command) Syntax() string {
return this.syntax
if this.syntax == "" {
return "<args>"
} else {
return this.syntax
}
}

func (this *command) Args() []string {
Expand Down
9 changes: 3 additions & 6 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ func (this *config) Parse() error {
func (this *config) Usage(name string) {
name = strings.ToLower(strings.TrimSpace(name))
parts := strings.Fields(name)
if len(parts) == 0 {
this.usageAll()
} else if cmd, _ := this.GetCommand(parts); cmd != nil {
if cmd, _ := this.GetCommand(parts); cmd != nil {
this.usageOne(cmd)
} else {
this.usageAll()
Expand Down Expand Up @@ -129,11 +127,10 @@ func (this *config) GetCommand(args []string) (gopi.Command, error) {
cmd = child
}
}

// Special case where root command matched
if cmd == this.commands {
i = 0
cmd = this.commands.commands[0]
args = append([]string{cmd.name}, args...)
return nil, nil
}

// Create a new command from the existing one, setting arguments
Expand Down

0 comments on commit d2f4774

Please sign in to comment.