Skip to content

Commit

Permalink
Merge pull request #4 from fujiwara/method-allows-kebab
Browse files Browse the repository at this point in the history
allows kebab-case method.
  • Loading branch information
fujiwara authored May 14, 2024
2 parents 1c0dc26 + 91eabd7 commit d2304f6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,21 @@ $ aws-sdk-client-go ecs DescribeClusters '{"Cluster":"default"}'

The third argument is JSON input for the method. If the method does not require input, you can omit the third argument (implicitly `{}` passed).

If the method name is "kebab-case", it automatically converts to "PascalCase" (for example, `describe-clusters` -> `DescribeClusters`).

```console
$ aws-sdk-client-go ecs describe-clusters '{"Cluster":"default"}'
```

#### Query output by JMESPath

`--query` option allows you to query the output by JMESPath like the AWS CLI.

```console
./aws-sdk-client-go ecs DescribeClusters '{"Cluster":"default"}' \
--query 'Clusters[0].ClusterArn'
```

#### 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.
Expand Down
15 changes: 14 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ func (c *CLI) SetWriter(w io.Writer) {
}

func (c *CLI) CallMethod(ctx context.Context) error {
key := buildKey(c.Service, c.Method)
method := kebabToCamel(c.Method)
key := buildKey(c.Service, method)
if c.Input == "help" {
fmt.Fprintf(c.w, "See https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/service/%s\n", key)
return nil
Expand Down Expand Up @@ -137,4 +138,16 @@ func buildKey(service, method string) string {
return fmt.Sprintf("%s#Client.%s", service, method)
}

func kebabToCamel(kebab string) string {
parts := strings.Split(kebab, "-")
results := make([]string, 0, len(parts))
for _, p := range parts {
if len(p) == 0 {
continue
}
results = append(results, strings.ToUpper(p[:1])+p[1:])
}
return strings.Join(results, "")
}

//go:generate go run cmd/aws-sdk-client-gen/main.go cmd/aws-sdk-client-gen/gen.go

0 comments on commit d2304f6

Please sign in to comment.