Skip to content

Commit

Permalink
Merge pull request #5 from fujiwara/version-flag
Browse files Browse the repository at this point in the history
add --version flag
  • Loading branch information
fujiwara authored May 15, 2024
2 parents 3406f10 + 4bf145f commit dd8dc24
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
15 changes: 13 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,28 @@ builds:
- CGO_ENABLED=0
main: cmd/aws-sdk-client-go/main.go
binary: aws-sdk-client-go
ldflags: '-s -w -extldflags "-static"'
ldflags:
- -s
- -w
- -extldflags "-static"
- -X github.com/fujiwara/aws-sdk-client-go.Version={{.Version}}
tags:
- osusergo
- netgo
goos:
- linux
#- darwin
- darwin
#- windows
goarch:
- amd64
- arm64
archives:
- format: tar.gz
files:
- aws-sdk-client-go
- LICENSE
- README.md

checksum:
name_template: "checksums.txt"
snapshot:
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
VERSION := $(shell git describe --abbrev=0 --tags)
.PHONY: clean test gen

aws-sdk-client-go: go.* *.go gen
CGO_ENABLED=0 \
go build -o $@ \
-tags netgo \
-ldflags '-s -w -extldflags "-static"' \
-ldflags '-s -w -extldflags "-static" -X github.com/fujiwara/aws-sdk-client-go.Version=$(VERSION)' \
cmd/aws-sdk-client-go/main.go

clean:
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The [AWS CLI](https://aws.amazon.com/cli/) is very useful, but it requires too m

## Install

**Note:** The release binaries are large (about 500MB after being extracted) because they contain codes for access to **[all AWS services](https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/service)**. If you want to use only a few services, you can build the client yourself. See [Build](#build) section.
**Note:** The release binaries are large (about 500MB after being extracted) and slow a bit to boot up (about 100ms), because they contain codes for access to **[all AWS services](https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/service)**. If you want to use only a few services, you can build the client yourself. See [Build](#build) section.

### Release binary

Expand All @@ -24,7 +24,7 @@ $ brew install fujiwara/tap/aws-sdk-client-go

## Build

You can build the client yourself, including only the needed services and methods.
You can build the client yourself, including only the needed services and methods. The optimized binary is small and boots up quickly.

The client is built by a configuration file `gen.yaml`.

Expand Down Expand Up @@ -113,7 +113,7 @@ $ aws-sdk-client-go ecs DescribeClusters '{"Cluster":"default"}' \

#### Show help

aws-sdk-client-go is a simple wrapper of the AWS SDK Go v2 service client. Its usage is the same as that of the AWS SDK Go v2.
aws-sdk-client-go is a simple wrapper of the AWS SDK Go v2 service client. Its usage is the same as that of the AWS SDK Go v2. If the third argument is "help", it shows the URL of the method documentation.

```console
$ aws-sdk-client-go ecs DescribeClusters help
Expand Down
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"github.com/jmespath/go-jmespath"
)

var Version = "HEAD"

var clientMethods = make(map[string]ClientMethod)

type ClientMethod func(context.Context, aws.Config, json.RawMessage) (any, error)
Expand All @@ -26,6 +28,7 @@ type CLI struct {
Input string `arg:"" help:"input JSON" default:"{}"`
Compact bool `short:"c" help:"compact JSON output"`
Query string `short:"q" help:"JMESPath query to apply to output"`
Version bool `short:"v" help:"show version"`

w io.Writer
}
Expand All @@ -38,6 +41,10 @@ func Run(ctx context.Context) error {
}

func (c *CLI) Dispatch(ctx context.Context) error {
if c.Version {
fmt.Fprintf(c.w, "aws-sdk-client-go %s\n", Version)
return nil
}
if c.Service == "" {
return c.ListServices(ctx)
} else if c.Method == "" {
Expand Down

0 comments on commit dd8dc24

Please sign in to comment.