Skip to content

Commit

Permalink
feat: add config flag
Browse files Browse the repository at this point in the history
Allow the use of another file rather than the hardcoded one.
  • Loading branch information
virtualroot committed Nov 20, 2024
1 parent 1f27af8 commit fe64dd1
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"flag"
"fmt"
"log"
"os"
Expand Down Expand Up @@ -51,7 +52,14 @@ func main() {
case "help":
printUsage()
case "run":
runSync()
runCmd := flag.NewFlagSet("run", flag.ExitOnError)
configFile := runCmd.String("config", "feeds.yaml", "path to config file")

if err := runCmd.Parse(os.Args[2:]); err != nil {
log.Fatalf("Error parsing flags: %v", err)
}

runSync(*configFile)
default:
fmt.Printf("Unknown command: %s\n", os.Args[1])
printUsage()
Expand All @@ -63,23 +71,25 @@ func printUsage() {
fmt.Printf(`RSS to Notion Sync Tool
Usage:
%s <command>
%s <command> [flags]
Commands:
run Execute the RSS to Notion synchronization
Flags:
-config string Path to config file (default "feeds.yaml")
help Show this help message
Configuration:
Create a feeds.yaml file with the following structure:
Create a YAML config file with the following structure:
feeds:
- https://example.com/feed.xml
notion_db_id: your_notion_database_id
notion_api_key: your_notion_api_key
`, os.Args[0])
}

func runSync() {
config, err := loadConfig("feeds.yaml")
func runSync(configFile string) {
config, err := loadConfig(configFile)
if err != nil {
log.Fatalf("Error loading config: %v", err)
}
Expand Down

0 comments on commit fe64dd1

Please sign in to comment.