Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit 45ba413

Browse files
author
AJ ONeal
committed
add vesrion and goreleaser support
1 parent 737ceae commit 45ba413

File tree

3 files changed

+128
-12
lines changed

3 files changed

+128
-12
lines changed

.goreleaser.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# This is an example goreleaser.yaml file with some sane defaults.
2+
# Make sure to check the documentation at http://goreleaser.com
3+
project_name: arc
4+
before:
5+
hooks:
6+
# You may remove this if you don't use go modules.
7+
- go mod download
8+
# you may remove this if you don't need go generate
9+
- go generate ./...
10+
builds:
11+
-
12+
env:
13+
- CGO_ENABLED=0
14+
main: ./cmd/arc
15+
goos:
16+
- linux
17+
- windows
18+
- darwin
19+
goarch:
20+
- 386
21+
- amd64
22+
- arm
23+
- arm64
24+
goarm:
25+
- 6
26+
- 7
27+
archives:
28+
-
29+
format: binary
30+
replacements:
31+
darwin: mac
32+
checksum:
33+
name_template: 'checksums.txt'
34+
snapshot:
35+
name_template: "{{ .Tag }}-next"
36+
changelog:
37+
sort: asc
38+
filters:
39+
exclude:
40+
- '^docs:'
41+
- '^test:'

README.md

Lines changed: 76 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,75 @@ Files are put into the root of the archive; directories are recursively added, p
4848

4949
Tar files can optionally be compressed using any of the above compression formats.
5050

51+
## GoDoc
52+
53+
See <https://pkg.go.dev/github.com/mholt/archiver/v3>
54+
5155
## Install
5256

57+
### With webi
58+
59+
[`webi`](https://webinstall.dev/arc) will install `webi` and `arc` to `~/.local/bin/` and update your `PATH`.
60+
61+
#### Mac, Linux, Raspberry Pi
62+
63+
```bash
64+
curl -fsS https://webinstall.dev/arc | bash
65+
```
66+
67+
#### Windows 10
68+
69+
```pwsh
70+
curl.exe -fsS -A MS https://webinstall.dev/arc | powershell
71+
```
72+
73+
### With Go
74+
5375
To install the runnable binary to your \$GOPATH/bin:
5476

5577
```bash
56-
$ go install github.com/mholt/archiver/cmd/arc
78+
go get github.com/mholt/archiver/cmd/arc
5779
```
5880

59-
Or download binaries from the [releases](https://github.com/mholt/archiver/releases) page.
81+
### Manually
6082

61-
To use as a dependency in your project:
83+
To install manually
84+
85+
1. Download the binary for your platform from the [Github Releases](https://github.com/mholt/archiver/releases) page.
86+
2. Move the binary to a location in your path, for example:
87+
- without `sudo`:
88+
```bash
89+
chmod a+x ~/Downloads/arc_*
90+
mkdir -p ~/.local/bin
91+
mv ~/Downloads/arc_* ~/.local/bin/arc
92+
```
93+
- as `root`:
94+
```bash
95+
chmod a+x ~/Downloads/arc_*
96+
sudo mkdir -p /usr/local/bin
97+
sudo mv ~/Downloads/arc_* /usr/local/bin/arc
98+
```
99+
3. If needed, update `~/.bashrc` or `~/.profile` to include add `arc` in your `PATH`, for example:
100+
```
101+
echo 'PATH="$HOME:/.local/bin:$PATH"' >> ~/.bashrc
102+
```
103+
104+
## Build from Source
62105
106+
You can successfully build `arc` with just the go tooling, or with `goreleaser`.
107+
108+
### With `go`
109+
110+
```bash
111+
go build cmd/arc/*.go
63112
```
64-
$ go get github.com/mholt/archiver/v3
113+
114+
### Multi-platform with `goreleaser`
115+
116+
Builds with `goreleaser` will also include version info.
117+
118+
```bash
119+
goreleaser --snapshot --skip-publish --rm-dist
65120
```
66121

67122
## Command Use
@@ -71,7 +126,7 @@ $ go get github.com/mholt/archiver/v3
71126
```bash
72127
# Syntax: arc archive [archive name] [input files...]
73128

74-
$ arc archive test.tar.gz file1.txt images/file2.jpg folder/subfolder
129+
arc archive test.tar.gz file1.txt images/file2.jpg folder/subfolder
75130
```
76131

77132
(At least one input file is required.)
@@ -81,7 +136,7 @@ $ arc archive test.tar.gz file1.txt images/file2.jpg folder/subfolder
81136
```bash
82137
# Syntax: arc unarchive [archive name] [destination]
83138

84-
$ arc unarchive test.tar.gz
139+
arc unarchive test.tar.gz
85140
```
86141

87142
(The destination path is optional; default is current directory.)
@@ -93,7 +148,10 @@ The archive name must end with a supported file extension&mdash;this is how it k
93148
```bash
94149
# Syntax: arc ls [archive name]
95150

96-
$ arc ls caddy_dist.tar.gz
151+
arc ls caddy_dist.tar.gz
152+
```
153+
154+
```txt
97155
drwxr-xr-x matt staff 0 2018-09-19 15:47:18 -0600 MDT dist/
98156
-rw-r--r-- matt staff 6148 2017-08-07 18:34:22 -0600 MDT dist/.DS_Store
99157
-rw-r--r-- matt staff 22481 2018-09-19 15:47:18 -0600 MDT dist/CHANGES.txt
@@ -109,16 +167,16 @@ drwxr-xr-x matt staff 0 2018-09-19 15:47:18 -0600 MDT dist/
109167
```bash
110168
# Syntax: arc extract [archive name] [path in archive] [destination on disk]
111169

112-
$ arc extract test.tar.gz foo/hello.txt extracted/hello.txt
170+
arc extract test.tar.gz foo/hello.txt extracted/hello.txt
113171
```
114172

115173
### Compress a single file
116174

117175
```bash
118176
# Syntax: arc compress [input file] [output file]
119177

120-
$ arc compress test.txt compressed_test.txt.gz
121-
$ arc compress test.txt gz
178+
arc compress test.txt compressed_test.txt.gz
179+
arc compress test.txt gz
122180
```
123181

124182
For convenience, the output file (second argument) may simply be a compression format (without leading dot), in which case the output filename will be the same as the input filename but with the format extension appended, and the input file will be deleted if successful.
@@ -128,8 +186,8 @@ For convenience, the output file (second argument) may simply be a compression f
128186
```bash
129187
# Syntax: arc decompress [input file] [output file]
130188

131-
$ arc decompress test.txt.gz original_test.txt
132-
$ arc decompress test.txt.gz
189+
arc decompress test.txt.gz original_test.txt
190+
arc decompress test.txt.gz
133191
```
134192

135193
For convenience, the output file (second argument) may be omitted. In that case, the output filename will have the same name as the input filename, but with the compression extension stripped from the end; and the input file will be deleted if successful.
@@ -142,6 +200,12 @@ Flags are specified before the subcommand. Use `arc help` or `arc -h` to get usa
142200

143201
The archiver package allows you to easily create and open archives, walk their contents, extract specific files, compress and decompress files, and even stream archives in and out using pure io.Reader and io.Writer interfaces, without ever needing to touch the disk.
144202

203+
To use as a dependency in your project:
204+
205+
```bash
206+
go get github.com/mholt/archiver/v3
207+
```
208+
145209
```go
146210
import "github.com/mholt/archiver/v3"
147211
```

cmd/arc/main.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ var (
2424
continueOnError bool
2525
)
2626

27+
var (
28+
version string
29+
commit string
30+
date string
31+
)
32+
2733
func init() {
2834
flag.IntVar(&compressionLevel, "level", flate.DefaultCompression, "Compression level")
2935
flag.BoolVar(&overwriteExisting, "overwrite", false, "Overwrite existing files")
@@ -39,6 +45,11 @@ func main() {
3945
fmt.Println(usageString())
4046
os.Exit(0)
4147
}
48+
if len(os.Args) >= 2 &&
49+
(os.Args[1] == "-V" || os.Args[1] == "--version" || os.Args[1] == "version") {
50+
fmt.Printf("arc v%s %s (%s)", version, commit, date)
51+
os.Exit(0)
52+
}
4253
if len(os.Args) < 3 {
4354
fatal(usageString())
4455
}

0 commit comments

Comments
 (0)