summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--comitium.go58
1 files changed, 53 insertions, 5 deletions
diff --git a/comitium.go b/comitium.go
index b5c4524..9a8bae6 100644
--- a/comitium.go
+++ b/comitium.go
@@ -8,12 +8,14 @@ package main
import (
"fmt"
+ "net/url"
"os"
"path/filepath"
"github.com/mitchellh/go-homedir"
"golang.nytpu.com/comitium/core"
+ "golang.nytpu.com/comitium/fetch"
)
func main() {
@@ -54,14 +56,60 @@ func main() {
switch os.Args[1] {
case "refresh":
- fmt.Println("Refresh")
+ if len(c.Args()) != 0 {
+ fmt.Fprint(os.Stderr, "\"refresh\" doesn't take an argument!\n\n")
+ usage()
+ os.Exit(1)
+ }
+ // TODO
+ fmt.Fprintln(os.Stderr, "Not Yet Implemented")
case "list":
- fmt.Println("List")
+ if len(c.Args()) != 0 {
+ fmt.Fprint(os.Stderr, "\"list\" doesn't take an argument!\n\n")
+ usage()
+ os.Exit(1)
+ }
+ // TODO
+ fmt.Fprintln(os.Stderr, "Not Yet Implemented")
case "add":
- fmt.Println("Add")
- fmt.Printf("Format: %v\n", *addTypeFlag)
+ if len(c.Args()) < 1 {
+ fmt.Fprint(os.Stderr, "Please provide a URL to add.\n\n")
+ usage()
+ os.Exit(1)
+ }
+ remote, err := url.Parse(c.Arg(0))
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "Error parsing URL: %v\n", err)
+ os.Exit(1)
+ }
+ if !*addTypeFlag {
+ // feed
+ err = fetch.Feed(&core.Data, remote, c.Arg(1))
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "Error adding feed: %v\n", err)
+ os.Exit(1)
+ }
+ } else {
+ // page
+ err = fetch.Page(&core.Data, remote, c.Arg(1))
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "Error adding page: %v\n", err)
+ os.Exit(1)
+ }
+ }
+ err = core.Data.WriteJSON(dataPath)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "Error writing json: %v\n", err)
+ os.Exit(1)
+ }
case "remove":
- fmt.Println("Remove")
+ if len(c.Args()) < 1 {
+ fmt.Fprint(os.Stderr, "Please provide a URL to remove.\n\n")
+ usage()
+ os.Exit(1)
+ }
+ // TODO
+ fmt.Fprintln(os.Stderr, "Not Yet Implemented")
}
}