|
| 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 | +} |
0 commit comments