diff --git a/.gitignore b/.gitignore index 8575996..2ee011a 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ config.toml # build pb +bin/ # OS Files .DS_Store diff --git a/Makefile b/Makefile index 2f6ca83..26ea48b 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,7 @@ LDFLAGS := $(shell go run buildscripts/gen-ldflags.go $(VERSION)) GOARCH := $(shell go env GOARCH) GOOS := $(shell go env GOOS) +GO111MODULE=on all: build @@ -14,6 +15,7 @@ checks: @(env bash $(PWD)/buildscripts/checkdeps.sh) getdeps: + @GO111MODULE=on @mkdir -p ${GOPATH}/bin @echo "Installing golangci-lint" && curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin @echo "Installing stringer" && go install -v golang.org/x/tools/cmd/stringer@latest @@ -41,6 +43,10 @@ build: checks @echo "Building pb binary to './pb'" @GO111MODULE=on CGO_ENABLED=0 go build -trimpath -tags kqueue --ldflags "$(LDFLAGS)" -o $(PWD)/pb +# Build pb for all supported platforms. +build-release: verifiers crosscompile + @echo "Built releases for version $(VERSION)" + # Builds pb and installs it to $GOPATH/bin. install: build @echo "Installing pb binary to '$(GOPATH)/bin/pb'" diff --git a/README.md b/README.md index 2856894..f98863d 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ -## PB +## pb -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. +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. ### Installation -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). +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). -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`. +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`. ![pb query](https://github.com/parseablehq/.github/blob/main/images/pb.png?raw=true) diff --git a/buildscripts/cross-compile.sh b/buildscripts/cross-compile.sh index e7b7e16..10e2886 100644 --- a/buildscripts/cross-compile.sh +++ b/buildscripts/cross-compile.sh @@ -30,26 +30,27 @@ function _init() { } function _build() { - local osarch=$1 - IFS=/ read -r -a arr <<<"$osarch" - os="${arr[0]}" - arch="${arr[1]}" - package=$(go list -f '{{.ImportPath}}') - printf -- "--> %15s:%s\n" "${osarch}" "${package}" + local ldflags=("$@") # Go build to build the binary. - export GOOS=$os - export GOARCH=$arch export GO111MODULE=on export CGO_ENABLED=0 - go build -tags kqueue -o /dev/null + + for osarch in ${SUPPORTED_OSARCH}; do + IFS=/ read -r -a arr <<<"$osarch" + os="${arr[0]}" + arch="${arr[1]}" + export GOOS=$os + export GOARCH=$arch + printf -- "Building release binary for --> %s:%s\n" "${os}" "${arch}" + go build -trimpath -tags kqueue --ldflags "${ldflags[@]}" -o "$(PWD)"/bin/pb_"${os}"_"${arch}" + shasum -a 256 "$(PWD)"/bin/pb_"${os}"_"${arch}" >"$(PWD)"/bin/pb_"${os}"_"${arch}".sha256 + done } function main() { - echo "Testing builds for OS/Arch: ${SUPPORTED_OSARCH}" - for each_osarch in ${SUPPORTED_OSARCH}; do - _build "${each_osarch}" - done + ldflags=/ read -r arr <<<"$(go run "$(PWD)"/buildscripts/gen-ldflags.go)" + _build "${arr[@]}" } _init && main "$@" diff --git a/buildscripts/gen-ldflags.go b/buildscripts/gen-ldflags.go index 17cbdf5..9d1313b 100644 --- a/buildscripts/gen-ldflags.go +++ b/buildscripts/gen-ldflags.go @@ -28,7 +28,7 @@ import ( func genLDFlags(version string) string { var ldflagsStr string ldflagsStr = "-s -w -X main.Version=" + version + " " - ldflagsStr = ldflagsStr + "-X main.Commit=" + commitID()[:12] + ldflagsStr = ldflagsStr + "-X main.Commit=" + commitID()[:6] return ldflagsStr } @@ -50,12 +50,9 @@ func commitID() string { } func main() { - var version string - if len(os.Args) > 1 { - version = os.Args[1] - } else { + version, ok := os.LookupEnv("VERSION") + if !ok { version = "v0.0.0/DEVELOPMENT" } - fmt.Println(genLDFlags(version)) } diff --git a/cmd/stream.go b/cmd/stream.go index 5227677..4c1becb 100644 --- a/cmd/stream.go +++ b/cmd/stream.go @@ -43,6 +43,15 @@ type StreamStatsData struct { Time time.Time `json:"time"` } +type StreamListItem struct { + name string +} + +func (item *StreamListItem) Render() string { + render := standardStyle.Render(item.name) + return itemOuter.Render(render) +} + // StreamRetentionData is the data structure for stream retention type StreamRetentionData []struct { Description string `json:"description"` @@ -143,7 +152,7 @@ var StatStreamCmd = &cobra.Command{ isRententionSet := len(retention) > 0 - fmt.Println(styleBold.Render("Info:")) + fmt.Println(styleBold.Render("\nInfo:")) fmt.Printf(" Event Count: %d\n", ingestionCount) fmt.Printf(" Ingestion Size: %s\n", humanize.Bytes(uint64(ingestionSize))) fmt.Printf(" Storage Size: %s\n", humanize.Bytes(uint64(storageSize))) @@ -217,7 +226,7 @@ var RemoveStreamCmd = &cobra.Command{ } if resp.StatusCode == 200 { - fmt.Printf("Removed stream %s", styleBold.Render(name)) + fmt.Printf("Removed stream %s\n", styleBold.Render(name)) } else { bytes, err := io.ReadAll(resp.Body) if err != nil { @@ -256,18 +265,27 @@ var ListStreamCmd = &cobra.Command{ return err } defer resp.Body.Close() - for _, item := range items { - fmt.Println(item["name"]) + + if len(items) >= 0 { + fmt.Println() + } else if len(items) == 0 { + fmt.Println("No streams found") + return nil } - } else { - bytes, err := io.ReadAll(resp.Body) - if err != nil { - return err + + for _, item := range items { + item := StreamListItem{item["name"]} + fmt.Println(item.Render()) } - body := string(bytes) - fmt.Printf("Request Failed\nStatus Code: %s\nResponse: %s\n", resp.Status, body) + fmt.Println() + return nil } - + bytes, err := io.ReadAll(resp.Body) + if err != nil { + return err + } + body := string(bytes) + fmt.Printf("Request Failed\nStatus Code: %s\nResponse: %s\n", resp.Status, body) return nil }, } diff --git a/main.go b/main.go index 61f29a1..3e59948 100644 --- a/main.go +++ b/main.go @@ -54,35 +54,35 @@ func defaultInitialProfile() config.Profile { // Root command var cli = &cobra.Command{ Use: "pb", - Short: "\nParseable command line tool", - Long: "\npb is a command line tool for Parseable", + Short: "\nParseable command line interface", + Long: "\npb is a command line interface for Parseable", RunE: func(command *cobra.Command, args []string) error { if p, _ := command.Flags().GetBool(versionFlag); p { cmd.PrintVersion(Version, Commit) return nil } - return errors.New("No command or flag supplied\n") + return errors.New("no command or flag supplied") }, } var profile = &cobra.Command{ Use: "profile", Short: "Manage profiles", - Long: "\nprofile command is used to manage multiple instances of Parseable. Each profile can have a different set of credentials and URL", + Long: "\nuse profile command to configure (multiple) Parseable instances. Each profile takes a URL and credentials.", } var user = &cobra.Command{ Use: "user", Short: "Manage users", - Long: "\nuser command is used to manage users. Users can be added, deleted and listed", + Long: "\nuser command is used to manage users.", PersistentPreRunE: cmd.PreRunDefaultProfile, } var stream = &cobra.Command{ Use: "stream", Short: "Manage streams", - Long: "\nstream command is used to manage streams. Streams can be created, deleted and listed", + Long: "\nstream command is used to manage streams.", PersistentPreRunE: cmd.PreRunDefaultProfile, } @@ -90,7 +90,7 @@ var query = &cobra.Command{ Use: "query [stream-name] --duration 10", Example: " pb query frontend --duration 10", Short: "Open SQL query prompt", - Long: "\nquery command is used to open a prompt to query a stream. The stream name and duration in minutes are required arguments", + Long: "\nquery command is used to open a prompt to query a stream.", Args: cobra.ExactArgs(1), PreRunE: cmd.PreRunDefaultProfile, RunE: func(command *cobra.Command, args []string) error {