all repos — llm_aggregator @ 7208dd81944bf3bb82070208a69ea5d1d083dd01

A CLI tool to aggregate RSS feeds and summarise them with LLMs

internal/cli/args.go (view raw)

  1package cli
  2
  3import (
  4	"fmt"
  5	"os"
  6	"strings"
  7
  8	"github.com/alexflint/go-arg"
  9)
 10
 11var (
 12	Version   string
 13	BuildDate string
 14)
 15
 16// Args represents command-line arguments.
 17type Args struct {
 18	FeedsFile string `arg:"--feeds-file,required" help:"Path to file containing RSS feed URLs (one per line)"`
 19	Prompt    string `arg:"--prompt,required" help:"User prompt for summarisation/analysis"`
 20
 21	// Feed aggregation options
 22	MaxArticlesPerFeed int `arg:"--max-articles-per-feed" help:"Maximum articles to fetch from each feed" default:"10"`
 23	MaxDaysOld         int `arg:"--max-days-old" help:"Only include articles from the last N days (0 for all)" default:"7"`
 24	MaxTotalArticles   int `arg:"--max-total-articles" help:"Maximum total articles to process" default:"20"`
 25
 26	// Content filtering
 27	IncludeKeywords string `arg:"--include-keywords" help:"Comma-separated list of keywords to include (case-insensitive)"`
 28	ExcludeKeywords string `arg:"--exclude-keywords" help:"Comma-separated list of keywords to exclude (case-insensitive)"`
 29
 30	// Deepseek API options
 31	APIKey      string  `arg:"--api-key" help:"OpenAI-compatible API key (default: read from LLM_AGGREGATOR_API_KEY env var)"`
 32	Model       string  `arg:"--model" help:"Deepseek model to use" default:"deepseek-chat"`
 33	MaxTokens   int     `arg:"--max-tokens" help:"Maximum tokens in response" default:"4000"`
 34	Temperature float64 `arg:"--temperature" help:"Sampling temperature (0.0 to 1.0)" default:"0.7"`
 35
 36	// Output options
 37	Output          string `arg:"--output" help:"Output format" default:"text" choice:"text,json,markdown"`
 38	OutputFile      string `arg:"--output-file" help:"Write output to file (default: stdout)"`
 39	IncludeArticles bool   `arg:"--include-articles" help:"Include original articles in JSON output"`
 40
 41	// System options
 42	SystemPrompt string `arg:"--system-prompt" help:"Custom system prompt for Deepseek"`
 43	TUI          bool   `arg:"--tui" help:"Enable TUI interface with progress bar"`
 44	Verbose      bool   `arg:"-v,--verbose" help:"Show verbose output"`
 45	ShowVersion  bool   `arg:"--version" help:"Show version"`
 46}
 47
 48// Version returns the version string.
 49func (Args) Version() string {
 50	return fmt.Sprintf("llm_aggregator v%s (built %s)", Version, BuildDate)
 51}
 52
 53// Description returns the program description.
 54func (Args) Description() string {
 55	return `LLM Aggregator - Aggregate RSS feeds and summarise with Deepseek API
 56
 57Examples:
 58  # Basic usage with prompts
 59  llm_aggregator --feeds-file feeds.txt --prompt "What are the latest trends in free software?"
 60  
 61  # With custom Deepseek model
 62  llm_aggregator --feeds-file feeds.txt --prompt "Summarise tech news" --model deepseek-coder
 63  
 64  # Output to JSON file
 65  llm_aggregator --feeds-file feeds.txt --prompt "Analyse AI developments" --output json --output-file analysis.json
 66  
 67  # Filter by keywords
 68  llm_aggregator --feeds-file feeds.txt --prompt "Linux news" --include-keywords linux,opensource
 69
 70Environment Variables:
 71  LLM_AGGREGATOR_API_KEY: Your Deepseek API key (required if not provided via --api-key)`
 72}
 73
 74// ParseKeywords parses comma-separated keywords string into list.
 75func ParseKeywords(keywordString string) []string {
 76	if keywordString == "" {
 77		return nil
 78	}
 79	keywords := strings.Split(keywordString, ",")
 80	result := make([]string, 0, len(keywords))
 81	for _, kw := range keywords {
 82		if trimmed := strings.TrimSpace(kw); trimmed != "" {
 83			result = append(result, trimmed)
 84		}
 85	}
 86	return result
 87}
 88
 89// ParseArgs parses command line arguments.
 90func ParseArgs() (*Args, error) {
 91	var args Args
 92	parser, err := arg.NewParser(arg.Config{
 93		Program: "llm_aggregator",
 94	}, &args)
 95	if err != nil {
 96		return nil, err
 97	}
 98
 99	// Handle help and version flags before checking required fields
100	if len(os.Args) > 1 {
101		if os.Args[1] == "-h" || os.Args[1] == "--help" {
102			parser.WriteHelp(os.Stdout)
103			os.Exit(0)
104		}
105		if os.Args[1] == "--version" {
106			fmt.Printf("llm_aggregator v%s (built %s)", Version, BuildDate)
107			os.Exit(0)
108		}
109	}
110
111	err = parser.Parse(os.Args[1:])
112	if err != nil {
113		return nil, err
114	}
115
116	return &args, nil
117}