Skip to content

Commit 8a7ff88

Browse files
authored
Merge pull request #2 from 404missinglink/add-go-version
feat: add Go version implementation
2 parents a332332 + 3884943 commit 8a7ff88

File tree

13 files changed

+810
-3
lines changed

13 files changed

+810
-3
lines changed

.github/workflows/build-go.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Build Go App
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- cmd/arxiv-cli/*.go
7+
- go.mod
8+
- go.sum
9+
- internal/download/*.go
10+
11+
jobs:
12+
build-go:
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: write
16+
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
21+
- name: Set up Go
22+
uses: actions/setup-go@v5
23+
with:
24+
go-version: "1.24"
25+
26+
- name: Build package
27+
run: make build-go

.github/workflows/lint-go.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Lint Go
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- cmd/arxiv-cli/*.go
7+
- go.mod
8+
- go.sum
9+
- internal/download/*.go
10+
11+
jobs:
12+
lint-go:
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: read
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
20+
- name: Set up Go
21+
uses: actions/setup-go@v5
22+
with:
23+
go-version: "1.24"
24+
25+
- name: Set up golangci
26+
uses: golangci/golangci-lint-action@v8
27+
with:
28+
version: latest
29+
30+
- name: Install goimports
31+
run: go install golang.org/x/tools/cmd/goimports@latest
32+
33+
- name: Format
34+
run: make format-go
35+
36+
- name: Lint
37+
run: make lint-go

.github/workflows/publish-go.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Release Go App
2+
on:
3+
push:
4+
tags:
5+
- "go@v*"
6+
7+
permissions:
8+
contents: read # for checkout
9+
10+
jobs:
11+
release:
12+
name: Release
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: write # to be able to publish a GitHub release
16+
issues: write # to be able to comment on released issues
17+
pull-requests: write # to be able to comment on released pull requests
18+
id-token: write # to enable use of OIDC for npm provenance
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
25+
- name: Setup Node.js
26+
uses: actions/setup-node@v4
27+
with:
28+
node-version: "lts/*"
29+
30+
- name: Install goreleaser
31+
run: npm i -g @goreleaser/goreleaser
32+
33+
- name: Release Go binary
34+
run: goreleaser release
35+
env:
36+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/test-go.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Go Tests - PR
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- cmd/arxiv-cli/*.go
7+
- go.mod
8+
- go.sum
9+
- internal/download/*.go
10+
11+
jobs:
12+
test-go:
13+
runs-on: ubuntu-latest
14+
15+
strategy:
16+
matrix:
17+
go-version: ["1.22", "1.25"]
18+
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- name: Set up Go
23+
uses: actions/setup-go@v5
24+
with:
25+
go-version: ${{ matrix.go-version }}
26+
27+
- name: Cache Go modules
28+
uses: actions/cache@v4
29+
with:
30+
path: |
31+
~/.cache/go-build
32+
~/go/pkg/mod
33+
key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }}
34+
restore-keys: |
35+
${{ runner.os }}-go-${{ matrix.go-version }}-
36+
37+
- name: Run tests
38+
run: make test-go

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,9 @@ metadata.jsonl
44
texts/
55
pdfs/
66
.venv/
7-
.env
7+
.env
8+
# Go build artifacts
9+
*.exe
10+
arxiv-cli
11+
bin/
12+
dist/

.goreleaser.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
builds:
2+
- binary: arxiv-cli
3+
main: ./cmd/arxiv-cli
4+
dir: .
5+
goos:
6+
- windows
7+
- darwin
8+
- linux
9+
goarch:
10+
- amd64
11+
- arm64

Makefile

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: build test clippy clippy-fix format format-check version-bump
1+
.PHONY: build test clippy clippy-fix format format-check version-bump build-go test-go format-go lint-go
22

33
build:
44
cargo build --target-dir target/
@@ -30,4 +30,20 @@ version-bump:
3030
npm-publish:
3131
$(info ****************** login and publish to npm ******************)
3232
$(info ****************** meant for manual usage ******************)
33-
bash scripts/login_and_publish_to_npm.sh
33+
bash scripts/login_and_publish_to_npm.sh
34+
35+
build-go:
36+
$(info ****************** building Go binary ******************)
37+
go build -C . -o bin/arxiv-cli ./cmd/arxiv-cli
38+
39+
test-go:
40+
$(info ****************** running Go tests ******************)
41+
go test ./...
42+
43+
format-go:
44+
$(info ****************** formatting Go code ******************)
45+
goimports -w .
46+
47+
lint-go:
48+
$(info ****************** running golangci-lint ******************)
49+
golangci-lint run

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ Intuitive command-line tool to download the most recent number of papers belongi
88
# with npm
99
npm install @cle-does-things/arxiv-cli
1010

11+
# with go install
12+
go install github.com/AstraBert/arxiv-cli/cmd/arxiv-cli@latest
13+
1114
# with cargo
1215
cargo install arxiv-cli
1316
```

cmd/arxiv-cli/main.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"os"
7+
8+
"github.com/AstraBert/arxiv-cli/internal/download"
9+
"github.com/spf13/cobra"
10+
)
11+
12+
var (
13+
query string
14+
limit int
15+
pdf bool
16+
summary bool
17+
noMetadata bool
18+
)
19+
20+
func main() {
21+
rootCmd := &cobra.Command{
22+
Use: "arxiv-cli",
23+
Short: "Download papers from arXiv by category or search query",
24+
Long: "Intuitive command-line tool to download the most recent number of papers belonging a specific category from arXiv.",
25+
Version: "1.0.0",
26+
RunE: func(cmd *cobra.Command, args []string) error {
27+
if query == "" {
28+
return fmt.Errorf("query is required (use --query or -q)")
29+
}
30+
31+
ctx := context.Background()
32+
return download.DownloadArxivPapers(
33+
ctx,
34+
query,
35+
limit,
36+
!noMetadata,
37+
pdf,
38+
summary,
39+
)
40+
},
41+
}
42+
43+
rootCmd.Flags().StringVarP(&query, "query", "q", "", "Search query (e.g., \"graphrag\", \"machine learning\") (required)")
44+
rootCmd.Flags().IntVarP(&limit, "limit", "l", 5, "The maximum number of papers to fetch")
45+
rootCmd.Flags().BoolVarP(&pdf, "pdf", "p", false, "Whether or not to fetch and save the PDF paper")
46+
rootCmd.Flags().BoolVarP(&summary, "summary", "s", false, "Whether or not to save the summary of the papers txt files")
47+
rootCmd.Flags().BoolVar(&noMetadata, "no-metadata", false, "Whether or not to disable fetching and saving the metadata of the paper to a JSONL file")
48+
49+
if err := rootCmd.MarkFlagRequired("query"); err != nil {
50+
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
51+
os.Exit(1)
52+
}
53+
54+
if err := rootCmd.Execute(); err != nil {
55+
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
56+
os.Exit(1)
57+
}
58+
}

go.mod

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module github.com/AstraBert/arxiv-cli
2+
3+
go 1.22
4+
5+
require github.com/spf13/cobra v1.10.2
6+
7+
require (
8+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
9+
github.com/spf13/pflag v1.0.9 // indirect
10+
)

0 commit comments

Comments
 (0)