Skip to content

Commit a4dc850

Browse files
authored
Fix release process and minor cleanup (#15)
1 parent c25b627 commit a4dc850

File tree

7 files changed

+64
-41
lines changed

7 files changed

+64
-41
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ config.toml
2525

2626
# build
2727
pb
28+
bin/
2829

2930
# OS Files
3031
.DS_Store

Makefile

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ LDFLAGS := $(shell go run buildscripts/gen-ldflags.go $(VERSION))
66

77
GOARCH := $(shell go env GOARCH)
88
GOOS := $(shell go env GOOS)
9+
GO111MODULE=on
910

1011
all: build
1112

@@ -14,6 +15,7 @@ checks:
1415
@(env bash $(PWD)/buildscripts/checkdeps.sh)
1516

1617
getdeps:
18+
@GO111MODULE=on
1719
@mkdir -p ${GOPATH}/bin
1820
@echo "Installing golangci-lint" && curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin
1921
@echo "Installing stringer" && go install -v golang.org/x/tools/cmd/stringer@latest
@@ -41,6 +43,10 @@ build: checks
4143
@echo "Building pb binary to './pb'"
4244
@GO111MODULE=on CGO_ENABLED=0 go build -trimpath -tags kqueue --ldflags "$(LDFLAGS)" -o $(PWD)/pb
4345

46+
# Build pb for all supported platforms.
47+
build-release: verifiers crosscompile
48+
@echo "Built releases for version $(VERSION)"
49+
4450
# Builds pb and installs it to $GOPATH/bin.
4551
install: build
4652
@echo "Installing pb binary to '$(GOPATH)/bin/pb'"

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
## PB
1+
## pb
22

3-
PB (short for Parseable) is a command line interface for [Parseable Server](https://github.com/parseablehq/parseable). PB allows you to manage Streams, Users, and Data on Parseable Server. You can use PB to manage multiple Parseable Server instances using Profiles.
3+
pb (short for Parseable) is a command line interface for [Parseable Server](https://github.com/parseablehq/parseable). pb allows you to manage Streams, Users, and Data on Parseable Server. You can use pb to manage multiple Parseable Server instances using Profiles.
44

55
### Installation
66

7-
PB is available as a single, self contained binary for Mac, Linux, and Windows. You can download the latest version from the [releases page](https://github.com/parseablehq/pb/releases/latest).
7+
pb is available as a single, self contained binary for Mac, Linux, and Windows. You can download the latest version from the [releases page](https://github.com/parseablehq/pb/releases/latest).
88

9-
To install PB, download the binary for your platform and place it in a directory that is in your $PATH. For example, on Mac you can place the binary in `/usr/local/bin`.
9+
To install pb, download the binary for your platform and place it in a directory that is in your $PATH. For example, on Mac you can place the binary in `/usr/local/bin`.
1010

1111
![pb query](https://github.com/parseablehq/.github/blob/main/images/pb.png?raw=true)
1212

buildscripts/cross-compile.sh

+14-13
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,27 @@ function _init() {
3030
}
3131

3232
function _build() {
33-
local osarch=$1
34-
IFS=/ read -r -a arr <<<"$osarch"
35-
os="${arr[0]}"
36-
arch="${arr[1]}"
37-
package=$(go list -f '{{.ImportPath}}')
38-
printf -- "--> %15s:%s\n" "${osarch}" "${package}"
33+
local ldflags=("$@")
3934

4035
# Go build to build the binary.
41-
export GOOS=$os
42-
export GOARCH=$arch
4336
export GO111MODULE=on
4437
export CGO_ENABLED=0
45-
go build -tags kqueue -o /dev/null
38+
39+
for osarch in ${SUPPORTED_OSARCH}; do
40+
IFS=/ read -r -a arr <<<"$osarch"
41+
os="${arr[0]}"
42+
arch="${arr[1]}"
43+
export GOOS=$os
44+
export GOARCH=$arch
45+
printf -- "Building release binary for --> %s:%s\n" "${os}" "${arch}"
46+
go build -trimpath -tags kqueue --ldflags "${ldflags[@]}" -o "$(PWD)"/bin/pb_"${os}"_"${arch}"
47+
shasum -a 256 "$(PWD)"/bin/pb_"${os}"_"${arch}" >"$(PWD)"/bin/pb_"${os}"_"${arch}".sha256
48+
done
4649
}
4750

4851
function main() {
49-
echo "Testing builds for OS/Arch: ${SUPPORTED_OSARCH}"
50-
for each_osarch in ${SUPPORTED_OSARCH}; do
51-
_build "${each_osarch}"
52-
done
52+
ldflags=/ read -r arr <<<"$(go run "$(PWD)"/buildscripts/gen-ldflags.go)"
53+
_build "${arr[@]}"
5354
}
5455

5556
_init && main "$@"

buildscripts/gen-ldflags.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
func genLDFlags(version string) string {
2929
var ldflagsStr string
3030
ldflagsStr = "-s -w -X main.Version=" + version + " "
31-
ldflagsStr = ldflagsStr + "-X main.Commit=" + commitID()[:12]
31+
ldflagsStr = ldflagsStr + "-X main.Commit=" + commitID()[:6]
3232
return ldflagsStr
3333
}
3434

@@ -50,12 +50,9 @@ func commitID() string {
5050
}
5151

5252
func main() {
53-
var version string
54-
if len(os.Args) > 1 {
55-
version = os.Args[1]
56-
} else {
53+
version, ok := os.LookupEnv("VERSION")
54+
if !ok {
5755
version = "v0.0.0/DEVELOPMENT"
5856
}
59-
6057
fmt.Println(genLDFlags(version))
6158
}

cmd/stream.go

+29-11
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ type StreamStatsData struct {
4343
Time time.Time `json:"time"`
4444
}
4545

46+
type StreamListItem struct {
47+
name string
48+
}
49+
50+
func (item *StreamListItem) Render() string {
51+
render := standardStyle.Render(item.name)
52+
return itemOuter.Render(render)
53+
}
54+
4655
// StreamRetentionData is the data structure for stream retention
4756
type StreamRetentionData []struct {
4857
Description string `json:"description"`
@@ -143,7 +152,7 @@ var StatStreamCmd = &cobra.Command{
143152

144153
isRententionSet := len(retention) > 0
145154

146-
fmt.Println(styleBold.Render("Info:"))
155+
fmt.Println(styleBold.Render("\nInfo:"))
147156
fmt.Printf(" Event Count: %d\n", ingestionCount)
148157
fmt.Printf(" Ingestion Size: %s\n", humanize.Bytes(uint64(ingestionSize)))
149158
fmt.Printf(" Storage Size: %s\n", humanize.Bytes(uint64(storageSize)))
@@ -217,7 +226,7 @@ var RemoveStreamCmd = &cobra.Command{
217226
}
218227

219228
if resp.StatusCode == 200 {
220-
fmt.Printf("Removed stream %s", styleBold.Render(name))
229+
fmt.Printf("Removed stream %s\n", styleBold.Render(name))
221230
} else {
222231
bytes, err := io.ReadAll(resp.Body)
223232
if err != nil {
@@ -256,18 +265,27 @@ var ListStreamCmd = &cobra.Command{
256265
return err
257266
}
258267
defer resp.Body.Close()
259-
for _, item := range items {
260-
fmt.Println(item["name"])
268+
269+
if len(items) >= 0 {
270+
fmt.Println()
271+
} else if len(items) == 0 {
272+
fmt.Println("No streams found")
273+
return nil
261274
}
262-
} else {
263-
bytes, err := io.ReadAll(resp.Body)
264-
if err != nil {
265-
return err
275+
276+
for _, item := range items {
277+
item := StreamListItem{item["name"]}
278+
fmt.Println(item.Render())
266279
}
267-
body := string(bytes)
268-
fmt.Printf("Request Failed\nStatus Code: %s\nResponse: %s\n", resp.Status, body)
280+
fmt.Println()
281+
return nil
269282
}
270-
283+
bytes, err := io.ReadAll(resp.Body)
284+
if err != nil {
285+
return err
286+
}
287+
body := string(bytes)
288+
fmt.Printf("Request Failed\nStatus Code: %s\nResponse: %s\n", resp.Status, body)
271289
return nil
272290
},
273291
}

main.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -54,43 +54,43 @@ func defaultInitialProfile() config.Profile {
5454
// Root command
5555
var cli = &cobra.Command{
5656
Use: "pb",
57-
Short: "\nParseable command line tool",
58-
Long: "\npb is a command line tool for Parseable",
57+
Short: "\nParseable command line interface",
58+
Long: "\npb is a command line interface for Parseable",
5959
RunE: func(command *cobra.Command, args []string) error {
6060
if p, _ := command.Flags().GetBool(versionFlag); p {
6161
cmd.PrintVersion(Version, Commit)
6262
return nil
6363
}
6464

65-
return errors.New("No command or flag supplied\n")
65+
return errors.New("no command or flag supplied")
6666
},
6767
}
6868

6969
var profile = &cobra.Command{
7070
Use: "profile",
7171
Short: "Manage profiles",
72-
Long: "\nprofile command is used to manage multiple instances of Parseable. Each profile can have a different set of credentials and URL",
72+
Long: "\nuse profile command to configure (multiple) Parseable instances. Each profile takes a URL and credentials.",
7373
}
7474

7575
var user = &cobra.Command{
7676
Use: "user",
7777
Short: "Manage users",
78-
Long: "\nuser command is used to manage users. Users can be added, deleted and listed",
78+
Long: "\nuser command is used to manage users.",
7979
PersistentPreRunE: cmd.PreRunDefaultProfile,
8080
}
8181

8282
var stream = &cobra.Command{
8383
Use: "stream",
8484
Short: "Manage streams",
85-
Long: "\nstream command is used to manage streams. Streams can be created, deleted and listed",
85+
Long: "\nstream command is used to manage streams.",
8686
PersistentPreRunE: cmd.PreRunDefaultProfile,
8787
}
8888

8989
var query = &cobra.Command{
9090
Use: "query [stream-name] --duration 10",
9191
Example: " pb query frontend --duration 10",
9292
Short: "Open SQL query prompt",
93-
Long: "\nquery command is used to open a prompt to query a stream. The stream name and duration in minutes are required arguments",
93+
Long: "\nquery command is used to open a prompt to query a stream.",
9494
Args: cobra.ExactArgs(1),
9595
PreRunE: cmd.PreRunDefaultProfile,
9696
RunE: func(command *cobra.Command, args []string) error {

0 commit comments

Comments
 (0)