Skip to content

Commit ffb8aae

Browse files
committed
format and update readme
1 parent c8dcde7 commit ffb8aae

2 files changed

Lines changed: 44 additions & 28 deletions

File tree

README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,29 @@
1717

1818
No installation is required. Just grab a [release](https://github.com/spatialcurrent/gocat/releases). You might want to rename your binary to just `gocat` (or `cat`) for convenience.
1919

20-
If you do have go already installed, you can just run using `go run main.go` or install with `bash scripts/install.sh`
20+
If you do have go already installed, you can just run using `go run main.go` or install with `make install`
2121

2222
# Usage
2323

24-
See the few examples below.
24+
See the usage below or the following examples.
25+
26+
```
27+
gocat is a super simple utility to concatenate files (local, remote, or on AWS S3) provided as positional arguments. Supports stdin (aka "-"), local files (path/to/file or file://path/to/file), remote files (http://path/to/file), or files on AWS S3 (s3://path/to/file).
28+
29+
Usage:
30+
gocat [-|stdin|FILE|URI]... [flags]
31+
32+
Flags:
33+
-a, --append-new-lines append new lines to files that do not end in new lines characters
34+
--aws-access-key-id string AWS Access Key ID
35+
--aws-default-region string AWS Default Region
36+
--aws-profile string AWS Profile
37+
--aws-region string AWS Region (overrides default region)
38+
--aws-secret-access-key string AWS Secret Access Key
39+
--aws-session-token string AWS Session Token
40+
-b, --buffer-size int buffer size for file reader (default 4096)
41+
-h, --help help for gocat
42+
```
2543

2644
# Examples
2745

main.go

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import (
1616
import (
1717
"github.com/pkg/errors"
1818
"github.com/spf13/cobra"
19-
"github.com/spf13/viper"
2019
"github.com/spf13/pflag"
20+
"github.com/spf13/viper"
2121
)
2222

2323
import (
@@ -33,14 +33,14 @@ import (
3333
)
3434

3535
const (
36-
flagAWSProfile string = "aws-profile"
37-
flagAWSDefaultRegion string = "aws-default-region"
38-
flagAWSRegion string = "aws-region"
39-
flagAWSAccessKeyID string = "aws-access-key-id"
36+
flagAWSProfile string = "aws-profile"
37+
flagAWSDefaultRegion string = "aws-default-region"
38+
flagAWSRegion string = "aws-region"
39+
flagAWSAccessKeyID string = "aws-access-key-id"
4040
flagAWSSecretAccessKey string = "aws-secret-access-key"
41-
flagAWSSessionToken string = "aws-session-token"
41+
flagAWSSessionToken string = "aws-session-token"
4242

43-
flagBufferSize string = "buffer-size"
43+
flagBufferSize string = "buffer-size"
4444
flagAppendNewlines string = "append-new-lines"
4545
)
4646

@@ -78,7 +78,7 @@ func main() {
7878
cmd := &cobra.Command{
7979
Use: "gocat [-|stdin|FILE|URI]...",
8080
Short: "gocat",
81-
Long: `super simple utility to concatenate file paths and uris provided as positional arguments. Can read from stdin (aka \"-\"), local files, files on AWS S3, or remote urls.`,
81+
Long: `gocat is a super simple utility to concatenate files (local, remote, or on AWS S3) provided as positional arguments. Supports stdin (aka "-"), local files (path/to/file or file://path/to/file), remote files (http://path/to/file), or files on AWS S3 (s3://path/to/file).`,
8282
RunE: func(cmd *cobra.Command, args []string) error {
8383
v, err := initViper(cmd)
8484
if err != nil {
@@ -103,35 +103,34 @@ func main() {
103103

104104
for _, uri := range args {
105105

106-
107106
if uri == "-" {
108107
uri = "stdin"
109108
}
110109

111-
if strings.HasPrefix(uri, "s3://") {
110+
if strings.HasPrefix(uri, "s3://") {
112111
if session == nil {
113112
accessKeyID := v.GetString(flagAWSAccessKeyID)
114113
secretAccessKey := v.GetString(flagAWSSecretAccessKey)
115114
sessionToken := v.GetString(flagAWSSessionToken)
116115

117116
region := v.GetString(flagAWSRegion)
118117
if len(region) == 0 {
119-
if defaultRegion := v.GetString(flagAWSDefaultRegion); len(defaultRegion) > 0 {
118+
if defaultRegion := v.GetString(flagAWSDefaultRegion); len(defaultRegion) > 0 {
120119
region = defaultRegion
121120
}
122121
}
123122

124123
config := aws.Config{
125-
MaxRetries: aws.Int(3),
126-
Region: aws.String(region),
127-
}
124+
MaxRetries: aws.Int(3),
125+
Region: aws.String(region),
126+
}
128127

129-
if len(accessKeyID) > 0 && len(secretAccessKey) > 0 {
130-
config.Credentials = credentials.NewStaticCredentials(
131-
accessKeyID,
132-
secretAccessKey,
133-
sessionToken)
134-
}
128+
if len(accessKeyID) > 0 && len(secretAccessKey) > 0 {
129+
config.Credentials = credentials.NewStaticCredentials(
130+
accessKeyID,
131+
secretAccessKey,
132+
sessionToken)
133+
}
135134

136135
session = awssession.Must(awssession.NewSessionWithOptions(awssession.Options{
137136
Config: config,
@@ -142,11 +141,10 @@ func main() {
142141
}
143142
}
144143

145-
146-
inputBytes := make([]byte, 0)
144+
inputBytes := make([]byte, 0)
147145

148146
// if not reading from stdin or stdin hasn't been read yet.
149-
if uri != "stdin" || len(stdinBytes) == 0 {
147+
if uri != "stdin" || len(stdinBytes) == 0 {
150148
inputReader, _, inputError := grw.ReadFromResource(uri, "none", bufferSize, false, s3Client)
151149
if inputError != nil {
152150
return errors.Wrap(inputError, fmt.Sprintf("error reading from uri %q", uri))
@@ -158,7 +156,7 @@ func main() {
158156
inputBytes = b
159157
}
160158

161-
// if reading from stdin and stdin bytes are already cached
159+
// if reading from stdin and stdin bytes are already cached
162160
if uri == "stdin" && len(inputBytes) == 0 && len(stdinBytes) > 0 {
163161
inputBytes = stdinBytes
164162
}
@@ -170,8 +168,8 @@ func main() {
170168
return errors.Wrap(err, fmt.Sprintf("error writing bytes from uri %q", uri))
171169
}
172170

173-
if v.GetBool(flagAppendNewlines) {
174-
if inputBytes[len(inputBytes) - 1] != '\n' {
171+
if v.GetBool(flagAppendNewlines) {
172+
if inputBytes[len(inputBytes)-1] != '\n' {
175173
_, err := os.Stdout.Write([]byte("\n"))
176174
if err != nil {
177175
return errors.Wrap(err, fmt.Sprintf("error writing new line from uri %q", uri))

0 commit comments

Comments
 (0)