Skip to content

Commit

Permalink
Replace flag with zflag.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefansundin committed Aug 16, 2022
1 parent 8660488 commit 2c4292a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 39 deletions.
50 changes: 17 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,43 +21,27 @@ go install github.com/stefansundin/s3sha256sum@latest
## Usage

```
$ s3sha256sum -help
$ s3sha256sum --help
Usage: s3sha256sum [parameters] <S3Uri> [S3Uri]...
S3Uri must have the format s3://<bucketname>/<key>.
Parameters:
-ca-bundle string
The CA certificate bundle to use when verifying SSL certificates.
-debug
Turn on debug logging.
-endpoint-url string
Override the S3 endpoint URL. (for use with S3 compatible APIs)
-expected-bucket-owner string
The account ID of the expected bucket owner.
-no-sign-request
Do not sign requests.
-no-verify-ssl
Do not verify SSL certificates.
-paranoid duration
Print status and hash state on an interval. (e.g. "10s")
-profile string
Use a specific profile from your credential file.
-region string
The region to use. Overrides config/env settings. Avoids one API call.
-request-payer string
Confirms that the requester knows that they will be charged for the requests. Possible values: requester.
-resume string
Provide a hash state to resume from a specific position.
-use-accelerate-endpoint
Use S3 Transfer Acceleration.
-use-path-style
Use S3 Path Style.
-verbose
Verbose output.
-version
Print version number.
-version-id string
Version ID used to reference a specific version of the S3 object.
--ca-bundle string The CA certificate bundle to use when verifying SSL certificates.
--debug Turn on debug logging.
--endpoint-url string Override the S3 endpoint URL. (for use with S3 compatible APIs)
--expected-bucket-owner string The account ID of the expected bucket owner.
--no-sign-request Do not sign requests.
--no-verify-ssl Do not verify SSL certificates.
--paranoid duration Print status and hash state on an interval. (e.g. "10s")
--profile string Use a specific profile from your credential file.
--region string The region to use. Overrides config/env settings. Avoids one API call.
--request-payer string Confirms that the requester knows that they will be charged for the requests. Possible values: requester.
--resume string Provide a hash state to resume from a specific position.
--use-accelerate-endpoint Use S3 Transfer Acceleration.
--use-path-style Use S3 Path Style.
--verbose Verbose output.
--version Print version number.
--version-id string Version ID used to reference a specific version of the S3 object.
```

You can also set environment variables that [aws-sdk-go-v2](https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/config#EnvConfig) automatically consumes:
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/aws/aws-sdk-go-v2 v1.16.11
github.com/aws/aws-sdk-go-v2/config v1.17.1
github.com/aws/aws-sdk-go-v2/service/s3 v1.27.5
github.com/stefansundin/go-zflag v1.1.1
)

require (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeN
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stefansundin/go-zflag v1.1.1 h1:XabhzWS588bVvV1z1UctSa6i8zHkXc5W9otqtnDSHw8=
github.com/stefansundin/go-zflag v1.1.1/go.mod h1:HXX5rABl1AoTcZ2jw+CqJ7R8irczaLquGNZlFabZooc=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
9 changes: 5 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"encoding/base64"
"encoding/hex"
"errors"
"flag"
"fmt"
"hash"
"io"
Expand All @@ -24,6 +23,7 @@ import (
"github.com/aws/aws-sdk-go-v2/credentials/stscreds"
"github.com/aws/aws-sdk-go-v2/service/s3"
s3Types "github.com/aws/aws-sdk-go-v2/service/s3/types"
flag "github.com/stefansundin/go-zflag"
)

const version = "0.1.0"
Expand Down Expand Up @@ -76,10 +76,11 @@ func main() {
if versionFlag {
fmt.Println(version)
os.Exit(0)
}
if flag.NArg() == 0 {
} else if flag.NArg() == 0 {
flag.Usage()
os.Exit(0)
fmt.Fprintln(os.Stderr)
fmt.Fprintln(os.Stderr, "Error: At least one S3Uri parameter is required!")
os.Exit(1)
}

if endpointURL != "" {
Expand Down
4 changes: 2 additions & 2 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ func formatFilesize(size uint64) string {
}

func formatResumeCommand(encodedState, arg string) string {
cmd := []string{os.Args[0], "-resume", encodedState}
cmd := []string{os.Args[0], "--resume", encodedState}
for i := 1; i < len(os.Args); i++ {
if os.Args[i] == "-resume" {
if os.Args[i] == "--resume" {
i++
continue
}
Expand Down

0 comments on commit 2c4292a

Please sign in to comment.