Skip to content

Commit dfe4b2e

Browse files
authored
update GRW; cli tests (#4)
1 parent 1f4ae60 commit dfe4b2e

7 files changed

Lines changed: 1544 additions & 33 deletions

File tree

.circleci/config.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ jobs:
2626
- run: make test_go
2727
- run: make imports
2828
- run: git diff --exit-code
29+
test_cli:
30+
executor: base
31+
steps:
32+
- run: sudo chown -R circleci /go/src
33+
- restore_cache:
34+
keys:
35+
- v1-go-src-{{ .Branch }}-{{ .Revision }}
36+
- run: make deps_go
37+
- run: make install
38+
- run: make test_cli
2939
build_cli:
3040
executor: base
3141
steps:
@@ -48,3 +58,6 @@ workflows:
4858
- build_cli:
4959
requires:
5060
- pre_deps_golang
61+
- test_cli:
62+
requires:
63+
- pre_deps_golang

Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,23 @@ deps_arm: ## Install dependencies to cross-compile to ARM
5252
fmt: ## Format Go source code
5353
go fmt $$(go list ./... )
5454

55+
.PHONY: imports
5556
imports: ## Update imports in Go source code
5657
# If missing, install goimports with: go get golang.org/x/tools/cmd/goimports
57-
goimports -w $$(find . -iname '*.go')
58+
goimports -w -local github.com/spatialcurrent/gocat,github.com/spatialcurrent $$(find . -iname '*.go')
5859

5960
vet: ## Vet Go source code
6061
go vet $$(go list ./...)
6162

63+
.PHONY: test_go
6264
test_go: ## Run Go tests
6365
bash scripts/test.sh
6466

67+
.PHONY: test_cli
68+
test_cli: ## Run CLI tests
69+
bash scripts/test-cli.sh
70+
71+
.PHONY: build
6572
build: build_cli build_javascript build_so build_android ## Build CLI, Shared Objects (.so), JavaScript, and Android
6673

6774
install: ## Install gocat CLI on current platform
@@ -83,6 +90,7 @@ bin/gocat_windows_amd64.exe: ## Build gocat CLI for Windows / amd64
8390
bin/gocat_linux_arm64: ## Build gocat CLI for Linux / arm64
8491
GOOS=linux GOARCH=arm64 go build -o $(DEST)/gocat_linux_arm64 -gcflags="$(GCFLAGS)" -ldflags="$(LDFLAGS)" github.com/spatialcurrent/gocat
8592

93+
.PHONY: build_cli
8694
build_cli: bin/gocat_darwin_amd64 bin/gocat_linux_amd64 bin/gocat_windows_amd64.exe bin/gocat_linux_arm64 ## Build command line programs
8795

8896
## Clean

README.md

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,42 @@
66

77
**gocat** is a super simple command line program for concatenating files. **gocat** supports the following operating systems and architectures.
88

9+
## Platforms
10+
11+
The following platforms are supported. Pull requests to support other platforms are welcome!
12+
913
| GOOS | GOARCH |
1014
| ---- | ------ |
1115
| darwin | amd64 |
1216
| linux | amd64 |
1317
| windows | amd64 |
1418
| linux | arm64 |
1519

16-
# Installation
20+
## Releases
21+
22+
Find releases at [https://github.com/spatialcurrent/gocat/releases](https://github.com/spatialcurrent/gocat/releases). You might want to rename your binary to just `gocat` (or `cat`) for convenience. See the **Building** section below to build from scratch.
23+
24+
**Darwin**
25+
26+
- `gocat_darwin_amd64` - CLI for Darwin on amd64 (includes `macOS` and `iOS` platforms)
1727

18-
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.
28+
**Linux**
1929

20-
If you do have go already installed, you can just run using `go run main.go` or install with `make install`
30+
- `gocat_linux_amd64` - CLI for Linux on amd64
31+
- `gocat_linux_amd64` - CLI for Linux on arm64
2132

22-
# Usage
33+
**Windows**
34+
35+
- `gocat_windows_amd64.exe` - CLI for Windows on amd64
36+
37+
## Usage
2338

2439
See the usage below or the following examples.
2540

2641
```shell
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).
42+
gocat is a super simple utility to concatenate files (local, remote, or on AWS S3) provided as positional arguments.
43+
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).
44+
Supports the following compression algorithms: bzip2, flate, gzip, none, snappy, zip, zlib
2845

2946
Usage:
3047
gocat [flags] [-|stdin|FILE|URI]...
@@ -41,42 +58,60 @@ Flags:
4158
-h, --help help for gocat
4259
```
4360

44-
# Examples
61+
## Examples
4562

46-
**Shell**
63+
### Shell
4764

4865
```shell
4966
gocat "~/.bash_aliases" "~/.bashrc"
5067
```
5168

52-
**Remote File**
69+
### Remote File
5370

5471
`gocat` arguments can point to remote files
5572

5673
```shell
5774
gocat https://spatialcurrent.io
5875
```
5976

60-
**All Files With Extension**
77+
### All Files With Extension
6178

6279
`gocat` will print every file given as a positional argument, which can be useful when looking through thousands of files.
6380

6481
```shell
6582
gocat $( find . -print | grep -i '.*[.]md')
6683
```
6784

68-
# Building
85+
## Building
86+
87+
Use `make help` to see help information for each target.
88+
89+
**CLI**
6990

70-
You can build all the released artifacts using `make build` or run the make target for a specific operating system and architecture.
91+
The `make build_cli` script is used to build executables for Linux and Windows. Use `make install` for standard installation as a go executable.
92+
93+
**Changing Destination**
94+
95+
The default destination for build artifacts is `go-reader-writer/bin`, but you can change the destination with an environment variable. For building on a Chromebook consider saving the artifacts in `/usr/local/go/bin`, e.g., `DEST=/usr/local/go/bin make build_cli`
96+
97+
## Testing
98+
99+
**CLI**
100+
101+
To run CLI testes use `make test_cli`, which uses [shUnit2](https://github.com/kward/shunit2). If you recive a `shunit2:FATAL Please declare TMPDIR with path on partition with exec permission.` error, you can modify the `TMPDIR` environment variable in line or with `export TMPDIR=<YOUR TEMP DIRECTORY HERE>`. For example:
102+
103+
```
104+
TMPDIR="/usr/local/tmp" make test_cli
105+
```
71106

72-
# Testing
107+
**Go**
73108

74-
Run test using `bash scripts/test.sh` or `make test`, which runs unit tests, `go vet`, `go vet with shadow`, [errcheck](https://github.com/kisielk/errcheck), [ineffassign](https://github.com/gordonklaus/ineffassign), [staticcheck](https://staticcheck.io/), and [misspell](https://github.com/client9/misspell).
109+
To run Go tests use `make test_go` (or `bash scripts/test.sh`), which runs unit tests, `go vet`, `go vet with shadow`, [errcheck](https://github.com/kisielk/errcheck), [ineffassign](https://github.com/gordonklaus/ineffassign), [staticcheck](https://staticcheck.io/), and [misspell](https://github.com/client9/misspell).
75110

76-
# Contributing
111+
## Contributing
77112

78113
[Spatial Current, Inc.](https://spatialcurrent.io) is currently accepting pull requests for this repository. We'd love to have your contributions! Please see [Contributing.md](https://github.com/spatialcurrent/gocat/blob/master/CONTRIBUTING.md) for how to get started.
79114

80-
# License
115+
## License
81116

82117
This work is distributed under the **MIT License**. See **LICENSE** file.

main.go

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,17 @@ import (
1414
"io/ioutil"
1515
"os"
1616
"strings"
17-
)
18-
19-
import (
20-
"github.com/pkg/errors"
21-
"github.com/spf13/cobra"
22-
"github.com/spf13/pflag"
23-
"github.com/spf13/viper"
24-
)
2517

26-
import (
2718
"github.com/aws/aws-sdk-go/aws"
2819
"github.com/aws/aws-sdk-go/aws/credentials"
2920
awssession "github.com/aws/aws-sdk-go/aws/session"
3021
"github.com/aws/aws-sdk-go/service/s3"
31-
)
22+
"github.com/pkg/errors"
23+
"github.com/spf13/cobra"
24+
"github.com/spf13/pflag"
25+
"github.com/spf13/viper"
3226

33-
import (
34-
"github.com/spatialcurrent/go-reader-writer/grw"
27+
"github.com/spatialcurrent/go-reader-writer/pkg/grw"
3528
)
3629

3730
const (
@@ -78,10 +71,12 @@ func checkConfig(v *viper.Viper) error {
7871

7972
func main() {
8073
cmd := &cobra.Command{
81-
Use: "gocat [flags] [-|stdin|FILE|URI]...",
82-
Short: "gocat",
74+
Use: `gocat [flags] [-|stdin|FILE|URI]...`,
8375
DisableFlagsInUseLine: true,
84-
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).`,
76+
Short: "gocat is a super simple utility to concatenate files (local, remote, or on AWS S3) provided as positional arguments.",
77+
Long: `gocat is a super simple utility to concatenate files (local, remote, or on AWS S3) provided as positional arguments.
78+
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).
79+
Supports the following compression algorithms: ` + strings.Join(grw.Algorithms, ", "),
8580
RunE: func(cmd *cobra.Command, args []string) error {
8681
v, err := initViper(cmd)
8782
if err != nil {
@@ -158,7 +153,13 @@ func main() {
158153
inputReaders = append(inputReaders, bytes.NewReader(stdinBytes))
159154
}
160155
} else {
161-
inputReader, _, err := grw.ReadFromResource(uri, "none", bufferSize, false, s3Client)
156+
inputReader, _, err := grw.ReadFromResource(&grw.ReadFromResourceInput{
157+
Uri: uri,
158+
Alg: "none",
159+
Dict: grw.NoDict,
160+
BufferSize: bufferSize,
161+
S3Client: s3Client,
162+
})
162163
if err != nil {
163164
return errors.Wrap(err, fmt.Sprintf("error reading from uri %q", uri))
164165
}
@@ -181,6 +182,8 @@ func main() {
181182
initFlags(cmd.Flags())
182183

183184
if err := cmd.Execute(); err != nil {
184-
panic(err)
185+
fmt.Fprintln(os.Stderr, "gocat: "+err.Error())
186+
fmt.Fprintln(os.Stderr, "Try gocat --help for more information.")
187+
os.Exit(1)
185188
}
186189
}

0 commit comments

Comments
 (0)