1// Copyright (C) 2013-2015 Sören Tempel 2// 3// This program is free software: you can redistribute it and/or modify 4// it under the terms of the GNU General Public License as published by 5// the Free Software Foundation, either version 3 of the License, or 6// (at your option) any later version. 7// 8// This program is distributed in the hope that it will be useful, 9// but WITHOUT ANY WARRANTY; without even the implied warranty of10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the11// GNU General Public License for more details.12//13// You should have received a copy of the GNU General Public License14// along with this program. If not, see <http://www.gnu.org/licenses/>.1516package main1718import (19 "fmt"20 "github.com/nmeum/cpod/opml"21 "github.com/nmeum/cpod/store"22 "github.com/nmeum/cpod/util"23 "os"24 "path/filepath"25)2627func usage() {28 fmt.Fprintf(os.Stderr, "USAGE: cpod-import FILE...\n")29 os.Exit(1)30}3132func load(files []string) (out []opml.Outline, err error) {33 for _, file := range files {34 var op *opml.OPML3536 op, err = opml.Load(file)37 if err != nil {38 return39 }4041 for _, o := range op.Outlines {42 out = append(out, o)43 }44 }4546 return47}4849func main() {50 if len(os.Args) <= 1 {51 usage()52 }5354 storeDir := filepath.Join(util.EnvDefault("XDG_CONFIG_HOME", ".config"), "cpod")55 if err := os.MkdirAll(storeDir, 0755); err != nil {56 panic(err)57 }5859 store, err := store.Load(filepath.Join(storeDir, "urls"))60 if err != nil && !os.IsNotExist(err) {61 panic(err)62 }6364 outlines, err := load(os.Args)65 if err != nil {66 panic(err)67 }6869 for _, outline := range outlines {70 url := outline.URL71 if !store.Contains(url) {72 store.Add(url)73 }74 }7576 if err = store.Save(); err != nil {77 panic(err)78 }79}