Skip to content

Commit

Permalink
Adds apexes mode; updates install instructions etc
Browse files Browse the repository at this point in the history
  • Loading branch information
tomnomnom committed Apr 6, 2022
1 parent 99ad735 commit 490aaef
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 23 deletions.
12 changes: 11 additions & 1 deletion README.mkd
Expand Up @@ -7,7 +7,7 @@ Pull out bits of URLs provided on `stdin`
If you have Go installed and configured:

```
▶ go get -u github.com/tomnomnom/unfurl
▶ go install github.com/tomnomnom/unfurl@latest
```

Otherwise [download the latest binary for your platform](https://github.com/tomnomnom/unfurl/releases),
Expand Down Expand Up @@ -51,6 +51,16 @@ example.net

The `-u`/`--unique` flag works for all modes.

### Apex Domains

You can extract the apex part of the domain (e.g. the `example.com` in `http://sub.example.com`) using the `apexes` mode:

```
▶ cat urls.txt | unfurl -u apexes
example.com
example.net
```

### Paths

```
Expand Down
7 changes: 7 additions & 0 deletions go.mod
@@ -0,0 +1,7 @@
module github.com/tomnomnom/unfurl

go 1.18

require github.com/jakewarren/tldomains v0.0.0-20220401175117-e21ec594add9

require golang.org/x/net v0.0.0-20220401154927-543a649e0bdd // indirect
9 changes: 9 additions & 0 deletions go.sum
@@ -0,0 +1,9 @@
github.com/jakewarren/tldomains v0.0.0-20220401175117-e21ec594add9 h1:Pcr+CqSKD2lPGhHX/NU/md02EBwPR56X567WzO4iew0=
github.com/jakewarren/tldomains v0.0.0-20220401175117-e21ec594add9/go.mod h1:iNGwlKkTjgCKgRtxW5G398eul77UVW1b4eLScbkEe+c=
golang.org/x/net v0.0.0-20220401154927-543a649e0bdd h1:zYlwaUHTmxuf6H7hwO2dgwqozQmH7zf4x+/qql4oVWc=
golang.org/x/net v0.0.0-20220401154927-543a649e0bdd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
12 changes: 11 additions & 1 deletion main.go
Expand Up @@ -35,6 +35,8 @@ func main() {
"domain": domains,
"paths": paths,
"path": paths,
"apex": apexes,
"apexes": apexes,
"format": format,
}[mode]

Expand Down Expand Up @@ -156,7 +158,14 @@ func domains(u *url.URL, f string) []string {
return format(u, "%d")
}

// domains returns the path portion of the URL. e.g.
// apexes return the apex portion of the URL. e.g.
// for http://sub.example.com/path it will return
// []string{"example.com"}
func apexes(u *url.URL, f string) []string {
return format(u, "%r.%t")
}

// paths returns the path portion of the URL. e.g.
// for http://sub.example.com/path it will return
// []string{"/path"}
func paths(u *url.URL, f string) []string {
Expand Down Expand Up @@ -316,6 +325,7 @@ func init() {
h += " keypairs Key=value pairs from the query string (one per line)\n"
h += " domains The hostname (e.g. sub.example.com)\n"
h += " paths The request path (e.g. /users)\n"
h += " apexes The apex domain (e.g. example.com from sub.example.com)\n"
h += " format Specify a custom format (see below)\n\n"

h += "Format Directives:\n"
Expand Down
31 changes: 10 additions & 21 deletions script/release
Expand Up @@ -26,24 +26,15 @@ if [ $? -ne 0 ]; then
exit 3
fi

# Check if tag exists
git fetch --tags
git tag | grep "^${TAG}$"

if [ $? -ne 0 ]; then
github-release release \
--user ${USER} \
--repo ${REPO} \
--tag ${TAG} \
--name "${REPO} ${TAG}" \
--description "${TAG}" \
--pre-release
fi

FILELIST=""

for ARCH in "amd64" "386"; do
for OS in "darwin" "linux" "windows" "freebsd"; do

if [[ "${OS}" == "darwin" && "${ARCH}" == "386" ]]; then
continue
fi

BINFILE="${BINARY}"

if [[ "${OS}" == "windows" ]]; then
Expand All @@ -57,18 +48,16 @@ for ARCH in "amd64" "386"; do
if [[ "${OS}" == "windows" ]]; then
ARCHIVE="${BINARY}-${OS}-${ARCH}-${VERSION}.zip"
zip ${ARCHIVE} ${BINFILE}
rm ${BINFILE}
else
ARCHIVE="${BINARY}-${OS}-${ARCH}-${VERSION}.tgz"
tar --create --gzip --file=${ARCHIVE} ${BINFILE}
fi

echo "Uploading ${ARCHIVE}..."
github-release upload \
--user ${USER} \
--repo ${REPO} \
--tag ${TAG} \
--name "${ARCHIVE}" \
--file ${PROJDIR}/${ARCHIVE}
FILELIST="${FILELIST} ${PROJDIR}/${ARCHIVE}"
done
done

gh release create ${TAG} ${FILELIST}
rm ${FILELIST}

0 comments on commit 490aaef

Please sign in to comment.